From 79ac324ca11ae9cb9f9a92447280afe31cc72998 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Sun, 22 Mar 2015 17:37:07 +0100 Subject: [PATCH] [FIX] stock_account: Invoicing on incoming shipment When an extra line is added on an incoming shipment, the resulting invoice must consider the tax of the product. opw:630758, 630778 --- addons/purchase/stock.py | 8 ++++++++ addons/sale_stock/sale_stock.py | 8 ++++++++ addons/stock_account/stock.py | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 5f569e1964d..c6ced4e59fd 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -119,6 +119,14 @@ class stock_move(osv.osv): res['price_unit'] = purchase_line.price_unit return res + def _get_moves_taxes(self, cr, uid, moves, context=None): + is_extra_move, extra_move_tax = super(stock_move, self)._get_moves_taxes(cr, uid, moves, context=context) + for move in moves: + if move.purchase_line_id: + is_extra_move[move.id] = False + extra_move_tax[move.picking_id, move.product_id] = [(6, 0, [x.id for x in move.purchase_line_id.taxes_id])] + return (is_extra_move, extra_move_tax) + def attribute_price(self, cr, uid, move, context=None): """ diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 35a75674ed9..08e45776fb5 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -398,6 +398,14 @@ class stock_move(osv.osv): res['price_unit'] = res['price_unit'] / uos_coeff return res + def _get_moves_taxes(self, cr, uid, moves, context=None): + is_extra_move, extra_move_tax = super(stock_move, self)._get_moves_taxes(cr, uid, moves, context=context) + for move in moves: + if move.procurement_id and move.procurement_id.sale_line_id: + is_extra_move[move.id] = False + extra_move_tax[move.picking_id, move.product_id] = [(6, 0, [x.id for x in move.procurement_id.sale_line_id.tax_id])] + return (is_extra_move, extra_move_tax) + class stock_location_route(osv.osv): _inherit = "stock.location.route" diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 486c94d797f..b59d7144250 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -162,6 +162,19 @@ class stock_move(osv.osv): 'account_analytic_id': False, } + def _get_moves_taxes(self, cr, uid, moves, context=None): + #extra moves with the same picking_id and product_id of a move have the same taxes + extra_move_tax = {} + is_extra_move = {} + for move in moves: + if move.picking_id: + is_extra_move[move.id] = True + if not (move.picking_id, move.product_id) in extra_move_tax: + extra_move_tax[move.picking_id, move.product_id] = 0 + else: + is_extra_move[move.id] = False + return (is_extra_move, extra_move_tax) + #---------------------------------------------------------- # Picking #---------------------------------------------------------- @@ -278,6 +291,7 @@ class stock_picking(osv.osv): invoice_obj = self.pool.get('account.invoice') move_obj = self.pool.get('stock.move') invoices = {} + is_extra_move, extra_move_tax = move_obj._get_moves_taxes(cr, uid, moves, context=context) for move in moves: company = move.company_id origin = move.picking_id.name @@ -299,6 +313,8 @@ class stock_picking(osv.osv): invoice_line_vals = move_obj._get_invoice_line_vals(cr, uid, move, partner, inv_type, context=context) invoice_line_vals['invoice_id'] = invoices[key] invoice_line_vals['origin'] = origin + if is_extra_move[move.id] and extra_move_tax[move.picking_id, move.product_id]: + invoice_line_vals['invoice_line_tax_id'] = extra_move_tax[move.picking_id, move.product_id] move_obj._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context) move_obj.write(cr, uid, move.id, {'invoice_state': 'invoiced'}, context=context)