From 856623c78a7b27f7c4843dd0e284cbdeb0f8a000 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Sat, 11 Jan 2025 11:05:59 +0100 Subject: [PATCH] [IMP] base_wamas_ubl: simulate complete rejection at reception Also support this simulation on customer return --- .../wamas2wamas_input_kret_nothing.wamas | 1 + .../wamas2wamas_input_kret_partial.wamas | 1 + .../wamas2wamas_input_wea_nothing.wamas | 1 + .../samples/wamas2wamas_output_kret.wamas | 6 ++++ .../wamas2wamas_output_kret_nothing.wamas | 6 ++++ .../wamas2wamas_output_kret_partial.wamas | 6 ++++ .../wamas2wamas_output_wea_nothing.wamas | 6 ++++ .../lib/wamas/tests/test_wamas2wamas.py | 32 ++++++++++++++++--- base_wamas_ubl/lib/wamas/utils.py | 13 +++++--- base_wamas_ubl/lib/wamas/wamas2wamas.py | 16 ++++++---- .../lib/wamas/wamas_grammar/kretpq.py | 4 +-- base_wamas_ubl/models/base_wamas_ubl.py | 4 +-- base_wamas_ubl/tests/test_base_wamas_ubl.py | 3 ++ 13 files changed, 80 insertions(+), 19 deletions(-) create mode 120000 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_nothing.wamas create mode 120000 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_partial.wamas create mode 120000 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_wea_nothing.wamas create mode 100644 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret.wamas create mode 100644 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_nothing.wamas create mode 100644 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_partial.wamas create mode 100644 base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_wea_nothing.wamas diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_nothing.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_nothing.wamas new file mode 120000 index 0000000000..4b168b372a --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_nothing.wamas @@ -0,0 +1 @@ +wamas2wamas_input_kret.wamas \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_partial.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_partial.wamas new file mode 120000 index 0000000000..4b168b372a --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_kret_partial.wamas @@ -0,0 +1 @@ +wamas2wamas_input_kret.wamas \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_wea_nothing.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_wea_nothing.wamas new file mode 120000 index 0000000000..41fd59eeb1 --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_input_wea_nothing.wamas @@ -0,0 +1 @@ +wamas2wamas_input_wea.wamas \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret.wamas new file mode 100644 index 0000000000..347cc8677c --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret.wamas @@ -0,0 +1,6 @@ +WAMAS ODOO 00000120231220091116KRETKQ050000130377 HOST 0001040 202304270000002023042708000020230427180000 +WAMAS ODOO 00000220231220091116KRETPQ050000130377 HOST 0000200001151 0000020001151 00000DISPONIBLE 000001536000000000000000 BOUT 19700101 +WAMAS ODOO 00000320231220091116KRETPQ050000130377 HOST 0000300001156 0000030001156 00000DISPONIBLE 000005184000000000000000 PET 19700101 +WAMAS ODOO 00000420231220091116KRETPQ050000130377 HOST 0000400001160 0000040001160 00000DISPONIBLE 000003840000000000000000 BOUT 19700101 +WAMAS ODOO 00000520231220091116KRETPQ050000130377 HOST 0000500001162 0000050001162 00000DISPONIBLE 000003072000000000000000 PET 19700101 +WAMAS ODOO 00000620231220091116KRETPQ050000130377 HOST 0000600001176 0000060001176 00000DISPONIBLE 000003024000000000000000 PET 19700101 \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_nothing.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_nothing.wamas new file mode 100644 index 0000000000..0719157352 --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_nothing.wamas @@ -0,0 +1,6 @@ +WAMAS ODOO 00000120231220091116KRETKQ050000130377 HOST 0001040 202304270000002023042708000020230427180000 +WAMAS ODOO 00000220231220091116KRETPQ050000130377 HOST 0000200001151 0000020001151 00000DISPONIBLE 000000000000000000000000 BOUT 19700101 +WAMAS ODOO 00000320231220091116KRETPQ050000130377 HOST 0000300001156 0000030001156 00000DISPONIBLE 000000000000000000000000 PET 19700101 +WAMAS ODOO 00000420231220091116KRETPQ050000130377 HOST 0000400001160 0000040001160 00000DISPONIBLE 000000000000000000000000 BOUT 19700101 +WAMAS ODOO 00000520231220091116KRETPQ050000130377 HOST 0000500001162 0000050001162 00000DISPONIBLE 000000000000000000000000 PET 19700101 +WAMAS ODOO 00000620231220091116KRETPQ050000130377 HOST 0000600001176 0000060001176 00000DISPONIBLE 000000000000000000000000 PET 19700101 \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_partial.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_partial.wamas new file mode 100644 index 0000000000..9157b411fa --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_kret_partial.wamas @@ -0,0 +1,6 @@ +WAMAS ODOO 00000120231220091116KRETKQ050000130377 HOST 0001040 202304270000002023042708000020230427180000 +WAMAS ODOO 00000220231220091116KRETPQ050000130377 HOST 0000200001151 0000020001151 00000DISPONIBLE 000000001000000000000000 BOUT 19700101 +WAMAS ODOO 00000320231220091116KRETPQ050000130377 HOST 0000300001156 0000030001156 00000DISPONIBLE 000000001000000000000000 PET 19700101 +WAMAS ODOO 00000420231220091116KRETPQ050000130377 HOST 0000400001160 0000040001160 00000DISPONIBLE 000000001000000000000000 BOUT 19700101 +WAMAS ODOO 00000520231220091116KRETPQ050000130377 HOST 0000500001162 0000050001162 00000DISPONIBLE 000000001000000000000000 PET 19700101 +WAMAS ODOO 00000620231220091116KRETPQ050000130377 HOST 0000600001176 0000060001176 00000DISPONIBLE 000000001000000000000000 PET 19700101 \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_wea_nothing.wamas b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_wea_nothing.wamas new file mode 100644 index 0000000000..30db86bbb4 --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/wamas2wamas_output_wea_nothing.wamas @@ -0,0 +1,6 @@ +WAMAS ODOO 00000120231220091116WEAKQ0051000130377 HOST 19700101010000 19700101010000 20231220091116 0001040 +WAMAS ODOO 00000220231220091116WEAPQ0050000130377 000130377 HOST 000020 0001151 00000DISPONIBLE 000000000000000000000000 BOUT N +WAMAS ODOO 00000320231220091116WEAPQ0050000130377 000130377 HOST 000030 0001156 00000DISPONIBLE 000000000000000000000000 PET N +WAMAS ODOO 00000420231220091116WEAPQ0050000130377 000130377 HOST 000040 0001160 00000DISPONIBLE 000000000000000000000000 BOUT N +WAMAS ODOO 00000520231220091116WEAPQ0050000130377 000130377 HOST 000050 0001162 00000DISPONIBLE 000000000000000000000000 PET N +WAMAS ODOO 00000620231220091116WEAPQ0050000130377 000130377 HOST 000060 0001176 00000DISPONIBLE 000000000000000000000000 PET N \ No newline at end of file diff --git a/base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py b/base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py index c683e9ee07..1730eb60cb 100644 --- a/base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py +++ b/base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py @@ -10,24 +10,46 @@ class TestWamas2wamas(unittest.TestCase): maxDiff = None - def _test(self, filename, partial_qty=False): + def _test(self, filename, processed_qty=None): with file_open( file_path("tests/samples/wamas2wamas_input_%s.wamas" % filename) ) as infile, file_open( file_path("tests/samples/wamas2wamas_output_%s.wamas" % filename) ) as outfile: str_input = infile.read() - output = wamas2wamas(str_input, partial_qty=partial_qty) + output = wamas2wamas(str_input, processed_qty=processed_qty) expected_output = outfile.read() self.assertEqual(output, expected_output) @freeze_time("2023-12-20 09:11:16") - def testWamas2wamas_full(self): + def testWamas2wamas_wea_full(self): + """Reception where the demand is fully processed""" self._test("wea") @freeze_time("2023-12-20 09:11:16") - def testWamas2wamas_partial(self): - self._test("wea_partial", partial_qty=True) + def testWamas2wamas_wea_partial(self): + """Reception where the demand is partially processed""" + self._test("wea_partial", processed_qty=1) + + @freeze_time("2023-12-20 09:11:16") + def testWamas2wamas_wea_nothing(self): + """Reception where the demand is not processed at all""" + self._test("wea_nothing", processed_qty=0) + + @freeze_time("2023-12-20 09:11:16") + def testWamas2wamas_kret_full(self): + """Customer return where the demand is fully processed""" + self._test("wea") + + @freeze_time("2023-12-20 09:11:16") + def testWamas2wamas_kret_partial(self): + """Customer return where the demand is partially processed""" + self._test("wea_partial", processed_qty=1) + + @freeze_time("2023-12-20 09:11:16") + def testWamas2wamas_kret_nothing(self): + """Customer return where the demand is not processed at all""" + self._test("wea_nothing", processed_qty=0) if __name__ == "__main__": diff --git a/base_wamas_ubl/lib/wamas/utils.py b/base_wamas_ubl/lib/wamas/utils.py index c6ca1f51ae..9a0baf0605 100644 --- a/base_wamas_ubl/lib/wamas/utils.py +++ b/base_wamas_ubl/lib/wamas/utils.py @@ -79,8 +79,8 @@ def get_current_datetime(val=0): return datetime.utcnow() -def get_quantity_done(quantity, partial=False): - return quantity if not partial else 1 +def get_quantity_done(quantity, quantity_done=None): + return quantity if quantity_done is None else quantity_done def _set_string(val, length, dp, **kwargs): @@ -332,8 +332,13 @@ def generate_wamas_dict(dict_item, grammar, **kwargs): # noqa: C901 elif df_func == "get_random_str_num": args = (length,) elif df_func == "get_quantity_done": - quantity = dict_item.get("BestMng", 0) - args = (quantity, kwargs.get("partial_qty")) + if "BestMng" in dict_item.keys(): + quantity = dict_item.get("BestMng", 0) + elif "SollMng" in dict_item.keys(): + quantity = dict_item.get("SollMng", 0) + else: + raise Exception("Quantity field not found") + args = (quantity, kwargs.get("processed_qty")) elif "get_date_from_field" in df_func: args = (dict_wamas_out,) args += ast.literal_eval(re.search(r"\((.*?)\)", df_func).group(0)) diff --git a/base_wamas_ubl/lib/wamas/wamas2wamas.py b/base_wamas_ubl/lib/wamas/wamas2wamas.py index c7b9b43b70..c451687e37 100644 --- a/base_wamas_ubl/lib/wamas/wamas2wamas.py +++ b/base_wamas_ubl/lib/wamas/wamas2wamas.py @@ -13,7 +13,7 @@ _logger = logging.getLogger("wamas2wamas") -def simulate_response(dict_wamas_in, partial_qty=False): +def simulate_response(dict_wamas_in, processed_qty=None): res = [] line_idx = 0 dict_parent_id = {} @@ -29,17 +29,17 @@ def simulate_response(dict_wamas_in, partial_qty=False): dict_parent_id=dict_parent_id, telegram_type_out=telegram_type_out, do_wamas2wamas=True, - partial_qty=partial_qty, + processed_qty=processed_qty, ) if line: res.append(line) return res -def wamas2wamas(infile, partial_qty=False): +def wamas2wamas(infile, processed_qty=None): data = wamas2dict(infile) _logger.debug(pformat(data)) - wamas_lines = simulate_response(data, partial_qty=partial_qty) + wamas_lines = simulate_response(data, processed_qty=processed_qty) return "\n".join(wamas_lines) @@ -50,7 +50,11 @@ def main(): ) parser.add_argument("-v", "--verbose", action="store_true", help="enable debug log") parser.add_argument( - "-p", "--partial", action="store_true", help="simulate partial quantity" + "-p", + "--processed-qty", + type=float, + dest="processed_qty", + help="quantity processed, by default complete quantity is processed", ) parser.add_argument( "-o", "--output", dest="outputfile", help="write result in this file" @@ -60,7 +64,7 @@ def main(): if args.verbose: logging.basicConfig(level=logging.DEBUG) infile = utils.file_open(args.inputfile).read() - res = wamas2wamas(infile, args.partial) + res = wamas2wamas(infile, args.processed_qty) if args.outputfile: fd = utils.file_open(args.outputfile, "w") fd.write(res) diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/kretpq.py b/base_wamas_ubl/lib/wamas/wamas_grammar/kretpq.py index 9a5f1edfa9..f969bae061 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/kretpq.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/kretpq.py @@ -118,9 +118,9 @@ "type": "float", "length": 12, "dp": 3, - "dict_key": "SollMng", + "dict_key": False, "df_val": False, - "df_func": False, + "df_func": "get_quantity_done", }, "IvKretp_AnmMngs_Gew": { "type": "float", diff --git a/base_wamas_ubl/models/base_wamas_ubl.py b/base_wamas_ubl/models/base_wamas_ubl.py index c872feb785..2fb6022a7a 100644 --- a/base_wamas_ubl/models/base_wamas_ubl.py +++ b/base_wamas_ubl/models/base_wamas_ubl.py @@ -44,8 +44,8 @@ def get_wamas_type(self, str_file): return detect_wamas_type(str_file) @api.model - def wamas2wamas(self, str_file, partial_qty=False): - return wamas2wamas(str_file, partial_qty=partial_qty) + def wamas2wamas(self, str_file, processed_qty=None): + return wamas2wamas(str_file, processed_qty=processed_qty) @api.model def record_data_to_wamas(self, data, msg_type): diff --git a/base_wamas_ubl/tests/test_base_wamas_ubl.py b/base_wamas_ubl/tests/test_base_wamas_ubl.py index 100273b79f..db9ed20c70 100644 --- a/base_wamas_ubl/tests/test_base_wamas_ubl.py +++ b/base_wamas_ubl/tests/test_base_wamas_ubl.py @@ -17,6 +17,9 @@ class TestBaseWamas(TransactionCase): + + maxDiff = None + @classmethod def setUpClass(cls): super().setUpClass()