[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
This commit is contained in:
parent
a4890f1fe2
commit
7ed26f1e07
|
@ -146,7 +146,7 @@ class procurement_order(osv.osv):
|
||||||
procurements = self.read(cr, uid, ids, ['state'], context=context)
|
procurements = self.read(cr, uid, ids, ['state'], context=context)
|
||||||
unlink_ids = []
|
unlink_ids = []
|
||||||
for s in procurements:
|
for s in procurements:
|
||||||
if s['state'] in ['draft', 'cancel']:
|
if s['state'] == 'cancel':
|
||||||
unlink_ids.append(s['id'])
|
unlink_ids.append(s['id'])
|
||||||
else:
|
else:
|
||||||
raise osv.except_osv(_('Invalid Action!'),
|
raise osv.except_osv(_('Invalid Action!'),
|
||||||
|
|
|
@ -26,8 +26,9 @@ from _common import ceiling
|
||||||
|
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
from openerp import tools
|
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.translate import _
|
||||||
|
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
|
|
||||||
import openerp.addons.decimal_precision as dp
|
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.
|
Keep track of the ``product.template`` standard prices as they are changed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_name = 'prices.history'
|
_name = 'product.price.history'
|
||||||
_rec_name = 'datetime'
|
_rec_name = 'datetime'
|
||||||
_order = 'datetime desc'
|
_order = 'datetime desc'
|
||||||
|
|
||||||
|
@ -490,7 +491,7 @@ class product_template(osv.osv):
|
||||||
def create(self, cr, uid, vals, context=None):
|
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'''
|
''' 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)
|
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, {
|
price_history_obj.create(cr, uid, {
|
||||||
'product_template_id': product_template_id,
|
'product_template_id': product_template_id,
|
||||||
'cost': vals.get('standard_price', 0.0),
|
'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:
|
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,))
|
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:
|
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:
|
for prod_template_id in ids:
|
||||||
price_history_obj.create(cr, uid, {
|
price_history_obj.create(cr, uid, {
|
||||||
'product_template_id': prod_template_id,
|
'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 _('Products: ') + self.pool.get('product.category').browse(cr, uid, context['categ_id'], context=context).name
|
||||||
return res
|
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:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
if date is None:
|
||||||
|
date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
product = self.browse(cr, uid, product_id, context=context)
|
product = self.browse(cr, uid, product_id, context=context)
|
||||||
date = context.get('history_date', time.strftime('%Y-%m-%d %H:%M:%S'))
|
price_history_obj = self.pool.get('product.price.history')
|
||||||
prices_history_obj = self.pool.get('prices.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)
|
||||||
history_ids = prices_history_obj.search(cr, uid, [('company_id', '=', company_id), ('product_template_id', '=', product.product_tmpl_id.id), ('datetime', '<=', date)], limit=1)
|
|
||||||
if history_ids:
|
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)))
|
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):
|
def _product_price(self, cr, uid, ids, name, arg, context=None):
|
||||||
|
|
|
@ -15,7 +15,7 @@ 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_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_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_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_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_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_sale_manager,product.category salemanager,product.model_product_category,base.group_sale_manager,1,1,1,1
|
||||||
|
|
|
|
@ -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_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,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_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_product_price_history_purchase_user,prices.history purchase user,product.model_product_price_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
|
access_product_price_history_purchase_manager,prices.history purchase manager,product.model_product_price_history,purchase.group_purchase_manager,1,1,1,1
|
||||||
|
|
|
|
@ -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_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_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_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_product_price_history_salemanager,prices.history sale manager,product.model_product_price_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_product_price_history_account_user,prices.history account user,product.model_product_price_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
|
access_product_price_history_sale_use,prices.history sale use,product.model_product_price_history,base.group_sale_salesman,1,0,0,0
|
||||||
|
|
|
|
@ -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_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_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_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_product_price_history_stock_user,prices.history stock user,product.model_product_price_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_manager,prices.history stock manager,product.model_product_price_history,stock.group_stock_manager,1,1,1,1
|
||||||
|
|
|
|
@ -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):
|
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)
|
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 = {}
|
prod_dict = {}
|
||||||
if 'inventory_value' in fields:
|
if 'inventory_value' in fields:
|
||||||
for line in res:
|
for line in res:
|
||||||
|
@ -56,20 +59,22 @@ class stock_history(osv.osv):
|
||||||
if line_rec.product_id.cost_method == 'real':
|
if line_rec.product_id.cost_method == 'real':
|
||||||
prod_dict[line_rec.product_id.id] = line_rec.price_unit_on_quant
|
prod_dict[line_rec.product_id.id] = line_rec.price_unit_on_quant
|
||||||
else:
|
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
|
inv_value += prod_dict[line_rec.product_id.id] * line_rec.quantity
|
||||||
line['inventory_value'] = inv_value
|
line['inventory_value'] = inv_value
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_inventory_value(self, cr, uid, ids, name, attr, context=None):
|
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")
|
product_obj = self.pool.get("product.product")
|
||||||
res = {}
|
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):
|
for line in self.browse(cr, uid, ids, context=context):
|
||||||
if line.product_id.cost_method == 'real':
|
if line.product_id.cost_method == 'real':
|
||||||
res[line.id] = line.quantity * line.price_unit_on_quant
|
res[line.id] = line.quantity * line.price_unit_on_quant
|
||||||
else:
|
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
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
Loading…
Reference in New Issue