add functional field and make uom required by states #048292
This commit is contained in:
parent
3c6ec5295e
commit
ee822431f0
|
@ -17,7 +17,10 @@ class ProductionTemplate(ModelSQL, ModelView):
|
||||||
__name__ = 'production.template'
|
__name__ = 'production.template'
|
||||||
|
|
||||||
name = fields.Char('Name', required=True)
|
name = fields.Char('Name', required=True)
|
||||||
uom = fields.Many2One('product.uom', 'Uom', required=True)
|
uom = fields.Many2One('product.uom', 'Uom',
|
||||||
|
states = {
|
||||||
|
'required': True
|
||||||
|
})
|
||||||
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||||
'on_change_with_unit_digits')
|
'on_change_with_unit_digits')
|
||||||
quantity = fields.Float('Quantity',
|
quantity = fields.Float('Quantity',
|
||||||
|
@ -42,6 +45,21 @@ class ProductionTemplate(ModelSQL, ModelView):
|
||||||
cost_distribution_templates = fields.One2Many(
|
cost_distribution_templates = fields.One2Many(
|
||||||
'production.cost_price.distribution.template',
|
'production.cost_price.distribution.template',
|
||||||
'production_template', "Cost Distribution Templates")
|
'production_template', "Cost Distribution Templates")
|
||||||
|
inputs_products = fields.Function(fields.One2Many('product.product', None,
|
||||||
|
'Products'), 'get_products', searcher='search_input_products')
|
||||||
|
|
||||||
|
def get_products(self, name=None):
|
||||||
|
products = []
|
||||||
|
for template in self.inputs:
|
||||||
|
products += template.products
|
||||||
|
return [x.id for x in products]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_input_products(cls, name, clause):
|
||||||
|
Inputs = Pool().get('production.template.inputs-product.template')
|
||||||
|
product = clause[-1]
|
||||||
|
inputs = Inputs.search([('template.products', '=', product)])
|
||||||
|
return [('id', 'in', [x.production_template.id for x in inputs])]
|
||||||
|
|
||||||
@fields.depends('uom')
|
@fields.depends('uom')
|
||||||
def on_change_with_unit_digits(self, name=None):
|
def on_change_with_unit_digits(self, name=None):
|
||||||
|
@ -57,6 +75,8 @@ class ProductionTemplate(ModelSQL, ModelView):
|
||||||
record.check_cost_distribution()
|
record.check_cost_distribution()
|
||||||
|
|
||||||
def check_input_uoms(self):
|
def check_input_uoms(self):
|
||||||
|
if not self.uom:
|
||||||
|
return
|
||||||
category_uom = self.uom.category
|
category_uom = self.uom.category
|
||||||
uoms = [i.default_uom.category for i in self.inputs]
|
uoms = [i.default_uom.category for i in self.inputs]
|
||||||
uoms.append(category_uom)
|
uoms.append(category_uom)
|
||||||
|
|
Loading…
Reference in New Issue