[IMP]: product: Return name of product with supplier product code and name in name_get method in product module instead of purchase module

bzr revid: rpa@tinyerp.com-20101124092015-i2hse1bv9b0m9pfi
This commit is contained in:
rpa (Open ERP) 2010-11-24 14:50:15 +05:30
parent 432d5ceeae
commit 1ac2c0d91c
2 changed files with 23 additions and 12 deletions

View File

@ -489,7 +489,9 @@ class product_product(osv.osv):
def on_order(self, cr, uid, ids, orderline, quantity):
pass
def name_get(self, cr, user, ids, context={}):
def name_get(self, cr, user, ids, context=None):
if context is None:
context = {}
if not len(ids):
return []
def _name_get(d):
@ -497,10 +499,26 @@ class product_product(osv.osv):
code = d.get('default_code',False)
if code:
name = '[%s] %s' % (code,name)
if d['variants']:
if d.get('variants'):
name = name + ' - %s' % (d['variants'],)
return (d['id'], name)
result = map(_name_get, self.read(cr, user, ids, ['variants','name','default_code'], context))
partner_id = context.get('partner_id', False)
result = []
for product in self.browse(cr, user, ids, context=context):
sellers = filter(lambda x: x.name.id == partner_id, product.seller_ids)
if sellers:
for s in sellers:
mydict = {
'id': product.id,
'name': s.product_name or product.name,
'default_code': s.product_code or product.default_code,
'variants': product.variants
}
result.append(_name_get(mydict))
else:
result.append(_name_get(self.read(cr, user, product.id, ['variants','name','default_code'], context)))
return result
def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):

View File

@ -663,21 +663,14 @@ class purchase_order_line(osv.osv):
qty = qty or 1.0
seller_delay = 0
prod_name = self.pool.get('product.product').name_get(cr, uid, [prod.id])[0][1]
prod_name = self.pool.get('product.product').name_get(cr, uid, [prod.id], context=context)[0][1]
for s in prod.seller_ids:
if s.name.id == partner_id:
seller_delay = s.delay
temp_qty = s.qty # supplier _qty assigned to temp
if qty < temp_qty: # If the supplier quantity is greater than entered from user, set minimal.
qty = temp_qty
prod_suppl_name = s.product_name
prod_suppl_code = s.product_code
if not (prod_suppl_name or prod_suppl_code):
prod_name = self.pool.get('product.product').name_get(cr, uid, [prod.id])[0][1]
elif (not prod_suppl_name) or (not prod_suppl_code):
prod_name= '[' + (prod_suppl_code or prod.default_code or '') + '] '+ (prod_suppl_name or prod.name or '')
else:
prod_name= '[' + prod_suppl_code + '] '+ prod_suppl_name
if price_unit:
price = price_unit
else: