Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] base_wamas_ubl: simulate complete rejection at reception #1107

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
32 changes: 27 additions & 5 deletions base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,46 @@

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)

Check warning on line 20 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L20

Added line #L20 was not covered by tests
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)

Check warning on line 32 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L32

Added line #L32 was not covered by tests

@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)

Check warning on line 37 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L37

Added line #L37 was not covered by tests

@freeze_time("2023-12-20 09:11:16")
def testWamas2wamas_kret_full(self):
"""Customer return where the demand is fully processed"""
self._test("wea")

Check warning on line 42 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L42

Added line #L42 was not covered by tests

@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)

Check warning on line 47 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L47

Added line #L47 was not covered by tests

@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)

Check warning on line 52 in base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py#L52

Added line #L52 was not covered by tests


if __name__ == "__main__":
Expand Down
13 changes: 9 additions & 4 deletions base_wamas_ubl/lib/wamas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
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):
Expand Down Expand Up @@ -332,8 +332,13 @@
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)

Check warning on line 338 in base_wamas_ubl/lib/wamas/utils.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/utils.py#L338

Added line #L338 was not covered by tests
else:
raise Exception("Quantity field not found")

Check warning on line 340 in base_wamas_ubl/lib/wamas/utils.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/utils.py#L340

Added line #L340 was not covered by tests
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))
Expand Down
16 changes: 10 additions & 6 deletions base_wamas_ubl/lib/wamas/wamas2wamas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -29,17 +29,17 @@
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)


Expand All @@ -50,7 +50,11 @@
)
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"
Expand All @@ -60,7 +64,7 @@
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)

Check warning on line 67 in base_wamas_ubl/lib/wamas/wamas2wamas.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2wamas.py#L67

Added line #L67 was not covered by tests
if args.outputfile:
fd = utils.file_open(args.outputfile, "w")
fd.write(res)
Expand Down
4 changes: 2 additions & 2 deletions base_wamas_ubl/lib/wamas/wamas_grammar/kretpq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions base_wamas_ubl/models/base_wamas_ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions base_wamas_ubl/tests/test_base_wamas_ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@


class TestBaseWamas(TransactionCase):

maxDiff = None

@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
Loading