This commit is contained in:
2026-01-26 17:32:33 +01:00
parent fbfc943301
commit 757b9f724d
5 changed files with 145 additions and 8 deletions

View File

@@ -609,6 +609,26 @@ class Product(
('template.code', operator, code_value, *extra),
]
@classmethod
def get_by_name(cls, name, type_='goods'):
pool = Pool()
Template = pool.get('product.template')
Uom = pool.get('product.uom')
templates = Template.search([('name', '=', name)], limit=1)
if templates:
return templates[0].products[0]
unit_uom, = Uom.search([('name', '=', 'Mt')], limit=1)
template, = Template.create([{
'name': name,
'type': type_,
'default_uom': unit_uom.id,
'cost_price_method': 'fixed',
}])
return template.products[0]
@staticmethod
def get_price_uom(products, name):
Uom = Pool().get('product.uom')

View File

@@ -92,6 +92,13 @@ class Uom(SymbolMixin, DigitsMixin, DeactivableMixin, ModelSQL, ModelView):
def default_digits():
return 2
@classmethod
def get_by_name(cls, name):
uom = cls.search([('symbol', '=', name)], limit=1)
if not uom:
return None
return uom[0]
@fields.depends('factor')
def on_change_factor(self):
if (self.factor or 0.0) == 0.0: