mirror of
https://github.com/NaN-tic/trytond-agronomics.git
synced 2023-12-14 05:33:01 +01:00
add setter to quality_test
This commit is contained in:
parent
3f9d2d4959
commit
71afd8848d
|
@ -173,10 +173,12 @@ class Production(metaclass=PoolMeta):
|
||||||
'production.cost_price.distribution.template',
|
'production.cost_price.distribution.template',
|
||||||
"Cost Distribution Template",
|
"Cost Distribution Template",
|
||||||
domain=[
|
domain=[
|
||||||
('id', 'in', Eval('production_template_cost_distribution_templates'))
|
('id', 'in',
|
||||||
|
Eval('production_template_cost_distribution_templates'))
|
||||||
], states={
|
], states={
|
||||||
'readonly': Eval('state').in_(['cancelled', 'done']),
|
'readonly': Eval('state').in_(['cancelled', 'done']),
|
||||||
}, depends=['state', 'production_template_cost_distribution_templates'])
|
}, depends=['state',
|
||||||
|
'production_template_cost_distribution_templates'])
|
||||||
cost_distribution_templates = fields.Function(
|
cost_distribution_templates = fields.Function(
|
||||||
fields.Many2Many('product.template',
|
fields.Many2Many('product.template',
|
||||||
None, None, "Cost Product Templates"),
|
None, None, "Cost Product Templates"),
|
||||||
|
@ -185,7 +187,6 @@ class Production(metaclass=PoolMeta):
|
||||||
pass_certification = fields.Boolean('Pass Certification')
|
pass_certification = fields.Boolean('Pass Certification')
|
||||||
pass_quality_sample = fields.Boolean('Pass Quality Sample')
|
pass_quality_sample = fields.Boolean('Pass Quality Sample')
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_allowed_products(cls, productions, name, value):
|
def set_allowed_products(cls, productions, name, value):
|
||||||
pass
|
pass
|
||||||
|
@ -217,8 +218,8 @@ class Production(metaclass=PoolMeta):
|
||||||
products = []
|
products = []
|
||||||
if not self.production_template:
|
if not self.production_template:
|
||||||
return []
|
return []
|
||||||
for x in self.production_template.inputs:
|
for input_ in self.production_template.inputs:
|
||||||
products += x.products
|
products += input_.products
|
||||||
return [x.id for x in products]
|
return [x.id for x in products]
|
||||||
|
|
||||||
@fields.depends('production_template')
|
@fields.depends('production_template')
|
||||||
|
@ -271,7 +272,7 @@ class Production(metaclass=PoolMeta):
|
||||||
gettext('agronomics.msg_check_production_percentatge',
|
gettext('agronomics.msg_check_production_percentatge',
|
||||||
production=self.rec_name,
|
production=self.rec_name,
|
||||||
percentatge=percentatge * 100,
|
percentatge=percentatge * 100,
|
||||||
))
|
))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wait(cls, productions):
|
def wait(cls, productions):
|
||||||
|
@ -417,17 +418,17 @@ class Production(metaclass=PoolMeta):
|
||||||
product.vintages = list(set(vintages))
|
product.vintages = list(set(vintages))
|
||||||
varieties = {}
|
varieties = {}
|
||||||
for input in self.inputs:
|
for input in self.inputs:
|
||||||
percent = round(input.quantity/total_output, 6)
|
percent = round(input.quantity / total_output, 6)
|
||||||
for variety in input.product.varieties:
|
for variety in input.product.varieties:
|
||||||
new_variety = varieties.get(variety.variety)
|
new_variety = varieties.get(variety.variety)
|
||||||
if not new_variety:
|
if not new_variety:
|
||||||
new_variety = Variety()
|
new_variety = Variety()
|
||||||
new_variety.percent = 0
|
new_variety.percent = 0
|
||||||
new_variety.variety = variety.variety
|
new_variety.variety = variety.variety
|
||||||
new_variety.percent += variety.percent/100.0*percent
|
new_variety.percent += variety.percent / 100.0 * percent
|
||||||
varieties[new_variety.variety] = new_variety
|
varieties[new_variety.variety] = new_variety
|
||||||
for key, variety in varieties.items():
|
for key, variety in varieties.items():
|
||||||
variety.percent = "%.4f" % round(100.0*variety.percent, 4)
|
variety.percent = "%.4f" % round(100.0 * variety.percent, 4)
|
||||||
product.varieties = varieties.values()
|
product.varieties = varieties.values()
|
||||||
return product
|
return product
|
||||||
|
|
||||||
|
@ -485,7 +486,8 @@ class Production(metaclass=PoolMeta):
|
||||||
if output.product not in products:
|
if output.product not in products:
|
||||||
continue
|
continue
|
||||||
has_product = True
|
has_product = True
|
||||||
cost = production_cost * (1 + cdist.percentatge) - production_cost
|
cost = (production_cost * (1 + cdist.percentatge) -
|
||||||
|
production_cost)
|
||||||
output_cost += round_price(cost / Decimal(total_output))
|
output_cost += round_price(cost / Decimal(total_output))
|
||||||
|
|
||||||
output_cost = output_cost if has_product else Decimal(0)
|
output_cost = output_cost if has_product else Decimal(0)
|
||||||
|
@ -560,7 +562,8 @@ class OutputDistribution(ModelSQL, ModelView):
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
context['locations'] = [self.location.id]
|
context['locations'] = [self.location.id]
|
||||||
with Transaction().set_context(context):
|
with Transaction().set_context(context):
|
||||||
quantities = Product.get_quantity(self.product.products, 'quantity')
|
quantities = Product.get_quantity(self.product.products,
|
||||||
|
'quantity')
|
||||||
self.initial_quantity = sum(quantities.values())
|
self.initial_quantity = sum(quantities.values())
|
||||||
|
|
||||||
@fields.depends('location', methods=['on_change_product'])
|
@fields.depends('location', methods=['on_change_product'])
|
||||||
|
@ -579,7 +582,8 @@ class OutputDistribution(ModelSQL, ModelView):
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
context['locations'] = [self.location.id]
|
context['locations'] = [self.location.id]
|
||||||
with Transaction().set_context(context):
|
with Transaction().set_context(context):
|
||||||
quantities = Product.get_quantity(self.product.products, 'quantity')
|
quantities = Product.get_quantity(self.product.products,
|
||||||
|
'quantity')
|
||||||
return sum(quantities.values())
|
return sum(quantities.values())
|
||||||
|
|
||||||
@fields.depends('final_quantity', 'initial_quantity')
|
@fields.depends('final_quantity', 'initial_quantity')
|
||||||
|
@ -625,7 +629,7 @@ class ProductionCostPriceDistribution(ModelSQL, ModelView):
|
||||||
__name__ = 'production.cost_price.distribution'
|
__name__ = 'production.cost_price.distribution'
|
||||||
template = fields.Many2One('product.template', "Template", required=True,
|
template = fields.Many2One('product.template', "Template", required=True,
|
||||||
ondelete='RESTRICT')
|
ondelete='RESTRICT')
|
||||||
origin = fields.Reference('Origin', selection='_get_models', required=True,)
|
origin = fields.Reference('Origin', selection='_get_models', required=True)
|
||||||
percentatge = fields.Numeric("Percentatge", digits=(16, 4), required=True)
|
percentatge = fields.Numeric("Percentatge", digits=(16, 4), required=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
15
weighing.py
15
weighing.py
|
@ -100,8 +100,11 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
||||||
], "State", readonly=True, required=True)
|
], "State", readonly=True, required=True)
|
||||||
state_string = state.translated('state')
|
state_string = state.translated('state')
|
||||||
all_do = fields.Function(fields.Char('All DO'), 'get_all_do')
|
all_do = fields.Function(fields.Char('All DO'), 'get_all_do')
|
||||||
quality_test = fields.Function(fields.Many2One('quality.test', 'Test'),
|
quality_test = fields.Function(fields.Many2One('quality.test', 'Test',
|
||||||
'get_quality_test')
|
states={
|
||||||
|
'readonly': Eval('state').in_(READONLY),
|
||||||
|
}),
|
||||||
|
'get_quality_test', 'set_quality_test')
|
||||||
product_created = fields.Many2One('product.product', 'Product Created',
|
product_created = fields.Many2One('product.product', 'Product Created',
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
@ -164,6 +167,13 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
||||||
tests = self.product_created.quality_tests
|
tests = self.product_created.quality_tests
|
||||||
return tests and tests[0] and tests[0].id
|
return tests and tests[0] and tests[0].id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_quality_test(cls, weighings, name, value):
|
||||||
|
Test = Pool().get('quality.test')
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
@fields.depends('weighing_date')
|
@fields.depends('weighing_date')
|
||||||
def on_change_with_crop(self):
|
def on_change_with_crop(self):
|
||||||
Crop = Pool().get('agronomics.crop')
|
Crop = Pool().get('agronomics.crop')
|
||||||
|
@ -360,6 +370,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
||||||
else:
|
else:
|
||||||
default = default.copy()
|
default = default.copy()
|
||||||
default.setdefault('beneficiaries', None)
|
default.setdefault('beneficiaries', None)
|
||||||
|
default.setdefault('product_created', None)
|
||||||
return super().copy(weighings, default=default)
|
return super().copy(weighings, default=default)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue