diff --git a/stock.py b/stock.py index 161b2389f2..812ef8d4f2 100644 --- a/stock.py +++ b/stock.py @@ -2,7 +2,7 @@ #this repository contains the full copyright notices and license terms. from decimal import Decimal -from trytond.model import fields +from trytond.model import Workflow, ModelView, fields from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction @@ -168,15 +168,9 @@ class Move: return super(Move, cls).copy(moves, default=default) @classmethod - def create(cls, vals): - move = super(Move, cls).create(vals) - if vals.get('state') == 'done': + @ModelView.button + @Workflow.transition('done') + def do(cls, moves): + super(Move, cls).do(moves) + for move in moves: move._create_account_stock_move() - return move - - @classmethod - def write(cls, moves, vals): - super(Move, cls).write(moves, vals) - if vals.get('state') == 'done': - for move in moves: - move._create_account_stock_move() diff --git a/tests/scenario_account_stock_continental.rst b/tests/scenario_account_stock_continental.rst index d267c5d7fe..9954ffbea6 100644 --- a/tests/scenario_account_stock_continental.rst +++ b/tests/scenario_account_stock_continental.rst @@ -345,8 +345,8 @@ Create Move from Supplier to Customer:: >>> move.unit_price = Decimal(6) >>> move.cost_price = move.unit_price >>> move.currency = currency - >>> move.state = 'done' >>> move.save() + >>> Move.do([move.id], config.context) >>> stock_supplier.reload() >>> (stock_supplier.debit, stock_supplier.credit) == \ ... (Decimal(0), Decimal(68)) @@ -363,8 +363,8 @@ Create Move from Supplier to Customer:: >>> move.unit_price = Decimal(5) >>> move.cost_price = move.unit_price >>> move.currency = currency - >>> move.state = 'done' >>> move.save() + >>> Move.do([move.id], config.context) >>> stock_supplier.reload() >>> (stock_supplier.debit, stock_supplier.credit) == \ ... (Decimal(0), Decimal(88))