Skip to content

Commit

Permalink
Merge pull request #406 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 Feb 13, 2024
2 parents 9896981 + dfbf002 commit 0f8dd84
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions frepple/controllers/frepplexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def xml(self, **kwargs):
== "true",
version=version,
delta=float(kwargs.get("delta", 999)),
language=language,
)
# last empty double quote is to let python understand frepple is a folder.
xml_folder = os.path.join(str(Path.home()), "logs", "frepple", "")
Expand Down
53 changes: 47 additions & 6 deletions frepple/controllers/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(
singlecompany=False,
version="0.0.0.unknown",
delta=999,
language="en_US",
):
self.database = database
self.company = company
Expand All @@ -185,6 +186,7 @@ def __init__(
self.timeformat = "%Y-%m-%dT%H:%M:%S"
self.singlecompany = singlecompany
self.delta = delta
self.language = language

# The mode argument defines different types of runs:
# - Mode 1:
Expand Down Expand Up @@ -342,16 +344,13 @@ def load_uom(self):
unit of measure of the uom dimension.
"""
self.uom = {}
self.uom_categories = {}
for i in self.generator.getData(
"uom.uom",
# We also need to load INactive UOMs, because there still might be records
# using the inactive UOM. Questionable practice, but can happen...
search=["|", ("active", "=", 1), ("active", "=", 0)],
fields=["factor", "uom_type", "category_id", "name"],
):
if i["uom_type"] == "reference":
self.uom_categories[i["category_id"][0]] = i["id"]
self.uom[i["id"]] = {
"factor": i["factor"],
"category": i["category_id"][0],
Expand Down Expand Up @@ -1013,6 +1012,34 @@ def export_items(self):
):
self.product_templates[i["id"]] = i

# Check if we can use short names
# To use short names, the internal reference (or the name when no internal reference is defined)
# needs to be unique
use_short_names = True

self.generator.env.cr.execute(
"""
select count(*) from
(
select coalesce(product_product.default_code,
product_template.name->>%s,
product_template.name->>'en_US'), count(*)
from product_product
inner join product_template on product_product.product_tmpl_id = product_template.id
where product_template.type not in ('service', 'consu')
group by coalesce(product_product.default_code,
product_template.name->>%s,
product_template.name->>'en_US')
having count(*) > 1
) t
""",
(self.language, self.language),
)
for i in self.generator.env.cr.fetchall():
if i[0] > 0:
use_short_names = False
break

# Read the products
supplierinfo_fields = [
"partner_id",
Expand Down Expand Up @@ -1047,13 +1074,20 @@ def export_items(self):
continue
tmpl = self.product_templates[i["product_tmpl_id"][0]]
if i["code"]:
name = ("[%s] %s" % (i["code"], i["name"]))[:300]
name = (
(("[%s] %s" % (i["code"], i["name"]))[:300])
if not use_short_names
else i["code"][:300]
)
description = i["name"][:500] if use_short_names else None
# product is a variant and has no internal reference
# we use the product id as code
elif i["product_template_attribute_value_ids"]:
name = ("[%s] %s" % (i["id"], i["name"]))[:300]
description = i["name"][:500] if use_short_names else None
else:
name = i["name"][:300]
description = i["name"][:500] if use_short_names else None
prod_obj = {
"name": name,
"template": i["product_tmpl_id"][0],
Expand All @@ -1063,8 +1097,15 @@ def export_items(self):
}
self.product_product[i["id"]] = prod_obj
self.product_template_product[i["product_tmpl_id"][0]] = prod_obj
yield '<item name=%s uom=%s volume="%f" weight="%f" cost="%f" category=%s subcategory="%s,%s" %s>\n' % (

# 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>\n' % (
quoteattr(name),
(
("description=%s" % (quoteattr(description),))
if use_short_names
else ""
),
quoteattr(tmpl["uom_id"][1]) if tmpl["uom_id"] else "",
i["volume"] or 0,
i["weight"] or 0,
Expand All @@ -1074,7 +1115,7 @@ def export_items(self):
# 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 '""',
self.uom_categories[self.uom[tmpl["uom_id"][0]]["category"]],
tmpl["uom_id"][0],
i["id"],
' type="item_mto"' if self.route_mto in tmpl["route_ids"] else "",
)
Expand Down

0 comments on commit 0f8dd84

Please sign in to comment.