From 935e61bab573847255fa8f682a7139e5367a1b40 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 8 Feb 2016 12:32:20 +0100 Subject: [PATCH] [FIX] stock_account: "Set standard price" button When a product with costing method = standard price and inventory valuation = perpetual (automated), the button "Set standard price" in General information in "product.template" is shown if the product template has only one variant. In the other case, the button is displayed in the variant view form. opw:668568 --- addons/stock_account/product.py | 50 +++++++++++++++++++ addons/stock_account/product_view.xml | 32 +++++++++++- .../wizard/stock_change_standard_price.py | 16 +++--- 3 files changed, 88 insertions(+), 10 deletions(-) diff --git a/addons/stock_account/product.py b/addons/stock_account/product.py index e187b0f8020..7ab0ec4ed9e 100644 --- a/addons/stock_account/product.py +++ b/addons/stock_account/product.py @@ -103,6 +103,7 @@ class product_template(osv.osv): accounts.update({'stock_journal': self.categ_id.property_stock_journal or False}) return accounts + # To remove in master because this function is now used on "product.product" model. def do_change_standard_price(self, cr, uid, ids, new_price, context=None): """ Changes the Standard Price of Product and creates an account move accordingly.""" location_obj = self.pool.get('stock.location') @@ -164,6 +165,55 @@ class product_product(osv.osv): self.valuation = 'manual_periodic' return {} + def do_change_standard_price(self, cr, uid, ids, new_price, 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') + if context is None: + context = {} + user_company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id + loc_ids = location_obj.search(cr, uid, [('usage', '=', 'internal'), ('company_id', '=', user_company_id)]) + for rec_id in ids: + for location in location_obj.browse(cr, uid, loc_ids, context=context): + c = context.copy() + c.update({'location': location.id, 'compute_child': False}) + product = self.browse(cr, uid, rec_id, context=c) + datas = self.pool['product.template'].get_product_accounts(cr, uid, product.product_tmpl_id.id, context=context) + diff = product.standard_price - new_price + if not diff: + raise UserError(_("No difference between standard price and new price!")) + qty = product.qty_available + if qty: + # Accounting Entries + amount_diff = abs(diff * qty) + if diff * qty > 0: + debit_account_id = datas['expense'].id + credit_account_id = datas['stock_valuation'].id + else: + debit_account_id = datas['stock_valuation'].id + credit_account_id = datas['expense'].id + + lines = [(0, 0, {'name': _('Standard Price changed'), + 'account_id': debit_account_id, + 'debit': amount_diff, + 'credit': 0, + }), + (0, 0, { + 'name': _('Standard Price changed'), + 'account_id': credit_account_id, + 'debit': 0, + 'credit': amount_diff, + })] + move_vals = { + 'journal_id': datas['stock_journal'].id, + 'company_id': location.company_id.id, + 'line_ids': lines, + } + move_id = move_obj.create(cr, uid, move_vals, context=context) + move_obj.post(cr, uid, [move_id], context=context) + self.write(cr, uid, rec_id, {'standard_price': new_price}) + return True + class product_category(osv.osv): _inherit = 'product.category' _columns = { diff --git a/addons/stock_account/product_view.xml b/addons/stock_account/product_view.xml index 98001316140..cfe702bc390 100644 --- a/addons/stock_account/product_view.xml +++ b/addons/stock_account/product_view.xml @@ -41,14 +41,14 @@
@@ -66,5 +66,33 @@ + + + product.product.product.view.form.easy.inherit + product.product + + + + + + + + +