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!'),
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
]
-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'
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),
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,
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):
access_product_pricelist_type_partner_manager,product.pricelist.type partner manager,model_product_pricelist_type,base.group_partner_manager,1,0,0,0\r
access_product_pricelist_partner_manager,product.pricelist partner manager,model_product_pricelist,base.group_partner_manager,1,0,0,0\r
access_product_product_employee,product.product employee,model_product_product,base.group_user,1,0,0,0\r
-access_prices_history_employee,prices.history employee,model_prices_history,base.group_user,1,0,0,0\r
+access_product_price_history_employee,prices.history employee,model_product_price_history,base.group_user,1,0,0,0\r
access_product_template_sale_manager,product.template salemanager,model_product_template,base.group_sale_manager,1,1,1,1\r
access_product_product_sale_manager,product.product salemanager,model_product_product,base.group_sale_manager,1,1,1,1\r
access_product_category_sale_manager,product.category salemanager,product.model_product_category,base.group_sale_manager,1,1,1,1\r
access_product_category_pos_manager,product.public.category manager,model_product_public_category,base.group_sale_manager,1,1,1,1\r
-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\r
access_stock_location_purchase_manager,stock.location purchase manager,stock.model_stock_location,purchase.group_purchase_manager,1,0,0,0\r
access_stock_warehouse_orderpoint_manager,stock.warehouse.orderpoint,stock.model_stock_warehouse_orderpoint,purchase.group_purchase_manager,1,0,0,0\r
access_stock_warehouse_orderpoint_manager,stock.warehouse.orderpoint,stock.model_stock_warehouse_orderpoint,group_purchase_user,1,0,0,0\r
-access_prices_history_purchase_user,prices.history purchase user,product.model_prices_history,purchase.group_purchase_user,1,0,0,0\r
-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\r
+access_product_price_history_purchase_manager,prices.history purchase manager,product.model_product_price_history,purchase.group_purchase_manager,1,1,1,1\r
access_product_pricelist_version_sale_manager,product.pricelist.version sale_manager,product.model_product_pricelist_version,base.group_sale_manager,1,1,1,1\r
access_account_invoice_report_salesman,account.invoice.report salesman,account.model_account_invoice_report,base.group_sale_salesman,1,0,0,0\r
access_account_move_line_salesman,account.move.line invoice,account.model_account_move_line,base.group_sale_salesman,1,0,0,0\r
-access_prices_history_salemanager,prices.history sale manager,product.model_prices_history,base.group_sale_manager,1,1,1,1\r
-access_prices_history_account_user,prices.history account user,product.model_prices_history,account.group_account_user,1,0,0,0\r
-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\r
+access_product_price_history_account_user,prices.history account user,product.model_product_price_history,account.group_account_user,1,0,0,0\r
+access_product_price_history_sale_use,prices.history sale use,product.model_product_price_history,base.group_sale_salesman,1,0,0,0\r
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
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:
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 = {