33
37
class purchase_order_line(osv.osv):
35
information from product are repacked
37
39
_inherit = 'purchase.order.line'
39
def create(self, cr, uid, vals, context=None):
41
update the name attribute if a product is selected
43
prod_obj = self.pool.get('product.product')
44
if vals.get('product_id'):
45
vals.update(name=prod_obj.browse(cr, uid, vals.get('product_id'), context=context).name,)
46
elif vals.get('comment'):
47
vals.update(name=vals.get('comment'),)
49
return super(purchase_order_line, self).create(cr, uid, vals, context=context)
51
def write(self, cr, uid, ids, vals, context=None):
53
update the name attribute if a product is selected
55
prod_obj = self.pool.get('product.product')
56
if vals.get('product_id'):
57
vals.update(name=prod_obj.browse(cr, uid, vals.get('product_id'), context=context).name,)
58
elif vals.get('comment'):
59
vals.update(name=vals.get('comment'),)
61
return super(purchase_order_line, self).write(cr, uid, ids, vals, context=context)
40
#_name = 'purchase.order.line'
41
_description = 'Purchase Order Line modified for MSF'
63
43
def _get_manufacturers(self, cr, uid, ids, field_name, arg, context=None):
65
get manufacturers info
68
45
for record in self.browse(cr, uid, ids, context=context):
69
46
result[record.id] = {
72
49
'third_manufacturer_id': False,
74
51
po_supplier = record.order_id.partner_id
76
for seller_id in record.product_id.seller_ids:
77
if seller_id.name == po_supplier:
79
'manufacturer_id': seller_id.manufacturer_id.id,
80
'second_manufacturer_id': seller_id.second_manufacturer_id.id,
81
'third_manufacturer_id': seller_id.third_manufacturer_id.id,
52
for seller_id in record.product_id.seller_ids:
53
if seller_id.name == po_supplier:
55
'manufacturer_id': seller_id.manufacturer_id.id,
56
'second_manufacturer_id': seller_id.second_manufacturer_id.id,
57
'third_manufacturer_id': seller_id.third_manufacturer_id.id,
87
def _getProductInfo(self, cr, uid, ids, field_name, arg, context=None):
89
compute function fields related to product identity
91
prod_obj = self.pool.get('product.product')
63
def _getProductInfo(self, cr, uid, ids, field_name, arg, context):
65
# ACCESS to product_id ??
92
67
# the name of the field is used to select the data to display
97
result[i].update({f:False,})
99
for obj in self.browse(cr, uid, ids, context=context):
101
internal_code = False
102
internal_name = False
103
supplier_code = False
104
supplier_name = False
106
prod = obj.product_id
108
internal_code = prod.default_code
109
internal_name = prod.name
110
# filter the seller list - only select the seller which corresponds
111
# to the supplier selected during PO creation
112
# if no supplier selected in product, there is no specific supplier info
114
partner_id = obj.order_id.partner_id.id
115
sellers = filter(lambda x: x.name.id == partner_id, prod.seller_ids)
118
supplier_code = seller.product_code
119
supplier_name = seller.product_name
121
result[obj.id].update(internal_code=internal_code,
122
internal_name=internal_name,
123
supplier_code=supplier_code,
124
supplier_name=supplier_name,
129
_columns = {'internal_code': fields.function(_getProductInfo, method=True, type='char', size=1024, string='Internal code', multi='get_vals',),
130
'internal_name': fields.function(_getProductInfo, method=True, type='char', size=1024, string='Internal name', multi='get_vals',),
131
'supplier_code': fields.function(_getProductInfo, method=True, type='char', size=1024, string='Supplier code', multi='get_vals',),
132
'supplier_name': fields.function(_getProductInfo, method=True, type='char', size=1024, string='Supplier name', multi='get_vals',),
133
# new colums to display product manufacturers linked to the purchase order supplier
134
'manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Manufacturer", store=False, multi="all"),
135
'second_manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Second Manufacturer", store=False, multi="all"),
136
'third_manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Third Manufacturer", store=False, multi="all"),
76
#'temp': fields.function(_getProductInfo,
80
# string='Test function'),
81
#new column internal_code
82
'internal_code': fields.char('Internal code', size=256),
83
#new column internal_name
84
'internal_name': fields.char('Internal name', size=256),
85
#new column supplier_code
86
'supplier_code': fields.char('Supplier code', size=256),
87
#new column supplier_name
88
'supplier_name': fields.char('Supplier name', size=256),
89
# new colums to display product manufacturers linked to the purchase order supplier
90
'manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Manufacturer", store=False, multi="all"),
91
'second_manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Second Manufacturer", store=False, multi="all"),
92
'third_manufacturer_id': fields.function(_get_manufacturers, method=True, type='many2one', relation="res.partner", string="Third Manufacturer", store=False, multi="all"),
99
def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
100
partner_id, date_order=False, fiscal_position=False, date_planned=False,
101
name=False, price_unit=False, notes=False):
103
# 1. call the original method
104
result = super(purchase_order_line, self).product_id_change(
105
cr, uid, ids, pricelist, product, qty, uom,
106
partner_id, date_order=False, fiscal_position=False,
107
date_planned=False, name=False, price_unit=False,
110
# when we erase the field, it is empty, so no product information but modified
113
result['value'].update({'name': False,
114
'internal_code': False,
115
'internal_name': False,
116
'supplier_code': False,
117
'supplier_name': False})
120
# 2. complete the new fields
126
#@@@override@purchase>purchase.py>purchase_order_line.product_id_change : copied from original method, is everything needed ?
128
lang=self.pool.get('res.partner').read(cr, uid, partner_id, ['lang'])['lang']
129
context={'lang':lang}
130
context['partner_id'] = partner_id
132
prod = self.pool.get('product.product').browse(cr, uid, product, context=context)
136
internal_code = prod.default_code
137
internal_name = prod.name
138
supplier_code = False
139
supplier_name = False
141
# filter the seller list - only select the seller which corresponds
142
# to the supplier selected during PO creation
143
# if no supplier selected in product, there is no specific supplier info
145
sellers = filter(lambda x: x.name.id == partner_id, prod.seller_ids)
148
supplier_code = seller.product_code
149
supplier_name = seller.product_name
151
# 3 .modify the description ('name' attribute)
152
result['value'].update({'name': internal_name,
153
'internal_code': internal_code,
154
'internal_name': internal_name,
155
'supplier_code': supplier_code,
156
'supplier_name': supplier_name})
158
# return the dictionary to update the view
139
162
purchase_order_line()