[FIX] stock_account: VAT for extra moves

If an extra move contains a product which is not initially in the order,
the taxes set on this product must be considered according to the fiscal position
of this order.

opw:634305
This commit is contained in:
Goffin Simon 2015-05-21 14:22:26 +02:00
parent e5a8d21a60
commit 75b9932451
3 changed files with 33 additions and 16 deletions

View File

@ -119,12 +119,20 @@ 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])]
def _get_moves_taxes(self, cr, uid, moves, inv_type, context=None):
is_extra_move, extra_move_tax = super(stock_move, self)._get_moves_taxes(cr, uid, moves, inv_type, context=context)
if inv_type == 'in_invoice':
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])]
elif move.product_id.product_tmpl_id.supplier_taxes_id:
mov_id = self.search(cr, uid, [('purchase_line_id', '!=', False), ('picking_id', '=', move.picking_id.id)], limit=1, context=context)
if mov_id:
mov = self.browse(cr, uid, mov_id[0], context=context)
fp = mov.purchase_line_id.order_id.fiscal_position
res = self.pool.get("account.invoice.line").product_id_change(cr, uid, [], move.product_id.id, None, partner_id=move.picking_id.partner_id.id, fposition_id=(fp and fp.id), type='in_invoice', context=context)
extra_move_tax[0, move.product_id] = [(6, 0, res['value']['invoice_line_tax_id'])]
return (is_extra_move, extra_move_tax)

View File

@ -413,12 +413,17 @@ 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])]
def _get_moves_taxes(self, cr, uid, moves, inv_type, context=None):
is_extra_move, extra_move_tax = super(stock_move, self)._get_moves_taxes(cr, uid, moves, inv_type, context=context)
if inv_type == 'out_invoice':
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])]
elif move.picking_id.sale_id and move.product_id.product_tmpl_id.taxes_id:
fp = move.picking_id.sale_id.fiscal_position
res = self.pool.get("account.invoice.line").product_id_change(cr, uid, [], move.product_id.id, None, partner_id=move.picking_id.partner_id.id, fposition_id=(fp and fp.id), context=context)
extra_move_tax[0, move.product_id] = [(6, 0, res['value']['invoice_line_tax_id'])]
return (is_extra_move, extra_move_tax)
def _get_taxes(self, cr, uid, move, context=None):

View File

@ -166,7 +166,7 @@ class stock_move(osv.osv):
'account_analytic_id': False,
}
def _get_moves_taxes(self, cr, uid, moves, context=None):
def _get_moves_taxes(self, cr, uid, moves, inv_type, 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 = {}
@ -295,7 +295,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)
is_extra_move, extra_move_tax = move_obj._get_moves_taxes(cr, uid, moves, inv_type, context=context)
product_price_unit = {}
for move in moves:
company = move.company_id
@ -322,8 +322,12 @@ class stock_picking(osv.osv):
product_price_unit[invoice_line_vals['product_id']] = invoice_line_vals['price_unit']
if is_extra_move[move.id] and invoice_line_vals['product_id'] in product_price_unit:
invoice_line_vals['price_unit'] = product_price_unit[invoice_line_vals['product_id']]
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]
if is_extra_move[move.id]:
if 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]
#the default product taxes
elif (0, move.product_id) in extra_move_tax:
invoice_line_vals['invoice_line_tax_id'] = extra_move_tax[0, 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)