[FIX] account_anglo_saxon: at invoice validation, the price for the analytic lines should be computed using the price_unit of the related stock.move instead of the product standard price (useful if different valuation method, could have price difference between delivery and invoice time)

bzr revid: mat@openerp.com-20131205163406-3rvupbbj3sm9q550
This commit is contained in:
Martin Trigaux 2013-12-05 17:34:06 +01:00
parent 896fab1b44
commit 81b3203dd7
2 changed files with 22 additions and 8 deletions

View File

@ -21,21 +21,25 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv from openerp.osv import osv, fields
class account_invoice_line(osv.osv): class account_invoice_line(osv.osv):
_inherit = "account.invoice.line" _inherit = "account.invoice.line"
_columns = {
'move_id': fields.many2one('stock.move', string="Move line", help="If the invoice was generated from a stock.picking, reference to the related move line."),
}
def move_line_get(self, cr, uid, invoice_id, context=None): def move_line_get(self, cr, uid, invoice_id, context=None):
res = super(account_invoice_line,self).move_line_get(cr, uid, invoice_id, context=context) res = super(account_invoice_line,self).move_line_get(cr, uid, invoice_id, context=context)
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context) inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context)
company_currency = inv.company_id.currency_id.id company_currency = inv.company_id.currency_id.id
def get_price(cr, uid, inv, company_currency,i_line): def get_price(cr, uid, inv, company_currency, i_line, price_unit):
cur_obj = self.pool.get('res.currency') cur_obj = self.pool.get('res.currency')
if inv.currency_id.id != company_currency: if inv.currency_id.id != company_currency:
price = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, i_line.product_id.standard_price * i_line.quantity, context={'date': inv.date_invoice}) price = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, price_unit * i_line.quantity, context={'date': inv.date_invoice})
else: else:
price = i_line.product_id.standard_price * i_line.quantity price = price_unit * i_line.quantity
return price return price
if inv.type in ('out_invoice','out_refund'): if inv.type in ('out_invoice','out_refund'):
@ -60,12 +64,13 @@ class account_invoice_line(osv.osv):
if not cacc: if not cacc:
cacc = i_line.product_id.categ_id.property_account_expense_categ and i_line.product_id.categ_id.property_account_expense_categ.id cacc = i_line.product_id.categ_id.property_account_expense_categ and i_line.product_id.categ_id.property_account_expense_categ.id
if dacc and cacc: if dacc and cacc:
price_unit = i_line.move_id and i_line.move_id.price_unit or i_line.product_id.standard_price
res.append({ res.append({
'type':'src', 'type':'src',
'name': i_line.name[:64], 'name': i_line.name[:64],
'price_unit':i_line.product_id.standard_price, 'price_unit':price_unit,
'quantity':i_line.quantity, 'quantity':i_line.quantity,
'price':get_price(cr, uid, inv, company_currency, i_line), 'price':get_price(cr, uid, inv, company_currency, i_line, price_unit),
'account_id':dacc, 'account_id':dacc,
'product_id':i_line.product_id.id, 'product_id':i_line.product_id.id,
'uos_id':i_line.uos_id.id, 'uos_id':i_line.uos_id.id,
@ -76,9 +81,9 @@ class account_invoice_line(osv.osv):
res.append({ res.append({
'type':'src', 'type':'src',
'name': i_line.name[:64], 'name': i_line.name[:64],
'price_unit':i_line.product_id.standard_price, 'price_unit':price_unit,
'quantity':i_line.quantity, 'quantity':i_line.quantity,
'price': -1 * get_price(cr, uid, inv, company_currency, i_line), 'price': -1 * get_price(cr, uid, inv, company_currency, i_line, price_unit),
'account_id':cacc, 'account_id':cacc,
'product_id':i_line.product_id.id, 'product_id':i_line.product_id.id,
'uos_id':i_line.uos_id.id, 'uos_id':i_line.uos_id.id,

View File

@ -28,6 +28,15 @@ class stock_picking(osv.osv):
_inherit = "stock.picking" _inherit = "stock.picking"
_description = "Picking List" _description = "Picking List"
def _prepare_invoice_line(self, cr, uid, group, picking, move_line, invoice_id,
invoice_vals, context=None):
"""Overwrite to add move_id reference"""
res = super(stock_picking, self)._prepare_invoice_line(cr, uid, group, picking, move_line, invoice_id, invoice_vals, context=context)
res.update({
'move_id': move_line.id,
})
return res
def action_invoice_create(self, cr, uid, ids, journal_id=False, def action_invoice_create(self, cr, uid, ids, journal_id=False,
group=False, type='out_invoice', context=None): group=False, type='out_invoice', context=None):
'''Return ids of created invoices for the pickings''' '''Return ids of created invoices for the pickings'''