From 7ed26f1e07768c808800038f7c4fd04c36b8110b Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 28 Apr 2014 17:33:55 +0200 Subject: [PATCH] [REF] product refactoring: prices.history model renamed into product.price.history + passed 'date' as real parameter instead of contextual one in get_history_price() because it makes more sense. bzr revid: qdp-launchpad@openerp.com-20140428153355-vbuam1hfnah7m4wp --- addons/procurement/procurement.py | 2 +- addons/product/product.py | 22 ++++++++++--------- addons/product/security/ir.model.access.csv | 4 ++-- addons/purchase/security/ir.model.access.csv | 4 ++-- addons/sale/security/ir.model.access.csv | 6 ++--- addons/stock/security/ir.model.access.csv | 4 ++-- .../wizard/stock_valuation_history.py | 11 +++++++--- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index f94f45b7f70..d52e4d9db8c 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -146,7 +146,7 @@ class procurement_order(osv.osv): procurements = self.read(cr, uid, ids, ['state'], context=context) unlink_ids = [] for s in procurements: - if s['state'] in ['draft', 'cancel']: + if s['state'] == 'cancel': unlink_ids.append(s['id']) else: raise osv.except_osv(_('Invalid Action!'), diff --git a/addons/product/product.py b/addons/product/product.py index 92bd1807c1b..5a9861daf3d 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -26,8 +26,9 @@ from _common import ceiling from openerp import SUPERUSER_ID from openerp import tools -from openerp.osv import osv, orm, fields +from openerp.osv import osv, fields from openerp.tools.translate import _ +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT import openerp.addons.decimal_precision as dp @@ -289,12 +290,12 @@ class product_category(osv.osv): ] -class prices_history(osv.osv): +class produce_price_history(osv.osv): """ Keep track of the ``product.template`` standard prices as they are changed. """ - _name = 'prices.history' + _name = 'product.price.history' _rec_name = 'datetime' _order = 'datetime desc' @@ -490,7 +491,7 @@ class product_template(osv.osv): def create(self, cr, uid, vals, context=None): ''' Store the initial standard price in order to be able to retrieve the cost of a product template for a given date''' product_template_id = super(product_template, self).create(cr, uid, vals, context=context) - price_history_obj = self.pool['prices.history'] + price_history_obj = self.pool['product.price.history'] price_history_obj.create(cr, uid, { 'product_template_id': product_template_id, 'cost': vals.get('standard_price', 0.0), @@ -507,7 +508,7 @@ class product_template(osv.osv): if old_uom.category_id.id != new_uom.category_id.id: raise osv.except_osv(_('Unit of Measure categories Mismatch!'), _("New Unit of Measure '%s' must belong to same Unit of Measure category '%s' as of old Unit of Measure '%s'. If you need to change the unit of measure, you may deactivate this product from the 'Procurements' tab and create a new one.") % (new_uom.name, old_uom.category_id.name, old_uom.name,)) if 'standard_price' in vals: - price_history_obj = self.pool['prices.history'] + price_history_obj = self.pool['product.price.history'] for prod_template_id in ids: price_history_obj.create(cr, uid, { 'product_template_id': prod_template_id, @@ -577,15 +578,16 @@ class product_product(osv.osv): return _('Products: ') + self.pool.get('product.category').browse(cr, uid, context['categ_id'], context=context).name return res - def get_history_price(self, cr, uid, product_id, company_id, context=None): + def get_history_price(self, cr, uid, product_id, company_id, date=None, context=None): if context is None: context = {} + if date is None: + date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) product = self.browse(cr, uid, product_id, context=context) - date = context.get('history_date', time.strftime('%Y-%m-%d %H:%M:%S')) - prices_history_obj = self.pool.get('prices.history') - history_ids = prices_history_obj.search(cr, uid, [('company_id', '=', company_id), ('product_template_id', '=', product.product_tmpl_id.id), ('datetime', '<=', date)], limit=1) + price_history_obj = self.pool.get('product.price.history') + history_ids = price_history_obj.search(cr, uid, [('company_id', '=', company_id), ('product_template_id', '=', product.product_tmpl_id.id), ('datetime', '<=', date)], limit=1) if history_ids: - return prices_history_obj.read(cr, uid, history_ids[0], ['cost'], context=context)['cost'] + return price_history_obj.read(cr, uid, history_ids[0], ['cost'], context=context)['cost'] raise osv.except_osv(_('Error!'), _("No standard price associated for product %s for the given date" % (product.name))) def _product_price(self, cr, uid, ids, name, arg, context=None): diff --git a/addons/product/security/ir.model.access.csv b/addons/product/security/ir.model.access.csv index 7d3a29a8216..7919e3a6baa 100644 --- a/addons/product/security/ir.model.access.csv +++ b/addons/product/security/ir.model.access.csv @@ -15,9 +15,9 @@ access_product_pricelist_item_user,product.pricelist.item.user,model_product_pri access_product_pricelist_type_partner_manager,product.pricelist.type partner manager,model_product_pricelist_type,base.group_partner_manager,1,0,0,0 access_product_pricelist_partner_manager,product.pricelist partner manager,model_product_pricelist,base.group_partner_manager,1,0,0,0 access_product_product_employee,product.product employee,model_product_product,base.group_user,1,0,0,0 -access_prices_history_employee,prices.history employee,model_prices_history,base.group_user,1,0,0,0 +access_product_price_history_employee,prices.history employee,model_product_price_history,base.group_user,1,0,0,0 access_product_template_sale_manager,product.template salemanager,model_product_template,base.group_sale_manager,1,1,1,1 access_product_product_sale_manager,product.product salemanager,model_product_product,base.group_sale_manager,1,1,1,1 access_product_category_sale_manager,product.category salemanager,product.model_product_category,base.group_sale_manager,1,1,1,1 access_product_category_pos_manager,product.public.category manager,model_product_public_category,base.group_sale_manager,1,1,1,1 -access_product_category_pos_user,product.public.category user,model_product_public_category,base.group_user,1,0,0,0 \ No newline at end of file +access_product_category_pos_user,product.public.category user,model_product_public_category,base.group_user,1,0,0,0 diff --git a/addons/purchase/security/ir.model.access.csv b/addons/purchase/security/ir.model.access.csv index 9463abd99f0..2b8f68c64e0 100644 --- a/addons/purchase/security/ir.model.access.csv +++ b/addons/purchase/security/ir.model.access.csv @@ -60,5 +60,5 @@ access_account_journal_purchase_manager,account.journal purchase manager,account access_stock_location_purchase_manager,stock.location purchase manager,stock.model_stock_location,purchase.group_purchase_manager,1,0,0,0 access_stock_warehouse_orderpoint_manager,stock.warehouse.orderpoint,stock.model_stock_warehouse_orderpoint,purchase.group_purchase_manager,1,0,0,0 access_stock_warehouse_orderpoint_manager,stock.warehouse.orderpoint,stock.model_stock_warehouse_orderpoint,group_purchase_user,1,0,0,0 -access_prices_history_purchase_user,prices.history purchase user,product.model_prices_history,purchase.group_purchase_user,1,0,0,0 -access_prices_history_purchase_manager,prices.history purchase manager,product.model_prices_history,purchase.group_purchase_manager,1,1,1,1 \ No newline at end of file +access_product_price_history_purchase_user,prices.history purchase user,product.model_product_price_history,purchase.group_purchase_user,1,0,0,0 +access_product_price_history_purchase_manager,prices.history purchase manager,product.model_product_price_history,purchase.group_purchase_manager,1,1,1,1 diff --git a/addons/sale/security/ir.model.access.csv b/addons/sale/security/ir.model.access.csv index f140c886600..74a06d201f3 100644 --- a/addons/sale/security/ir.model.access.csv +++ b/addons/sale/security/ir.model.access.csv @@ -41,6 +41,6 @@ access_product_group_res_partner_sale_manager,res_partner group_sale_manager,bas access_product_pricelist_version_sale_manager,product.pricelist.version sale_manager,product.model_product_pricelist_version,base.group_sale_manager,1,1,1,1 access_account_invoice_report_salesman,account.invoice.report salesman,account.model_account_invoice_report,base.group_sale_salesman,1,0,0,0 access_account_move_line_salesman,account.move.line invoice,account.model_account_move_line,base.group_sale_salesman,1,0,0,0 -access_prices_history_salemanager,prices.history sale manager,product.model_prices_history,base.group_sale_manager,1,1,1,1 -access_prices_history_account_user,prices.history account user,product.model_prices_history,account.group_account_user,1,0,0,0 -access_prices_history_sale_use,prices.history sale use,product.model_prices_history,base.group_sale_salesman,1,0,0,0 \ No newline at end of file +access_product_price_history_salemanager,prices.history sale manager,product.model_product_price_history,base.group_sale_manager,1,1,1,1 +access_product_price_history_account_user,prices.history account user,product.model_product_price_history,account.group_account_user,1,0,0,0 +access_product_price_history_sale_use,prices.history sale use,product.model_product_price_history,base.group_sale_salesman,1,0,0,0 diff --git a/addons/stock/security/ir.model.access.csv b/addons/stock/security/ir.model.access.csv index b7d63ee5050..ae640ec683a 100644 --- a/addons/stock/security/ir.model.access.csv +++ b/addons/stock/security/ir.model.access.csv @@ -72,5 +72,5 @@ access_stock_fixed_putaway_strat,stock_fixed_putaway_strat managers,model_stock_ access_stock_move_operation_link_manager,stock.move.operation.link manager,model_stock_move_operation_link,stock.group_stock_manager,1,1,1,1 access_stock_move_operation_link_user,stock.move.operation.link user,model_stock_move_operation_link,stock.group_stock_user,1,1,1,1 access_stock_move_operation_link_all,stock.move.operation.link all users,model_stock_move_operation_link,base.group_user,1,0,0,0 -access_prices_history_stock_user,prices.history stock user,product.model_prices_history,stock.group_stock_user,1,0,1,0 -access_prices_history_stock_manager,prices.history stock manager,product.model_prices_history,stock.group_stock_manager,1,1,1,1 +access_product_price_history_stock_user,prices.history stock user,product.model_product_price_history,stock.group_stock_user,1,0,1,0 +access_product_price_history_stock_manager,prices.history stock manager,product.model_product_price_history,stock.group_stock_manager,1,1,1,1 diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index 24a1e38467f..f1b0848289b 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -43,6 +43,9 @@ class stock_history(osv.osv): def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True): res = super(stock_history, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy) + if context is None: + context = {} + date = context.get('history_date') prod_dict = {} if 'inventory_value' in fields: for line in res: @@ -56,20 +59,22 @@ class stock_history(osv.osv): if line_rec.product_id.cost_method == 'real': prod_dict[line_rec.product_id.id] = line_rec.price_unit_on_quant else: - prod_dict[line_rec.product_id.id] = product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, context=context) + prod_dict[line_rec.product_id.id] = product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, date=date, context=context) inv_value += prod_dict[line_rec.product_id.id] * line_rec.quantity line['inventory_value'] = inv_value return res def _get_inventory_value(self, cr, uid, ids, name, attr, context=None): + if context is None: + context = {} + date = context.get('history_date') product_obj = self.pool.get("product.product") res = {} - # Browse takes an immense amount of time because it seems to reload the report for line in self.browse(cr, uid, ids, context=context): if line.product_id.cost_method == 'real': res[line.id] = line.quantity * line.price_unit_on_quant else: - res[line.id] = line.quantity * product_obj.get_history_price(cr, uid, line.product_id.id, line.company_id.id, context=context) + res[line.id] = line.quantity * product_obj.get_history_price(cr, uid, line.product_id.id, line.company_id.id, date=date, context=context) return res _columns = {