[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:
@@ -103,7 +103,7 @@ class product_template(osv.osv):
|
||||
accounts.update({'stock_journal': self.categ_id.property_stock_journal or False})
|
||||
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."""
|
||||
location_obj = self.pool.get('stock.location')
|
||||
move_obj = self.pool.get('account.move')
|
||||
@@ -127,22 +127,24 @@ class product_template(osv.osv):
|
||||
# Accounting Entries
|
||||
amount_diff = abs(diff * qty)
|
||||
if diff * qty > 0:
|
||||
debit_account_id = datas['expense'].id
|
||||
debit_account_id = account_id
|
||||
credit_account_id = datas['stock_valuation'].id
|
||||
else:
|
||||
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'),
|
||||
'account_id': debit_account_id,
|
||||
'debit': amount_diff,
|
||||
'credit': 0,
|
||||
'product_id': product.id,
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': _('Standard Price changed'),
|
||||
'account_id': credit_account_id,
|
||||
'debit': 0,
|
||||
'credit': amount_diff,
|
||||
'product_id': product.id,
|
||||
})]
|
||||
move_vals = {
|
||||
'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 "
|
||||
"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."),
|
||||
'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):
|
||||
""" To get default values for the object.
|
||||
@param self: The object pointer.
|
||||
@@ -40,6 +40,10 @@ class change_standard_price(osv.osv_memory):
|
||||
|
||||
if 'new_price' in fields:
|
||||
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
|
||||
|
||||
def change_price(self, cr, uid, ids, context=None):
|
||||
@@ -60,8 +64,8 @@ class change_standard_price(osv.osv_memory):
|
||||
prod_obj = self.pool.get('product.product')
|
||||
rec_id = prod_obj.browse(cr, uid, rec_id, context=context).product_tmpl_id.id
|
||||
prod_obj = self.pool.get('product.template')
|
||||
|
||||
res = self.browse(cr, uid, ids, context=context)
|
||||
|
||||
prod_obj.do_change_standard_price(cr, uid, [rec_id], res[0].new_price, context)
|
||||
|
||||
res = self.browse(cr, uid, ids, context=context)[0]
|
||||
|
||||
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'}
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
<form string="Change Standard Price">
|
||||
<separator string="Change Price"/>
|
||||
<group>
|
||||
<field name="new_price" string="Cost"/>
|
||||
<group>
|
||||
<field name="new_price" string="Cost"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="counterpart_account_id"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="change_price" string="_Apply" type="object" class="btn-primary"/>
|
||||
|
||||
Reference in New Issue
Block a user