Reviewers: ,
Please review this at http://codereview.tryton.org/881002/ Affected files: M move.py
Index: move.py =================================================================== --- a/move.py +++ b/move.py @@ -76,6 +76,27 @@ else: return self.product.cost_price + def _compute_product_fifo_cost_price(self): + if (move.from_location.type in ('supplier', 'production') + and move.to_location.type == 'storage'): + move._update_product_cost_price('in') + elif (move.from_location.type == 'storage' + and move.to_location.type == 'supplier'): + move._update_product_cost_price('out') + elif (move.from_location.type == 'storage' + and move.to_location.type != 'storage'): + cost_price = move._update_fifo_out_product_cost_price() + if not move.cost_price: + move.cost_price = cost_price + + def _compute_cancelled_product_fifo_cost_price(self): + if (move.from_location.type in ('supplier', 'production') + and move.to_location.type == 'storage'): + move._update_product_cost_price('out') + elif (move.to_location.type == 'supplier' + and move.from_location.type == 'storage'): + move._update_product_cost_price('in') + @classmethod @ModelView.button @Workflow.transition('done') @@ -87,20 +108,8 @@ for move in moves: if not move.effective_date: move.effective_date = today - if (move.from_location.type in ('supplier', 'production') - and move.to_location.type == 'storage' - and move.product.cost_price_method == 'fifo'): - move._update_product_cost_price('in') - elif (move.to_location.type == 'supplier' - and move.from_location.type == 'storage' - and move.product.cost_price_method == 'fifo'): - move._update_product_cost_price('out') - elif (move.from_location.type == 'storage' - and move.to_location.type != 'storage' - and move.product.cost_price_method == 'fifo'): - cost_price = move._update_fifo_out_product_cost_price() - if not move.cost_price: - move.cost_price = cost_price + if move.product.cost_price_method == 'fifo': + move._compute_product_fifo_cost_price() move.save() super(Move, cls).do(moves) @@ -115,14 +124,8 @@ today = Date.today() for move in moves: move.effective_date = today - if (move.from_location.type in ('supplier', 'production') - and move.to_location.type == 'storage' - and move.product.cost_price_method == 'fifo'): - move._update_product_cost_price('out') - elif (move.to_location.type == 'supplier' - and move.from_location.type == 'storage' - and move.product.cost_price_method == 'fifo'): - move._update_product_cost_price('in') + if move.product.cost_price_method == 'fifo': + move._compute_cancelled_product_fifo_cost_price() move.effective_date = None move.save()