Skip to content

Commit

Permalink
IMP: support for multilanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Oct 21, 2023
1 parent 138b868 commit 5056ad8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "Product Lifecycle Management",
"version": "16.0.22",
"version": "16.0.23",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
16 changes: 15 additions & 1 deletion plm/models/plm_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,19 @@ def translate_plm_m2o_name(self, objs, field_name, field_value):
object_browse_id = self.env[relation].create({'name': field_value})
return object_browse_id.id
return field_value


@api.model
def get_all_translation(self, object_id, fields):
"""
get all field translated in all available languages
"""
out = {}
obj = self.env[self._name].browse([object_id])
for field_name in fields:
for code in self.env['res.lang'].search([('active','=', True)]).mapped("code"):
propKey = f"{field_name}@-@-@{code}"
out[propKey] = getattr(obj.with_context(lang=code), field_name)
return out



19 changes: 16 additions & 3 deletions plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,11 @@ def translateForClient(self, values=[], forcedLang=''):
readDict = translationBrwsList[0].read(['value'])
values[fieldName] = readDict.get('value', '')
return values


@api.model
def get_all_translation(self, object_id, fields):
return self.product_tmpl_id.get_all_translation(object_id, fields)

def action_rev_docs(self):
"""
This function is called by the button on component view, section LinkedDocuments
Expand Down Expand Up @@ -1715,8 +1719,15 @@ def createFromProps(self, productAttribute):
elif "plm_m2o_" + attribute_name in productAttribute:
value = productAttribute["plm_m2o_" + attribute_name]
sanitaized_attributes[attribute_name] = self.env['product.template'].translate_plm_m2o_name([self.env['product.template'],
self.env['product.product']], attribute_name, value)

self.env['product.product']], attribute_name, value)
language_attrs = {}
for key in list(filter(lambda x: '@-@-@' in x,list(productAttribute.keys()))):
field_name, language = key.split('@-@-@')
if language not in language_attrs:
language_attrs[language] = {field_name: productAttribute[key]}
else:
language_attrs[language][field_name] = productAttribute[key]

engineering_name = sanitaized_attributes.get('engineering_code', False)
if not engineering_name:
return False
Expand All @@ -1733,6 +1744,8 @@ def createFromProps(self, productAttribute):
out_product_produc_id.write(sanitaized_attributes)
else: # write
out_product_produc_id = self.create(sanitaized_attributes)
for lang, translated_values in language_attrs.items():
out_product_produc_id.with_context(lang=lang).write(translated_values)
return out_product_produc_id


Expand Down

0 comments on commit 5056ad8

Please sign in to comment.