[FIX] stock_account: counterpart account of a cost price adjustment is more likely the expense account instead of the stock input/output. Backport of commit 57d0903154c562

This commit is contained in:
qdp-odoo 2015-12-02 16:20:32 +01:00
parent 4d8ec5f931
commit 077a168d4c
1 changed files with 10 additions and 5 deletions

View File

@ -128,16 +128,21 @@ class product_template(osv.osv):
'company_id': location.company_id.id,
}
move_id = move_obj.create(cr, uid, move_vals, context=context)
if diff*qty > 0:
counterpart_account = product.property_account_expense and product.property_account_expense.id or False
if not counterpart_account:
counterpart_account = product.categ_id.property_account_expense_categ and product.categ_id.property_account_expense_categ.id or False
if not counterpart_account:
raise osv.except_osv(_('Error!'), _('No expense account defined on the product %s or on its category') % (product.name))
if diff * qty > 0:
amount_diff = qty * diff
debit_account_id = datas['stock_account_input']
debit_account_id = counterpart_account
credit_account_id = datas['property_stock_valuation_account_id']
else:
amount_diff = qty * -diff
debit_account_id = datas['property_stock_valuation_account_id']
credit_account_id = datas['stock_account_output']
credit_account_id = counterpart_account
move_line_obj.create(cr, uid, {
'name': _('Standard Price changed'),
'account_id': debit_account_id,