From 11042be27a9b2b516511a16a2b1cf316f5996aa1 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Fri, 16 May 2014 12:01:15 +0200 Subject: [PATCH] Make bom and route readonly if process defined and copy values from process --- locale/ca_ES.po | 8 ++++++++ locale/es_ES.po | 8 ++++++++ product.py | 24 +++++++++++++++++++++++- tests/scenario_production.rst | 15 ++++++++------- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/locale/ca_ES.po b/locale/ca_ES.po index 41b8694..4ae994a 100644 --- a/locale/ca_ES.po +++ b/locale/ca_ES.po @@ -18,6 +18,10 @@ msgstr "" "La ruta \"%(bom)s\" no es pot eliminar perquè ha estat creada pel process " "\"%(process)s\"." +msgctxt "field:product.product-production.bom,process:" +msgid "Process" +msgstr "Procés" + msgctxt "field:production,process:" msgid "Process" msgstr "Procés" @@ -62,6 +66,10 @@ msgctxt "field:production.process,operations:" msgid "Operations" msgstr "Operacions" +msgctxt "field:production.process,output_products:" +msgid "Outputs" +msgstr "Sortides" + msgctxt "field:production.process,outputs:" msgid "Outputs" msgstr "Sortides" diff --git a/locale/es_ES.po b/locale/es_ES.po index bb33b29..39c4c07 100644 --- a/locale/es_ES.po +++ b/locale/es_ES.po @@ -18,6 +18,10 @@ msgstr "" "La ruta \"%(route)s\" no se puede eliminar porqué ha sido creada por el " "proceso \"%(process)s\"." +msgctxt "field:product.product-production.bom,process:" +msgid "Process" +msgstr "Proceso" + msgctxt "field:production,process:" msgid "Process" msgstr "Proceso" @@ -62,6 +66,10 @@ msgctxt "field:production.process,operations:" msgid "Operations" msgstr "Operaciones" +msgctxt "field:production.process,output_products:" +msgid "Outputs" +msgstr "Salidas" + msgctxt "field:production.process,outputs:" msgid "Outputs" msgstr "Salidas" diff --git a/product.py b/product.py index 5536314..e39bdbd 100644 --- a/product.py +++ b/product.py @@ -16,7 +16,29 @@ class ProductBom: ('output_products', '=', If(Bool(Eval('product')), Eval('product', 0), Get(Eval('_parent_product', {}), 'id', 0))), - ], depends=['product']) + ], + depends=['product'], on_change=['process', 'bom', 'route']) + + @classmethod + def __setup__(cls): + super(ProductBom, cls).__setup__() + if not 'process' in cls.bom.depends: + cls.bom.states.update({ + 'readonly': Bool(Eval('process', 0)), + }) + cls.bom.depends.append('process') + if not 'process' in cls.route.depends: + cls.route.states.update({ + 'readonly': Bool(Eval('process', 0)), + }) + cls.route.depends.append('process') + + def on_change_process(self): + res = {} + if self.process: + res['bom'] = self.process.bom.id + res['route'] = self.process.route.id + return res @classmethod def create(cls, vlist): diff --git a/tests/scenario_production.rst b/tests/scenario_production.rst index dc02f8c..6283dba 100644 --- a/tests/scenario_production.rst +++ b/tests/scenario_production.rst @@ -204,17 +204,18 @@ Create a process definition:: >>> len(process.route.operations) == 2 True >>> bom = process.bom - >>> len(bom.inputs) == 2 - True - >>> len(bom.outputs) == 1 - True + >>> route = process.route >>> ProductBom = Model.get('product.product-production.bom') - >>> product.processes.append(ProductBom(process=process)) + >>> product_bom = ProductBom() + >>> product.boms.append(product_bom) + >>> product_bom.process = process + >>> product_bom.bom == bom + True + >>> product_bom.route == route + True >>> product.save() >>> len(product.boms) == 1 True - >>> product.boms[0].bom == bom - True Create an Inventory::