Skip to content

Commit

Permalink
Merge pull request #456 from frePPLe/16.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (16.0)
  • Loading branch information
bt-admin authored Jul 6, 2024
2 parents 5ee1631 + d2384bb commit bfced59
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions frepple/controllers/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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.")
Expand Down Expand Up @@ -997,6 +998,49 @@ def export_workcenters(self):
if not first:
yield "</resources>\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 "<!-- categories -->\n"
yield "<items>\n"
first = False
yield "<item name=%s>%s</item>\n" % (
quoteattr(self.categories[i]["complete_name"]),
(
(
"<owner name=%s/>"
% quoteattr(
self.categories[self.categories[i]["parent_id"][0]][
"complete_name"
]
)
)
if self.categories[i]["parent_id"]
else ""
),
)
if not first:
yield "</items>\n"

def export_items(self):
"""
Send the list of products to frePPLe, based on the product.product model.
Expand Down Expand Up @@ -1141,7 +1185,7 @@ def export_items(self):
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 '<item name=%s %s uom=%s volume="%f" weight="%f" cost="%f" category=%s subcategory="%s,%s"%s%s>\n' % (
yield '<item name=%s %s uom=%s volume="%f" weight="%f" cost="%f" subcategory="%s,%s"%s%s>%s\n' % (
quoteattr(name),
(
("description=%s" % (quoteattr(description),))
Expand All @@ -1156,7 +1200,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"],
' type="item_mto"' if self.route_mto in tmpl["route_ids"] else "",
Expand All @@ -1170,6 +1213,16 @@ def export_items(self):
and tmpl["expiration_time"] > 0
else ""
),
(
(
"<owner name=%s/>"
% 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"]:
Expand Down

0 comments on commit bfced59

Please sign in to comment.