diff --git a/frepple/controllers/frepplexml.py b/frepple/controllers/frepplexml.py index bbdb3bc5..31077cdd 100644 --- a/frepple/controllers/frepplexml.py +++ b/frepple/controllers/frepplexml.py @@ -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", "") diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index 47babcab..fc88862c 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -161,6 +161,7 @@ def __init__( singlecompany=False, version="0.0.0.unknown", delta=999, + language="en_US", ): self.database = database self.company = company @@ -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: @@ -342,7 +344,6 @@ 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 @@ -350,8 +351,6 @@ def load_uom(self): 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], @@ -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", @@ -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], @@ -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 '\n' % ( + + # For make-to-order items the next line needs to XML snippet ' type="item_mto"'. + yield '\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, @@ -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 "", )