Use product.product instead of product.template when we go through the ORM.
In this process, I re-wrote the fonction change_product_qty_send_note in stock/wizard/stock_change_product_qty.py : the code is now much better ! bzr revid: alexis@via.ecp.fr-20120709162124-jmqv7hrl94fbzk1j
This commit is contained in:
parent
e9c288b4bf
commit
36cb6f479a
|
@ -155,7 +155,6 @@ class product_pricelist(osv.osv):
|
||||||
|
|
||||||
currency_obj = self.pool.get('res.currency')
|
currency_obj = self.pool.get('res.currency')
|
||||||
product_obj = self.pool.get('product.product')
|
product_obj = self.pool.get('product.product')
|
||||||
product_template_obj = self.pool.get('product.template')
|
|
||||||
product_category_obj = self.pool.get('product.category')
|
product_category_obj = self.pool.get('product.category')
|
||||||
product_uom_obj = self.pool.get('product.uom')
|
product_uom_obj = self.pool.get('product.uom')
|
||||||
supplierinfo_obj = self.pool.get('product.supplierinfo')
|
supplierinfo_obj = self.pool.get('product.supplierinfo')
|
||||||
|
@ -246,7 +245,7 @@ class product_pricelist(osv.osv):
|
||||||
price = 0.0
|
price = 0.0
|
||||||
if sinfo:
|
if sinfo:
|
||||||
qty_in_product_uom = qty
|
qty_in_product_uom = qty
|
||||||
product_default_uom = product_template_obj.read(cr, uid, [tmpl_id], ['uom_id'])[0]['uom_id'][0]
|
product_default_uom = product_obj.read(cr, uid, [product_id], ['uom_id'])[0]['uom_id'][0]
|
||||||
supplier = supplierinfo_obj.browse(cr, uid, sinfo, context=context)[0]
|
supplier = supplierinfo_obj.browse(cr, uid, sinfo, context=context)[0]
|
||||||
seller_uom = supplier.product_uom and supplier.product_uom.id or False
|
seller_uom = supplier.product_uom and supplier.product_uom.id or False
|
||||||
if seller_uom and product_default_uom and product_default_uom != seller_uom:
|
if seller_uom and product_default_uom and product_default_uom != seller_uom:
|
||||||
|
|
|
@ -47,7 +47,6 @@ class sale_order_line(osv.osv):
|
||||||
item_obj = self.pool.get('product.pricelist.item')
|
item_obj = self.pool.get('product.pricelist.item')
|
||||||
price_type_obj = self.pool.get('product.price.type')
|
price_type_obj = self.pool.get('product.price.type')
|
||||||
product_obj = self.pool.get('product.product')
|
product_obj = self.pool.get('product.product')
|
||||||
template_obj = self.pool.get('product.template')
|
|
||||||
field_name = 'list_price'
|
field_name = 'list_price'
|
||||||
|
|
||||||
if res_dict.get('item_id',False) and res_dict['item_id'].get(pricelist,False):
|
if res_dict.get('item_id',False) and res_dict['item_id'].get(pricelist,False):
|
||||||
|
@ -57,9 +56,7 @@ class sale_order_line(osv.osv):
|
||||||
field_name = price_type_obj.browse(cr, uid, item_base).field
|
field_name = price_type_obj.browse(cr, uid, item_base).field
|
||||||
|
|
||||||
product = product_obj.browse(cr, uid, product_id, context)
|
product = product_obj.browse(cr, uid, product_id, context)
|
||||||
product_tmpl_id = product.product_tmpl_id.id
|
product_read = product_obj.read(cr, uid, product_id, [field_name], context)
|
||||||
|
|
||||||
product_read = template_obj.read(cr, uid, product_tmpl_id, [field_name], context)
|
|
||||||
|
|
||||||
factor = 1.0
|
factor = 1.0
|
||||||
if uom and uom != product.uom_id.id:
|
if uom and uom != product.uom_id.id:
|
||||||
|
@ -110,7 +107,6 @@ class account_invoice_line(osv.osv):
|
||||||
item_obj = self.pool.get('product.pricelist.item')
|
item_obj = self.pool.get('product.pricelist.item')
|
||||||
price_type_obj = self.pool.get('product.price.type')
|
price_type_obj = self.pool.get('product.price.type')
|
||||||
product_obj = self.pool.get('product.product')
|
product_obj = self.pool.get('product.product')
|
||||||
template_obj = self.pool.get('product.template')
|
|
||||||
field_name = 'list_price'
|
field_name = 'list_price'
|
||||||
|
|
||||||
if res_dict.get('item_id',False) and res_dict['item_id'].get(pricelist,False):
|
if res_dict.get('item_id',False) and res_dict['item_id'].get(pricelist,False):
|
||||||
|
@ -120,9 +116,7 @@ class account_invoice_line(osv.osv):
|
||||||
field_name = price_type_obj.browse(cr, uid, item_base).field
|
field_name = price_type_obj.browse(cr, uid, item_base).field
|
||||||
|
|
||||||
product = product_obj.browse(cr, uid, product_id, context)
|
product = product_obj.browse(cr, uid, product_id, context)
|
||||||
product_tmpl_id = product.product_tmpl_id.id
|
product_read = product_obj.read(cr, uid, product_id, [field_name], context)
|
||||||
|
|
||||||
product_read = template_obj.read(cr, uid, product_tmpl_id, [field_name], context)
|
|
||||||
|
|
||||||
factor = 1.0
|
factor = 1.0
|
||||||
if uom and uom != product.uom_id.id:
|
if uom and uom != product.uom_id.id:
|
||||||
|
|
|
@ -103,20 +103,14 @@ class stock_change_product_qty(osv.osv_memory):
|
||||||
self.change_product_qty_send_note(cr, uid, [data.id], context)
|
self.change_product_qty_send_note(cr, uid, [data.id], context)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def change_product_qty_send_note (self, cr, uid, ids, context=None):
|
def change_product_qty_send_note(self, cr, uid, ids, context=None):
|
||||||
prod_obj = self.pool.get('product.product')
|
prod_obj = self.pool.get('product.product')
|
||||||
location_obj = self.pool.get('stock.location')
|
location_obj = self.pool.get('stock.location')
|
||||||
prod_temp_obj = self.pool.get('product.template')
|
|
||||||
uom_obj = self.pool.get('product.uom')
|
|
||||||
|
|
||||||
for data in self.browse(cr, uid, ids, context=context):
|
for data in self.browse(cr, uid, ids, context=context):
|
||||||
for location in location_obj.browse(cr, uid, [data.location_id.id], context=context):
|
location_name = location_obj.browse(cr, uid, data.location_id.id, context=context).name
|
||||||
location_name = location.name
|
message = _("<b>Quantity has been changed</b> to <em>%s %s </em> for <em>%s</em> location.") % (data.new_quantity, data.product_id.uom_id.name, location_name)
|
||||||
for prod in prod_obj.browse(cr, uid, [data.product_id.id], context=context):
|
prod_obj.message_append_note(cr, uid, [data.product_id.id], body=message, context=context)
|
||||||
for prod_temp in prod_temp_obj.browse(cr, uid, [prod.product_tmpl_id.id], context=context):
|
|
||||||
for uom in uom_obj.browse(cr, uid, [prod_temp.uom_id.id], context=context):
|
|
||||||
message = _("<b>Quantity has been changed</b> to <em>%s %s </em> for <em>%s</em> location.") % (data.new_quantity,uom.name,location_name)
|
|
||||||
prod_obj.message_append_note(cr, uid, [prod.id], body=message, context=context)
|
|
||||||
|
|
||||||
stock_change_product_qty()
|
stock_change_product_qty()
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ class stock_planning_createlines(osv.osv_memory):
|
||||||
planning_obj = self.pool.get('stock.planning')
|
planning_obj = self.pool.get('stock.planning')
|
||||||
mod_obj = self.pool.get('ir.model.data')
|
mod_obj = self.pool.get('ir.model.data')
|
||||||
prod_categ_obj = self.pool.get('product.category')
|
prod_categ_obj = self.pool.get('product.category')
|
||||||
template_obj = self.pool.get('product.template')
|
|
||||||
planning_lines = []
|
planning_lines = []
|
||||||
for f in self.browse(cr, uid, ids, context=context):
|
for f in self.browse(cr, uid, ids, context=context):
|
||||||
if f.forecasted_products:
|
if f.forecasted_products:
|
||||||
|
@ -67,8 +66,7 @@ class stock_planning_createlines(osv.osv_memory):
|
||||||
else:
|
else:
|
||||||
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
||||||
prod_categ_ids = prod_categ_obj.search(cr,uid,[('parent_id','child_of',categ_ids)])
|
prod_categ_ids = prod_categ_obj.search(cr,uid,[('parent_id','child_of',categ_ids)])
|
||||||
templates_ids = template_obj.search(cr,uid,[('categ_id','in',prod_categ_ids)])
|
products_id1 = product_obj.search(cr,uid,[('categ_id','in',prod_categ_ids)])
|
||||||
products_id1 = product_obj.search(cr,uid,[('product_tmpl_id','in',templates_ids)])
|
|
||||||
if len(products_id1)==0:
|
if len(products_id1)==0:
|
||||||
raise osv.except_osv(_('Error !'), _('No forecasts for selected period or no products in selected category !'))
|
raise osv.except_osv(_('Error !'), _('No forecasts for selected period or no products in selected category !'))
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,11 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||||
forecast_obj = self.pool.get('stock.sale.forecast')
|
forecast_obj = self.pool.get('stock.sale.forecast')
|
||||||
mod_obj = self.pool.get('ir.model.data')
|
mod_obj = self.pool.get('ir.model.data')
|
||||||
prod_categ_obj = self.pool.get('product.category')
|
prod_categ_obj = self.pool.get('product.category')
|
||||||
template_obj = self.pool.get('product.template')
|
|
||||||
forecast_lines = []
|
forecast_lines = []
|
||||||
for f in self.browse(cr, uid, ids, context=context):
|
for f in self.browse(cr, uid, ids, context=context):
|
||||||
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
||||||
prod_categ_ids = prod_categ_obj.search(cr, uid, [('parent_id','child_of', categ_ids)])
|
prod_categ_ids = prod_categ_obj.search(cr, uid, [('parent_id','child_of', categ_ids)])
|
||||||
templates_ids = template_obj.search(cr, uid, [('categ_id','in',prod_categ_ids)])
|
products_ids = product_obj.search(cr, uid, [('categ_id','in',prod_categ_ids)])
|
||||||
products_ids = product_obj.search(cr, uid, [('product_tmpl_id','in',templates_ids)])
|
|
||||||
if len(products_ids) == 0:
|
if len(products_ids) == 0:
|
||||||
raise osv.except_osv(_('Error !'), _('No products in selected category !'))
|
raise osv.except_osv(_('Error !'), _('No products in selected category !'))
|
||||||
copy = f.copy_forecast
|
copy = f.copy_forecast
|
||||||
|
|
Loading…
Reference in New Issue