diff --git a/CHANGELOG b/CHANGELOG index d04ed00ad6..09d5321ccf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow to define effective date of productions + Version 3.0.0 - 2013-10-21 * Bug fixes (see mercurial logs for details) * Add calendar view diff --git a/production.py b/production.py index ca2a06239d..2613841135 100644 --- a/production.py +++ b/production.py @@ -30,7 +30,11 @@ class Production(Workflow, ModelSQL, ModelView): 'readonly': ~Eval('state').in_(['request', 'draft']), }, depends=['state']) - effective_date = fields.Date('Effective Date', readonly=True) + effective_date = fields.Date('Effective Date', + states={ + 'readonly': Eval('state').in_(['cancel', 'done']), + }, + depends=['state']) company = fields.Many2One('company.company', 'Company', required=True, states={ 'readonly': ~Eval('state').in_(['request', 'draft']), @@ -545,7 +549,7 @@ class Production(Workflow, ModelSQL, ModelView): Move = pool.get('stock.move') Date = pool.get('ir.date') Move.do([m for p in productions for m in p.outputs]) - cls.write(productions, { + cls.write([p for p in productions if not p.effective_date], { 'effective_date': Date.today(), }) diff --git a/stock.py b/stock.py index ffc7ecb065..0985784800 100644 --- a/stock.py +++ b/stock.py @@ -33,3 +33,10 @@ class Move: readonly=True, select=True, ondelete='CASCADE', domain=[('company', '=', Eval('company'))], depends=['company']) + + def set_effective_date(self): + if not self.effective_date and self.production_input: + self.effective_date = self.production_input.effective_date + if not self.effective_date and self.production_output: + self.effective_date = self.production_output.effective_date + super(Move, self).set_effective_date() diff --git a/tests/scenario_production.rst b/tests/scenario_production.rst index d91f191621..57432b0af1 100644 --- a/tests/scenario_production.rst +++ b/tests/scenario_production.rst @@ -13,6 +13,7 @@ Imports:: >>> from decimal import Decimal >>> from proteus import config, Model, Wizard >>> today = datetime.date.today() + >>> yesterday = today - relativedelta(days=1) Create database:: @@ -145,11 +146,11 @@ Create an Inventory:: >>> inventory_line1 = InventoryLine() >>> inventory.lines.append(inventory_line1) >>> inventory_line1.product = component1 - >>> inventory_line1.quantity = 10 + >>> inventory_line1.quantity = 20 >>> inventory_line2 = InventoryLine() >>> inventory.lines.append(inventory_line2) >>> inventory_line2.product = component2 - >>> inventory_line2.quantity = 5 + >>> inventory_line2.quantity = 6 >>> inventory.save() >>> Inventory.confirm([inventory.id], config.context) >>> inventory.state @@ -182,12 +183,37 @@ Make a production:: >>> production.reload() >>> all(i.state == 'done' for i in production.inputs) True + >>> all(i.effective_date == today for i in production.inputs) + True >>> Production.done([production.id], config.context) >>> production.reload() >>> output, = production.outputs >>> output.state u'done' + >>> output.effective_date == today + True >>> config._context['locations'] = [storage.id] >>> product.reload() >>> product.quantity == 2 True + +Make a production with effective date yesterday:: + + >>> Production = Model.get('production') + >>> production = Production() + >>> production.effective_date = yesterday + >>> production.product = product + >>> production.bom = bom + >>> production.quantity = 2 + >>> production.click('wait') + >>> Production.assign_try([production.id], config.context) + True + >>> production.click('run') + >>> production.reload() + >>> all(i.effective_date == yesterday for i in production.inputs) + True + >>> production.click('done') + >>> production.reload() + >>> output, = production.outputs + >>> output.effective_date == yesterday + True