From 104e8e7305aacb9918779f6267c0842b90ca2fac Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Fri, 16 Feb 2024 14:16:09 +0100 Subject: [PATCH 1/5] Skip itemsuppliers for suppliers that have been archived or excluded for whatever other reason --- frepple/controllers/outbound.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index 6830ee04..2fc1d9a9 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -1138,7 +1138,10 @@ def export_items(self): ) suppliers = {} for sup in results: - name = self.map_customers.get(sup["partner_id"][0]) + name = self.map_customers.get(sup["partner_id"][0], None) + if not name: + # Skip uninterested suppliers (eg archived ones) + continue if sup.get("is_subcontractor", False): if not hasattr(tmpl, "subcontractors"): tmpl["subcontractors"] = [] From 09905d9db85ab2f1c38c23373f9e6c5597ba668d Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Fri, 16 Feb 2024 14:16:09 +0100 Subject: [PATCH 2/5] Skip itemsuppliers for suppliers that have been archived or excluded for whatever other reason --- frepple/controllers/outbound.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index 456a4bb6..393096bc 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -1111,7 +1111,10 @@ def export_items(self): ) suppliers = {} for sup in results: - name = self.map_customers.get(sup["name"][0]) + name = self.map_customers.get(sup["name"][0], None) + if not name: + # Skip uninterested suppliers (eg archived ones) + continue if sup.get("is_subcontractor", False): if not hasattr(tmpl, "subcontractors"): tmpl["subcontractors"] = [] From 1a5470fcf7037d09cfa675466fba4d8669bb687c Mon Sep 17 00:00:00 2001 From: Hicham Lahlou Date: Fri, 16 Feb 2024 14:44:55 +0100 Subject: [PATCH 3/5] append the workoorder id at the of the operation name and operationplan reference --- frepple/controllers/inbound.py | 2 +- frepple/controllers/outbound.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frepple/controllers/inbound.py b/frepple/controllers/inbound.py index 537997f4..f16b70a7 100644 --- a/frepple/controllers/inbound.py +++ b/frepple/controllers/inbound.py @@ -588,7 +588,7 @@ def run(self): if wo_data: for wo in mo.workorder_ids: for rec in wo_data: - if rec["id"] == wo.operation_id.id: + if rec["id"] == wo.id: # By default odoo populates the scheduled start date field only when you confirm and plan # the manufacturing order. # Here we are already updating it earlier diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index 393096bc..f4657f58 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -2432,7 +2432,7 @@ def export_manufacturingorders(self): ) yield '' % ( - quoteattr(suboperation), + quoteattr("%s - %s" % (suboperation, wo["id"])), idx, self.convert_float_time( max(time_left, 1), # Miniminum 1 minute remaining :-) @@ -2567,11 +2567,11 @@ def export_manufacturingorders(self): except Exception: wo_date = "" yield '\n' % ( - quoteattr(wo["display_name"]), + quoteattr("%s - %s" % (wo["display_name"], wo["id"])), wo_date, qty, state, - quoteattr(suboperation), + quoteattr("%s - %s" % (suboperation, wo["id"])), quoteattr(i["name"]), ) yield "\n" From 26120f074541b09e1ba79227af00f1ccc2610c52 Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Mon, 19 Feb 2024 15:29:44 +0100 Subject: [PATCH 4/5] remove workorder id again from the WO reference, keeping it on operation --- frepple/controllers/outbound.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index f4657f58..9ea8573f 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -2567,7 +2567,7 @@ def export_manufacturingorders(self): except Exception: wo_date = "" yield '\n' % ( - quoteattr("%s - %s" % (wo["display_name"], wo["id"])), + quoteattr(wo["display_name"]), wo_date, qty, state, From e680608f5bd23690feedb005cd8038ed6a7dcf55 Mon Sep 17 00:00:00 2001 From: Hicham Lahlou Date: Tue, 20 Feb 2024 17:19:44 +0100 Subject: [PATCH 5/5] use the Odoo _prepare_purchase_order_line function to compute fields in a generic way --- frepple/controllers/inbound.py | 40 ++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/frepple/controllers/inbound.py b/frepple/controllers/inbound.py index f16b70a7..df4ab8f1 100644 --- a/frepple/controllers/inbound.py +++ b/frepple/controllers/inbound.py @@ -74,6 +74,11 @@ def __init__(self, req, database=None, company=None, mode=1): def run(self): msg = [] if self.actual_user: + product_product = self.env["product.product"].with_user(self.actual_user) + product_supplierinfo = self.env["product.supplierinfo"].with_user( + self.actual_user + ) + uom_uom = self.env["uom.uom"].with_user(self.actual_user) proc_order = self.env["purchase.order"].with_user(self.actual_user) proc_orderline = self.env["purchase.order.line"].with_user(self.actual_user) mfg_order = self.env["mrp.production"].with_user(self.actual_user) @@ -93,6 +98,9 @@ def run(self): self.actual_user ) else: + product_product = self.env["product.product"] + product_supplierinfo = self.env["product.supplierinfo"] + uom_uom = self.env["uom.uom"] proc_order = self.env["purchase.order"] proc_orderline = self.env["purchase.order.line"] mfg_order = self.env["mrp.production"] @@ -271,10 +279,8 @@ def run(self): ] = date_ordered if (item_id, supplier_id) not in product_supplier_dict: - product = self.env["product.product"].browse(int(item_id)) - product_supplierinfo = self.env[ - "product.supplierinfo" - ].search( + product = product_product.browse(int(item_id)) + supplier = product_supplierinfo.search( [ ("name", "=", supplier_id), ( @@ -287,21 +293,30 @@ def run(self): limit=1, order="min_qty desc", ) - if product_supplierinfo: - price_unit = product_supplierinfo.price - else: - price_unit = 0 + product_uom = uom_uom.browse(int(uom_id)) + # first create a minimal PO line po_line = proc_orderline.create( { "order_id": supplier_reference[supplier_id]["id"], "product_id": int(item_id), "product_qty": quantity, "product_uom": int(uom_id), - "date_planned": date_planned, - "price_unit": price_unit, - "name": elem.get("item"), } ) + # Then let odoo computes all the fields (taxes, name, description...) + + d = po_line._prepare_purchase_order_line( + product, + quantity, + product_uom, + self.company, + supplier, + po, + ) + d["date_planned"] = date_planned + # Finally update the PO line + po_line.write(d) + # Aggregation of quantities under the same PO line # only happens in incremental export if self.mode == 2: @@ -621,6 +636,9 @@ def run(self): countmfg += 1 except Exception as e: + import traceback + + logger.info(traceback.format_exc()) logger.error("Exception %s" % e) msg.append(str(e)) # Remove the element now to keep the DOM tree small