[IMP] stock_account: let the user choose the counterpart account used in price adjustment wizard for products in perpetual inventory. Fixes #9856

This commit is contained in:
qdp-odoo
2015-12-02 17:26:47 +01:00
parent b278b2c431
commit 40bd4a2f05
3 changed files with 20 additions and 9 deletions
+5 -3
View File
@@ -103,7 +103,7 @@ class product_template(osv.osv):
accounts.update({'stock_journal': self.categ_id.property_stock_journal or False}) accounts.update({'stock_journal': self.categ_id.property_stock_journal or False})
return accounts return accounts
def do_change_standard_price(self, cr, uid, ids, new_price, context=None): def do_change_standard_price(self, cr, uid, ids, new_price, account_id, context=None):
""" Changes the Standard Price of Product and creates an account move accordingly.""" """ Changes the Standard Price of Product and creates an account move accordingly."""
location_obj = self.pool.get('stock.location') location_obj = self.pool.get('stock.location')
move_obj = self.pool.get('account.move') move_obj = self.pool.get('account.move')
@@ -127,22 +127,24 @@ class product_template(osv.osv):
# Accounting Entries # Accounting Entries
amount_diff = abs(diff * qty) amount_diff = abs(diff * qty)
if diff * qty > 0: if diff * qty > 0:
debit_account_id = datas['expense'].id debit_account_id = account_id
credit_account_id = datas['stock_valuation'].id credit_account_id = datas['stock_valuation'].id
else: else:
debit_account_id = datas['stock_valuation'].id debit_account_id = datas['stock_valuation'].id
credit_account_id = datas['expense'].id credit_account_id = account_id
lines = [(0, 0, {'name': _('Standard Price changed'), lines = [(0, 0, {'name': _('Standard Price changed'),
'account_id': debit_account_id, 'account_id': debit_account_id,
'debit': amount_diff, 'debit': amount_diff,
'credit': 0, 'credit': 0,
'product_id': product.id,
}), }),
(0, 0, { (0, 0, {
'name': _('Standard Price changed'), 'name': _('Standard Price changed'),
'account_id': credit_account_id, 'account_id': credit_account_id,
'debit': 0, 'debit': 0,
'credit': amount_diff, 'credit': amount_diff,
'product_id': product.id,
})] })]
move_vals = { move_vals = {
'journal_id': datas['stock_journal'].id, 'journal_id': datas['stock_journal'].id,
@@ -13,10 +13,10 @@ class change_standard_price(osv.osv_memory):
help="If cost price is increased, stock variation account will be debited " help="If cost price is increased, stock variation account will be debited "
"and stock output account will be credited with the value = (difference of amount * quantity available).\n" "and stock output account will be credited with the value = (difference of amount * quantity available).\n"
"If cost price is decreased, stock variation account will be creadited and stock input account will be debited."), "If cost price is decreased, stock variation account will be creadited and stock input account will be debited."),
'counterpart_account_id': fields.many2one('account.account', string="Counter-Part Account", required=True, domain=[('deprecated', '=', False)]),
} }
def default_get(self, cr, uid, fields, context=None): def default_get(self, cr, uid, fields, context=None):
""" To get default values for the object. """ To get default values for the object.
@param self: The object pointer. @param self: The object pointer.
@@ -40,6 +40,10 @@ class change_standard_price(osv.osv_memory):
if 'new_price' in fields: if 'new_price' in fields:
res.update({'new_price': price}) res.update({'new_price': price})
if 'counterpart_account_id' in fields:
default_account = product_obj.property_account_expense_id or product_obj.categ_id.property_account_expense_categ_id
if default_account:
res.update({'counterpart_account_id': default_account.id})
return res return res
def change_price(self, cr, uid, ids, context=None): def change_price(self, cr, uid, ids, context=None):
@@ -61,7 +65,7 @@ class change_standard_price(osv.osv_memory):
rec_id = prod_obj.browse(cr, uid, rec_id, context=context).product_tmpl_id.id rec_id = prod_obj.browse(cr, uid, rec_id, context=context).product_tmpl_id.id
prod_obj = self.pool.get('product.template') prod_obj = self.pool.get('product.template')
res = self.browse(cr, uid, ids, context=context) res = self.browse(cr, uid, ids, context=context)[0]
prod_obj.do_change_standard_price(cr, uid, [rec_id], res[0].new_price, context) prod_obj.do_change_standard_price(cr, uid, [rec_id], res.new_price, res.counterpart_account_id.id, context)
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
@@ -8,7 +8,12 @@
<form string="Change Standard Price"> <form string="Change Standard Price">
<separator string="Change Price"/> <separator string="Change Price"/>
<group> <group>
<field name="new_price" string="Cost"/> <group>
<field name="new_price" string="Cost"/>
</group>
<group>
<field name="counterpart_account_id"/>
</group>
</group> </group>
<footer> <footer>
<button name="change_price" string="_Apply" type="object" class="btn-primary"/> <button name="change_price" string="_Apply" type="object" class="btn-primary"/>