#046285 pass quality,sample and certifications from inputs variant to outputs variants on productions
This commit is contained in:
parent
0cc6648220
commit
75bffe9fd1
|
@ -34,6 +34,7 @@ def register():
|
|||
weighing.Weighing,
|
||||
weighing.WeighingPlantation,
|
||||
weighing.WeighingDo,
|
||||
# quality.QualitySample,
|
||||
quality.QualityTest,
|
||||
quality.QuantitativeTestLine,
|
||||
quality.QualitativeTestLine,
|
||||
|
|
|
@ -108,6 +108,9 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
['wine', 'unfiltered-wine', 'filtered-wine', 'clarified-wine',
|
||||
'bottled-wine']
|
||||
)}, depends=['agronomic_type']), 'get_alcohol_volume')
|
||||
quality_tests = fields.One2Many('quality.test', 'document', 'Quality Tests')
|
||||
quality_samples = fields.One2Many('quality.sample', 'product',
|
||||
'Quality Samples')
|
||||
|
||||
@classmethod
|
||||
def validate(cls, products):
|
||||
|
|
|
@ -30,6 +30,9 @@ class ProductionTemplate(ModelSQL, ModelView):
|
|||
enology_products = fields.One2Many('production.template.line',
|
||||
'production_template', 'Complementary Products')
|
||||
pass_feature = fields.Boolean('Pass on Feature')
|
||||
pass_quality = fields.Boolean('Pass Quality')
|
||||
pass_certification = fields.Boolean('Pass Certification')
|
||||
pass_quality_sample = fields.Boolean('Pass Quality Sample')
|
||||
cost_distribution_template = fields.Many2One(
|
||||
'production.cost_price.distribution.template',
|
||||
"Default cost distribution template",
|
||||
|
@ -178,11 +181,30 @@ class Production(metaclass=PoolMeta):
|
|||
fields.Many2Many('product.template',
|
||||
None, None, "Cost Product Templates"),
|
||||
'on_change_with_cost_distribution_templates')
|
||||
pass_quality = fields.Boolean('Pass Quality')
|
||||
pass_certification = fields.Boolean('Pass Certification')
|
||||
pass_quality_sample = fields.Boolean('Pass Quality Sample')
|
||||
|
||||
|
||||
@classmethod
|
||||
def set_allowed_products(cls, productions, name, value):
|
||||
pass
|
||||
|
||||
@fields.depends('production_template')
|
||||
def on_change_with_pass_quality(self):
|
||||
if self.production_template:
|
||||
return self.production_template.pass_quality
|
||||
|
||||
@fields.depends('production_template')
|
||||
def on_change_with_pass_certification(self):
|
||||
if self.production_template:
|
||||
return self.production_template.pass_certification
|
||||
|
||||
@fields.depends('production_template')
|
||||
def on_change_with_pass_quality_sample(self):
|
||||
if self.production_template:
|
||||
return self.production_template.pass_quality_sample
|
||||
|
||||
@fields.depends('production_template')
|
||||
def on_change_production_template(self):
|
||||
if (self.production_template and
|
||||
|
@ -335,6 +357,40 @@ class Production(metaclass=PoolMeta):
|
|||
product.template = template
|
||||
return product
|
||||
|
||||
def copy_certification(self, new_product):
|
||||
products = [x.product for x in self.inputs if x.product.certification]
|
||||
if not self.pass_certification or len(products) != 1:
|
||||
return new_product
|
||||
certification = products[0].certification
|
||||
new_product.certication = certification
|
||||
return new_product
|
||||
|
||||
def copy_quality_samples(self, new_product):
|
||||
QualitySample = Pool().get('quality.sample')
|
||||
products = [x.product for x in self.inputs if x.product.quality_samples]
|
||||
if not self.pass_certification or len(products) != 1:
|
||||
return new_product
|
||||
samples = products[0].quality_samples
|
||||
new_samples = QualitySample.copy(samples, {'product':new_product})
|
||||
QualitySample.done(new_samples)
|
||||
return new_product
|
||||
|
||||
def copy_quality(self, new_product):
|
||||
Quality = Pool().get('quality.test')
|
||||
products = [x.product for x in self.inputs]
|
||||
|
||||
if not self.pass_quality:
|
||||
return
|
||||
|
||||
tests = []
|
||||
for product in products:
|
||||
if tests and product.quality_tests:
|
||||
return
|
||||
tests += product.quality_tests or []
|
||||
new_tests = Quality.copy(tests, {'document': str(new_product)})
|
||||
Quality.confirmed(new_tests)
|
||||
Quality.manager_validate(new_tests)
|
||||
|
||||
def pass_feature(self, product):
|
||||
Variety = Pool().get('product.variety')
|
||||
Uom = Pool().get('product.uom')
|
||||
|
@ -378,6 +434,7 @@ class Production(metaclass=PoolMeta):
|
|||
product = production.create_variant(distrib.product,
|
||||
production.production_template.pass_feature)
|
||||
product = production.pass_feature(product)
|
||||
product = production.copy_certification(product)
|
||||
move = production._move(
|
||||
production.location,
|
||||
distrib.location,
|
||||
|
@ -388,8 +445,13 @@ class Production(metaclass=PoolMeta):
|
|||
move.production_output = production
|
||||
move.unit_price = Decimal(0)
|
||||
moves.append(move)
|
||||
|
||||
Move.save(moves)
|
||||
super().done(productions)
|
||||
for production in productions:
|
||||
for output in production.outputs:
|
||||
production.copy_quality(output.product)
|
||||
production.copy_quality_samples(output.product)
|
||||
|
||||
@classmethod
|
||||
def set_cost(cls, productions):
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import fields, Model
|
||||
from trytond.model import fields, Model, DeactivableMixin
|
||||
from trytond.modules.agronomics.wine import _WINE_DIGITS
|
||||
|
||||
class QualitySample(DeactivableMixin, metaclass=PoolMeta):
|
||||
__name__ = 'quality.sample'
|
||||
|
||||
|
||||
class QualityTest(metaclass=PoolMeta):
|
||||
__name__ = 'quality.test'
|
||||
|
|
|
@ -188,6 +188,7 @@ Create Production Template::
|
|||
>>> production_template.inputs.append(productA.template)
|
||||
>>> production_template.outputs.append(mostflor)
|
||||
>>> production_template.outputs.append(mostprimeres)
|
||||
>>> production_template.pass_quality = True
|
||||
>>> line = ProductionTemplateLine()
|
||||
>>> line.product = product2
|
||||
>>> line.quantity = 100
|
||||
|
@ -202,6 +203,10 @@ Create Production Template::
|
|||
>>> production_template.enology_products.append(line)
|
||||
>>> production_template.save()
|
||||
|
||||
Create Test:
|
||||
|
||||
>>> QualityTest = Model.get('quality.test')
|
||||
>>> Test = QualityTest()
|
||||
|
||||
Create an Inventory::
|
||||
|
||||
|
@ -315,3 +320,5 @@ Create Production
|
|||
[('Parellada', 16.6667), ('Macabeu', 83.3334)]
|
||||
>>> [x.name for x in most.product.denominations_of_origin]
|
||||
['Catalunya']
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<label name="production_template"/>
|
||||
<field name="production_template"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page[@id='other']/field[@name='done_by']" position="after">
|
||||
<label name="pass_quality"/>
|
||||
<field name="pass_quality"/>
|
||||
<label name="pass_quality_sample"/>
|
||||
<field name="pass_quality_sample"/>
|
||||
<label name="pass_certification"/>
|
||||
<field name="pass_certification"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook" position="inside">
|
||||
<page name="enology_products">
|
||||
<field name="enology_products" colspan="4"/>
|
||||
|
|
|
@ -4,12 +4,26 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<form>
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="pass_feature"/>
|
||||
<field name="pass_feature"/>
|
||||
<newline/>
|
||||
<group colspan="2" col="4" id="quantities">
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="uom"/>
|
||||
<field name="uom"/>
|
||||
</group>
|
||||
<group colspan="2" col="2" id="pass_features">
|
||||
<label name="pass_feature"/>
|
||||
<field name="pass_feature"/>
|
||||
<newline/>
|
||||
<label name="pass_quality"/>
|
||||
<field name="pass_quality"/>
|
||||
<newline/>
|
||||
<label name="pass_quality_sample"/>
|
||||
<field name="pass_quality_sample"/>
|
||||
<newline/>
|
||||
<label name="pass_certification"/>
|
||||
<field name="pass_certification"/>
|
||||
</group>
|
||||
<field name="inputs" colspan="2"/>
|
||||
<field name="outputs" colspan="2"/>
|
||||
<field name="enology_products" colspan="4"/>
|
||||
|
|
18
weighing.py
18
weighing.py
|
@ -100,7 +100,8 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
], "State", readonly=True, required=True)
|
||||
state_string = state.translated('state')
|
||||
all_do = fields.Function(fields.Char('All DO'), 'get_all_do')
|
||||
quality_test = fields.Many2One('quality.test', 'Test')
|
||||
quality_test = fields.Function(fields.Many2One('quality.test', 'Test'),
|
||||
'get_quality_test')
|
||||
product_created = fields.Many2One('product.product', 'Product Created',
|
||||
readonly=True)
|
||||
|
||||
|
@ -157,6 +158,12 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
def get_all_do(self, name):
|
||||
return ",".join([x.name for x in self.denomination_origin])
|
||||
|
||||
def get_quality_test(self, name):
|
||||
if not self.product_created:
|
||||
return
|
||||
tests = self.product_created.quality_tests
|
||||
return tests and tests[0] and tests[0].id
|
||||
|
||||
@fields.depends('weighing_date')
|
||||
def on_change_with_crop(self):
|
||||
Crop = Pool().get('agronomics.crop')
|
||||
|
@ -252,6 +259,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
def analysis(cls, weighings):
|
||||
pool = Pool()
|
||||
Product = pool.get('product.product')
|
||||
Quality = pool.get('quality.test')
|
||||
default_product_values = Product.default_get(Product._fields.keys(),
|
||||
with_rec_name=False)
|
||||
product = Product(**default_product_values)
|
||||
|
@ -262,9 +270,13 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
product.varieties = [weighing.variety.id]
|
||||
product.vintages = [weighing.crop.id]
|
||||
weighing.product_created = product
|
||||
weighing.quality_test = weighing.create_quality_test()
|
||||
# weighing.quality_test = weighing.create_quality_test(product)
|
||||
|
||||
cls.save(weighings)
|
||||
tests = []
|
||||
for weighing in weighings:
|
||||
tests.append(weighing.create_quality_test())
|
||||
Quality.save(tests)
|
||||
|
||||
def create_quality_test(self):
|
||||
pool = Pool()
|
||||
|
@ -277,7 +289,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
test = QualityTest(
|
||||
test_date=datetime.now(),
|
||||
templates=[template],
|
||||
document=str(self))
|
||||
document=str(self.product_created))
|
||||
test.apply_template_values()
|
||||
|
||||
return test
|
||||
|
|
Loading…
Reference in New Issue