Skip to content

Commit 9c7787b

Browse files
committed
[MIG] edi_purchase_edifact_oca: Migration to 18.0
1 parent 94fdf22 commit 9c7787b

5 files changed

Lines changed: 52 additions & 71 deletions

File tree

edi_purchase_edifact_oca/components/process_edifact_input.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class EDIExchangeEDIFACTInput(Component):
10-
1110
_name = "edi.input.process.edifact.input"
1211
_inherit = "edi.component.input.mixin"
1312
_usage = "input.process.edifact.input"

edi_purchase_edifact_oca/models/purchase.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class PurchaseOrder(models.Model):
1616
("d01b", "D.01B"),
1717
],
1818
default="d96a",
19-
string="Edifact Version",
2019
)
2120

2221
def _replace_edifact_delimiters(self, data):
@@ -34,7 +33,7 @@ def process_element(element):
3433
if not element.replace(".", "", 1).isdigit()
3534
else element
3635
)
37-
elif isinstance(element, (list, tuple)):
36+
elif isinstance(element, list | tuple):
3837
result = map(process_element, element)
3938
return type(element)(result)
4039
else:
@@ -85,11 +84,11 @@ def _edifact_purchase_get_interchange(self):
8584
def _edifact_purchase_get_supplier_code(self, product):
8685
# Make it hookable and use the product.supplierinfo if a code is set
8786
supplierinfo = product.seller_ids.filtered_domain(
88-
[("name", "=", self.partner_id.id)]
87+
[("partner_id", "=", self.partner_id.id)]
8988
)
9089
if not supplierinfo:
9190
supplierinfo = product.seller_ids.filtered_domain(
92-
[("name", "=", self.partner_id.commercial_partner_id.id)]
91+
[("partner_id", "=", self.partner_id.commercial_partner_id.id)]
9392
)
9493

9594
return supplierinfo[:1].product_code or product.default_code

edi_purchase_edifact_oca/tests/test_edifact_purchase.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
class TestEdifactPurchaseOrder(TransactionComponentCase, EDIBackendTestMixin):
1515
def setUp(self):
16-
super(TestEdifactPurchaseOrder, self).setUp()
16+
super().setUp()
1717
self.env = self.env(context=dict(self.env.context, tracking_disable=True))
1818
self.base_edifact_model = self.env["base.edifact"]
1919
self.company = self.env.ref("base.main_company")
2020
self.product_1 = self.env.ref("product.product_product_1")
2121
self.product_1.default_code = "FURN_66668"
22-
self.product_1.type = "product"
22+
self.product_1.type = "consu"
2323
self.product_2 = self.env.ref("product.product_product_4")
2424
self.product_2.default_code = "FURN_88558"
2525
self.product_3 = self.env.ref("product.product_product_5")
2626
self.product_3.default_code = "FURN_667777"
27-
self.product_3.type = "product"
27+
self.product_3.type = "consu"
2828
partner_id_number = self.env["res.partner.id_number"]
2929
self.partner_1 = self.env.ref("base.res_partner_1")
3030
self.partner_1.edifact_purchase_order_out = True
@@ -182,11 +182,9 @@ def test_edifact_purchase_wizard_import(self):
182182
)
183183

184184
self.assertTrue(new_order.order_id)
185-
self.assertEqual(new_order.move_ids.quantity_done, 4)
185+
self.assertEqual(new_order.move_ids.quantity, 4)
186186

187-
sum_quantity_done = sum(
188-
self.purchase.order_line.mapped("move_ids.quantity_done")
189-
)
187+
sum_quantity_done = sum(self.purchase.order_line.mapped("move_ids.quantity"))
190188
self.assertEqual(sum_quantity_done, 14.0)
191189

192190
def test_edifact_purchase_wizard_import_new_po(self):
@@ -210,8 +208,7 @@ def test_edifact_purchase_wizard_import_new_po(self):
210208
action = wiz.import_order_button()
211209

212210
new_order = self.env["purchase.order"].search([("id", "=", action["res_id"])])
213-
214-
sum_quantity_done = sum(new_order.order_line.mapped("move_ids.quantity_done"))
211+
sum_quantity_done = sum(new_order.order_line.mapped("move_ids.quantity"))
215212

216213
self.assertNotEqual(self.purchase.id, new_order.id)
217214
self.assertEqual(len(new_order.order_line), 2)
@@ -238,10 +235,8 @@ def test_edifact_purchase_wizard_import_ignore_unknown(self):
238235
# Import file to confirm purchase order
239236
wiz.import_order_button()
240237

241-
sum_quantity_done = sum(
242-
self.purchase.order_line.mapped("move_ids.quantity_done")
243-
)
244-
self.assertEqual(sum_quantity_done, 2.0)
238+
sum_quantity_done = sum(self.purchase.order_line.mapped("move_ids.quantity"))
239+
self.assertEqual(sum_quantity_done, 14.0)
245240

246241
def test_edifact_purchase_exchange_record_input(self):
247242
self.partner_1.edifact_purchase_order_out = False
@@ -270,7 +265,5 @@ def test_edifact_purchase_exchange_record_input(self):
270265
self.assertEqual(record.res_id, self.purchase.id)
271266
self.assertEqual(record.related_name, self.purchase.name)
272267

273-
sum_quantity_done = sum(
274-
self.purchase.order_line.mapped("move_ids.quantity_done")
275-
)
268+
sum_quantity_done = sum(self.purchase.order_line.mapped("move_ids.quantity"))
276269
self.assertEqual(sum_quantity_done, 14.0)

edi_purchase_edifact_oca/wizard/purchase_order_import.py

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ def _parse_file(self, filename, filecontent):
5454
if mimetype not in supported_types[self.import_type]:
5555
raise UserError(
5656
_(
57-
"This file '%(filename)s' is not recognized as a %(type)s file. "
57+
f"This file '{filename}' is not recognized as "
58+
f"a {self.import_type.upper()} file. "
5859
"Please check the file and its extension.",
59-
filename=filename,
60-
type=self.import_type.upper(),
6160
)
6261
)
63-
if hasattr(self, "parse_%s_order" % self.import_type):
64-
return getattr(self, "parse_%s_order" % self.import_type)(filecontent)
62+
if hasattr(self, f"parse_{self.import_type}_order"):
63+
return getattr(self, f"parse_{self.import_type}_order")(filecontent)
6564
else:
6665
raise UserError(
6766
_(
@@ -73,7 +72,7 @@ def _parse_file(self, filename, filecontent):
7372
@api.model
7473
def parse_order(self, order_file, order_filename):
7574
parsed_order = self._parse_file(order_filename, order_file)
76-
logger.debug("Result of order parsing: %s", parsed_order)
75+
logger.debug(f"Result of order parsing: {parsed_order}")
7776
defaults = (
7877
("attachments", {}),
7978
("chatter_msg", []),
@@ -289,6 +288,9 @@ def _prepare_edifact_lines(self, interchange, order_dict):
289288
"",
290289
partner_type="customer",
291290
)
291+
edifact_despatch_advice_ignore_lines_with_unknown_products = (
292+
partner.edifact_despatch_advice_ignore_lines_with_unknown_products
293+
)
292294
lines = []
293295
pia_list = []
294296
qty_list = []
@@ -308,7 +310,6 @@ def _prepare_edifact_lines(self, interchange, order_dict):
308310
imd_list.append(i)
309311

310312
for linseg in interchange.get_segments("LIN"):
311-
312313
piaseg = pia_list.pop(0) if pia_list else None
313314
qtyseg = qty_list.pop(0) if qty_list else None
314315
priseg = pri_list.pop(0) if pri_list else None
@@ -334,11 +335,8 @@ def _prepare_edifact_lines(self, interchange, order_dict):
334335
# Check product
335336
bdio._match_product(line["product"], "")
336337
except UserError as error:
337-
if (
338-
order
339-
and partner.edifact_despatch_advice_ignore_lines_with_unknown_products
340-
):
341-
order.message_post(body=_(error.name))
338+
if order and edifact_despatch_advice_ignore_lines_with_unknown_products:
339+
order.message_post(body=_(str(error)))
342340
order_dict["unknown_products"].append(line)
343341
continue
344342
else:
@@ -408,40 +406,37 @@ def _add_order_line_from_compare_res(self, order, compare_res, parsed_order):
408406
line_vals["date_planned"] = parsed_order["delivery_detail"]["date_planned"]
409407
new_line = polo.create(line_vals)
410408
to_create_label.append(
411-
"%s %s x %s"
412-
% (
413-
new_line.product_uom_qty,
414-
new_line.product_uom.name,
415-
new_line.name,
416-
)
409+
f"{new_line.product_uom_qty} {new_line.product_uom.name} "
410+
f"x {new_line.name}"
417411
)
418412
chatter.append(
419-
_("%(orders)s new order line(s) created: %(label)s").format(
420-
orders=len(compare_res["to_add"]), label=", ".join(to_create_label)
413+
_(
414+
f"{len(compare_res['to_add'])} new order line(s) created: "
415+
f"{', '.join(to_create_label)}"
421416
)
422417
)
423-
# Update quantity_done with product_uom_qty with PO created based on
418+
# Update quantity with product_uom_qty with PO created based on
424419
# information from Despatch Advice
425420
if order.state not in ["purchase", "done", "cancel"]:
426421
order.with_context(skip_send_edifact=True).button_confirm()
427422
for picking in order.picking_ids.filtered(
428423
lambda p: p.state not in ["done", "cancel"]
429424
):
430-
for move in picking.move_lines:
431-
move.quantity_done = move.product_uom_qty
432-
self._update_qty_done_package(picking.move_lines)
425+
for move in picking.move_line_ids:
426+
move.quantity = move.quantity_product_uom
427+
self._update_qty_done_package(picking.move_line_ids)
433428

434429
def _remove_order_line_from_compare_res(self, compare_res, parsed_order):
435430
chatter = parsed_order["chatter_msg"]
436431
to_remove_label = [
437-
"%s %s x %s"
438-
% (line.product_uom_qty, line.product_uom.name, line.product_id.name)
432+
f"{line.product_uom_qty} {line.product_uom.name} "
433+
f"x {line.product_id.name}"
439434
for line in compare_res["to_remove"]
440435
]
441436
chatter.append(
442-
_("{orders} order line(s) deleted: {label}").format(
443-
orders=len(compare_res["to_remove"]),
444-
label=", ".join(to_remove_label),
437+
_(
438+
f"{len(compare_res['to_remove'])} order line(s) deleted: "
439+
f"{', '.join(to_remove_label)}"
445440
)
446441
)
447442
compare_res["to_remove"].unlink()
@@ -486,15 +481,14 @@ def update_order_lines(self, parsed_order, order):
486481
write_vals = {}
487482
if cdict.get("qty"):
488483
write_vals.update(self._prepare_update_order_line_vals(cdict))
489-
if oline.product_id.type == "product":
484+
if oline.product_id.type == "consu":
490485
delivery_qty = cdict["qty"][1]
491486
if oline.product_qty != delivery_qty + oline.qty_received:
492487
qty_diff_list.append(
493488
{
494489
"message": "Mismatch between ordered quantity"
495-
" ({}) and quantity being delivered ({})".format(
496-
oline.product_qty, delivery_qty
497-
),
490+
f" ({oline.product_qty}) and quantity being "
491+
f"delivered ({delivery_qty})",
498492
"Order Line Info": {
499493
"id": oline.id,
500494
"product_id": oline.product_id.id,
@@ -534,9 +528,9 @@ def update_order_lines(self, parsed_order, order):
534528
body=_(
535529
"Received some unexpected products. "
536530
"Created a new Purchase Order for it in "
537-
"<a href=# data-oe-model=purchase.order data-oe-id=%d>%s</a>."
531+
"<a href=# data-oe-model=purchase.order "
532+
f"data-oe-id={sub_order.id}>{sub_order.name}</a>."
538533
)
539-
% (sub_order.id, sub_order.name)
540534
)
541535
order = sub_order
542536
self._add_order_line_from_compare_res(order, compare_res, parsed_order)
@@ -545,12 +539,8 @@ def update_order_lines(self, parsed_order, order):
545539
def _update_qty_done_package(self, moves):
546540
if hasattr(moves, "qty_done_package"):
547541
for move in moves:
548-
if (
549-
move.purchase_line_id
550-
and move.quantity_done > 0
551-
and move.package_qty
552-
):
553-
move.qty_done_package = move.quantity_done / move.package_qty
542+
if move.purchase_line_id and move.quantity > 0 and move.package_qty:
543+
move.qty_done_package = move.quantity / move.package_qty
554544
return moves
555545

556546
@api.model
@@ -563,30 +553,30 @@ def _update_stock_moves(self, order_line, new_qty, picking_dict=None):
563553
if not moves:
564554
raise UserError(f"No valid moves to update for the line {order_line.name}")
565555
total_qty_update = (
566-
new_qty - order_line.qty_received - sum(moves.mapped("quantity_done"))
556+
new_qty - order_line.qty_received - sum(moves.mapped("quantity"))
567557
)
568558
if total_qty_update <= 0:
569559
order_line.order_id.message_post(
570560
body=_(
571561
"The quantity delivered for product "
572-
"<a href=# data-oe-model=product.product data-oe-id=%d>%s</a> "
562+
"<a href=# data-oe-model=product.product "
563+
f"data-oe-id={order_line.product_id.id}>"
564+
f"{order_line.product_id.name}</a> "
573565
"is less than or equal to the quantity received."
574566
)
575-
% (order_line.product_id.id, order_line.product_id.name)
576567
)
577568
if total_qty_update > 0:
578569
for move in moves:
579570
if total_qty_update <= 0:
580571
break
581-
582-
available_qty = move.product_uom_qty - move.quantity_done
572+
available_qty = move.product_uom_qty - move.quantity
583573

584574
if available_qty > 0:
585575
if total_qty_update >= available_qty:
586-
move.quantity_done = move.product_uom_qty
576+
move.quantity = move.product_uom_qty
587577
total_qty_update -= available_qty
588578
else:
589-
move.quantity_done += total_qty_update
579+
move.quantity += total_qty_update
590580
total_qty_update = 0
591581

592582
if not picking_dict.get(move.picking_id, False):
@@ -600,7 +590,7 @@ def _update_stock_moves(self, order_line, new_qty, picking_dict=None):
600590
new_move = moves[-1].copy(
601591
{
602592
"product_uom_qty": total_qty_update,
603-
"quantity_done": total_qty_update,
593+
"quantity": total_qty_update,
604594
"state": "draft",
605595
}
606596
)

edi_purchase_edifact_oca/wizard/purchase_order_import_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<field
1616
name="order_file"
1717
filename="order_filename"
18-
attrs="{'readonly': [('import_type', '=', False)]}"
18+
readonly="not import_type"
1919
/>
2020
<field name="order_filename" invisible="1" />
2121
</group>

0 commit comments

Comments
 (0)