From 40bd4a2f051996d4ab5ca7956562c8f552c4c969 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Wed, 2 Dec 2015 17:26:47 +0100 Subject: [PATCH] [IMP] stock_account: let the user choose the counterpart account used in price adjustment wizard for products in perpetual inventory. Fixes #9856 --- addons/stock_account/product.py | 8 +++++--- .../wizard/stock_change_standard_price.py | 14 +++++++++----- .../wizard/stock_change_standard_price_view.xml | 7 ++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/addons/stock_account/product.py b/addons/stock_account/product.py index e187b0f8020..1f5433084df 100644 --- a/addons/stock_account/product.py +++ b/addons/stock_account/product.py @@ -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, diff --git a/addons/stock_account/wizard/stock_change_standard_price.py b/addons/stock_account/wizard/stock_change_standard_price.py index d75f760596d..778734395fb 100644 --- a/addons/stock_account/wizard/stock_change_standard_price.py +++ b/addons/stock_account/wizard/stock_change_standard_price.py @@ -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'} diff --git a/addons/stock_account/wizard/stock_change_standard_price_view.xml b/addons/stock_account/wizard/stock_change_standard_price_view.xml index e088c024f33..ef1dd334fa1 100644 --- a/addons/stock_account/wizard/stock_change_standard_price_view.xml +++ b/addons/stock_account/wizard/stock_change_standard_price_view.xml @@ -8,7 +8,12 @@
- + + + + + +