summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorMartin Trigaux <mat@openerp.com>2013-12-05 17:38:02 +0100
committerMartin Trigaux <mat@openerp.com>2013-12-05 17:38:02 +0100
commit7db84881e7b8fd220669c3aec00ad72605bdbecf (patch)
tree03f1183fb508f7dafcbfbdf7eef741dcedd1afe2 /addons
parent7662250693d89661cb2395971f5154bb7da0e77c (diff)
parent81b3203dd7dd64dbab20a2f5f6c78a5efbb7a6cf (diff)
[MERGE] [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-20131205163802-chgmkik9qj0s5kw6
Diffstat (limited to 'addons')
-rw-r--r--addons/account_anglo_saxon/invoice.py21
-rw-r--r--addons/account_anglo_saxon/stock.py9
2 files changed, 22 insertions, 8 deletions
diff --git a/addons/account_anglo_saxon/invoice.py b/addons/account_anglo_saxon/invoice.py
index 8b31a48b92b..81394bc926e 100644
--- a/addons/account_anglo_saxon/invoice.py
+++ b/addons/account_anglo_saxon/invoice.py
@@ -21,21 +21,25 @@
#
##############################################################################
-from openerp.osv import osv
+from openerp.osv import osv, fields
class account_invoice_line(osv.osv):
_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):
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)
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')
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:
- price = i_line.product_id.standard_price * i_line.quantity
+ price = price_unit * i_line.quantity
return price
if inv.type in ('out_invoice','out_refund'):
@@ -60,12 +64,13 @@ class account_invoice_line(osv.osv):
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
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({
'type':'src',
'name': i_line.name[:64],
- 'price_unit':i_line.product_id.standard_price,
+ 'price_unit':price_unit,
'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,
'product_id':i_line.product_id.id,
'uos_id':i_line.uos_id.id,
@@ -76,9 +81,9 @@ class account_invoice_line(osv.osv):
res.append({
'type':'src',
'name': i_line.name[:64],
- 'price_unit':i_line.product_id.standard_price,
+ 'price_unit':price_unit,
'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,
'product_id':i_line.product_id.id,
'uos_id':i_line.uos_id.id,
diff --git a/addons/account_anglo_saxon/stock.py b/addons/account_anglo_saxon/stock.py
index 1cf3ecf21ef..278deb9a2a8 100644
--- a/addons/account_anglo_saxon/stock.py
+++ b/addons/account_anglo_saxon/stock.py
@@ -28,6 +28,15 @@ class stock_picking(osv.osv):
_inherit = "stock.picking"
_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,
group=False, type='out_invoice', context=None):
'''Return ids of created invoices for the pickings'''