From 95388cb5b29bd111ff095ffc7f3f836fd9d656ea Mon Sep 17 00:00:00 2001 From: Hicham Lahlou Date: Fri, 5 Jul 2024 08:52:27 +0200 Subject: [PATCH] implement item hierarchy based on product category --- frepple/controllers/outbound.py | 57 +++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index afcbbcd..2ed79e5 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -281,6 +281,7 @@ def run(self): logger.debug("Exporting workcenterskills.") yield from self.export_workcenterskills() logger.debug("Exporting products.") + yield from self.export_item_hierarchy() yield from self.export_items() if with_mrp: logger.debug("Exporting BOMs.") @@ -985,6 +986,49 @@ def export_workcenters(self): if not first: yield "\n" + def export_item_hierarchy(self): + """ + Creates an item in frepple for each category that will be then used + as item.owner + + Mapping: + product.category.complete_name -> item.name + product.category.parent_id.complete_name -> item.owner_id + """ + self.categories = {} + for i in self.generator.getData( + "product.category", + search=[], + fields=[ + "complete_name", + "parent_id", + ], + ): + self.categories[i["id"]] = i + first = True + for i in self.categories: + if first: + yield "\n" + yield "\n" + first = False + yield "%s\n" % ( + quoteattr(self.categories[i]["complete_name"]), + ( + ( + "" + % quoteattr( + self.categories[self.categories[i]["parent_id"][0]][ + "complete_name" + ] + ) + ) + if self.categories[i]["parent_id"] + else "" + ), + ) + if not first: + yield "\n" + def export_items(self): """ Send the list of products to frePPLe, based on the product.product model. @@ -1115,7 +1159,7 @@ def export_items(self): self.product_product[i["id"]] = prod_obj self.product_template_product[i["product_tmpl_id"][0]] = prod_obj # For make-to-order items the next line needs to XML snippet ' type="item_mto"'. - yield '\n' % ( + yield '%s\n' % ( quoteattr(name), ( ("description=%s" % (quoteattr(description),)) @@ -1130,7 +1174,6 @@ def export_items(self): ) # Option 1: Map "sales price" to frepple # max(0, tmpl["standard_price"]) or 0) # Option 2: Map the "cost" to frepple / self.convert_qty_uom(1.0, tmpl["uom_id"], i["product_tmpl_id"][0]), - quoteattr(tmpl["categ_id"][1]) if tmpl["categ_id"] else '""', tmpl["uom_id"][0], i["id"], ( @@ -1143,6 +1186,16 @@ def export_items(self): and tmpl["expiration_time"] > 0 else "" ), + ( + ( + "" + % quoteattr( + self.categories[tmpl["categ_id"][0]]["complete_name"] + ) + ) + if tmpl["categ_id"] and tmpl["categ_id"][0] in self.categories + else "" + ), ) # Export suppliers for the item, if the item is allowed to be purchased if tmpl["purchase_ok"]: