Skip to content

Commit

Permalink
IMP: plm outo internal ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Oct 12, 2024
1 parent 2e5135f commit d4aac31
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 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.29",
"version": "16.0.30",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
11 changes: 6 additions & 5 deletions plm/models/plm_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,12 @@ 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)
obj = self.env[self._name].search([('id','=',object_id)])
if obj:
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


Expand Down
2 changes: 1 addition & 1 deletion plm_auto_internalref/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "PLM Auto Internal Reference",
"version": "16.0.1",
"version": "16.0.2",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
40 changes: 8 additions & 32 deletions plm_auto_internalref/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
class ProductProductExtension(models.Model):
_name = 'product.product'
_inherit = 'product.product'

@api.model_create_multi
def create(self, vals):
for val_dict in vals:
new_default_code = self.computeDefaultCode(val_dict)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
val_dict['default_code'] = new_default_code
return super().create(vals)

@property
def getDefaultCodeTemplate(self):
Expand All @@ -55,34 +46,19 @@ def computeDefaultCode(self,
:vals dict like with all the value that be updated
:objBrowse product.product or product.template in case of write operation
"""
out = False
in_revision = self.env.context.get('new_revision', False)
engineering_code = vals.get('engineering_code', '')
engineering_revision = vals.get('engineering_revision', 0)
default_code = vals.get('default_code')
if objBrowse: #suppose write operation
if objBrowse: # suppose write operation
if not engineering_code:
engineering_code = objBrowse.engineering_code
if not engineering_revision:
engineering_revision = objBrowse.engineering_revision
if not default_code:
default_code = objBrowse.default_code
if in_revision and engineering_code and engineering_code != '-':
out = self.getDefaultCodeTemplate % (engineering_code, engineering_revision)
if engineering_code and not default_code and engineering_code != '-':
out = self.getDefaultCodeTemplate % (engineering_code, engineering_revision)
if default_code == out:
return False
return out

def write(self, vals):
ret = False
for product in self:
new_default_code = product.computeDefaultCode(vals,
product)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
vals['default_code'] = new_default_code
ret = super(models.Model, product).write(vals)
return ret
return self.getDefaultCodeTemplate % (engineering_code, engineering_revision)

@api.onchange('engineering_code')
def oc_engineering_code(self):
for pp_id in self:
pp_id.default_code=pp_id.computeDefaultCode({},
pp_id.product_tmpl_id)

23 changes: 5 additions & 18 deletions plm_auto_internalref/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,10 @@ class ProductTemplateExtension(models.Model):
_name = 'product.template'
_inherit = 'product.template'

@api.model_create_multi
def create(self, vals):
obj_pp = self.env['product.product']
for val_dict in vals:
new_default_code = obj_pp.computeDefaultCode(val_dict)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
val_dict['default_code'] = new_default_code
return super().create(vals)

def write(self, vals):
new_default_code = self.env['product.product'].computeDefaultCode(vals,
self)
if new_default_code :
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
vals['default_code'] = new_default_code
return super(ProductTemplateExtension, self).write(vals)

@api.onchange('engineering_code')
def oc_engineering_code(self):
for pt_id in self:
pt_id.default_code=self.env['product.product'].computeDefaultCode({},
pt_id)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 comments on commit d4aac31

Please sign in to comment.