1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from datetime import datetime
23
from dateutil.relativedelta import relativedelta
24
from osv import osv, fields
25
from osv.orm import browse_record, browse_null
26
from tools.translate import _
27
import decimal_precision as dp
37
class purchase_order_line(osv.osv):
39
_inherit = 'purchase.order.line'
40
#_name = 'purchase.order.line'
41
_description = 'Purchase Order Line modified for MSF'
43
def _getProductInfo(self, cr, uid, ids, field_name, arg, context):
45
# ACCESS to product_id ??
47
# the name of the field is used to select the data to display
56
#'temp': fields.function(_getProductInfo,
60
# string='Test function'),
61
#new column internal_code
62
'internal_code': fields.char('Internal code', size=256),
63
#new column internal_name
64
'internal_name': fields.char('Internal name', size=256),
65
#new column supplier_code
66
'supplier_code': fields.char('Supplier code', size=256),
67
#new column supplier_name
68
'supplier_name': fields.char('Supplier name', size=256),
75
def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
76
partner_id, date_order=False, fiscal_position=False, date_planned=False,
77
name=False, price_unit=False, notes=False):
79
# 1. call the original method
80
result = super(purchase_order_line, self).product_id_change(
81
cr, uid, ids, pricelist, product, qty, uom,
82
partner_id, date_order=False, fiscal_position=False,
83
date_planned=False, name=False, price_unit=False,
86
# when we erase the field, it is empty, so no product information but modified
90
# 2. complete the new fields
96
#@@@override@purchase>purchase.py>purchase_order_line.product_id_change : copied from original method, is everything needed ?
98
lang=self.pool.get('res.partner').read(cr, uid, partner_id, ['lang'])['lang']
100
context['partner_id'] = partner_id
102
prod = self.pool.get('product.product').browse(cr, uid, product, context=context)
106
internal_code = prod.default_code
107
internal_name = prod.name
111
# filter the seller list - only select the seller which corresponds
112
# to the supplier selected during PO creation
113
# if no supplier selected in product, there is no specific supplier info
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
# 3 .modify the description ('name' attribute)
122
# get the inner dictionary
123
innerDic = result['value']
124
updateDic = {'name': internal_name,
125
'internal_code': internal_code,
126
'internal_name': internal_name,
127
'supplier_code': supplier_code,
128
'supplier_name': supplier_name}
130
innerDic.update(updateDic)
132
# return the dictionary to update the view
136
purchase_order_line()
139
class product_product(osv.osv):
141
_inherit = 'product.product'
142
_description = 'Product'
144
def name_get(self, cr, user, ids, context=None):
150
name = d.get('name','')
151
code = d.get('default_code',False)
153
name = '[%s] %s' % (code,name)
154
if d.get('variants'):
155
name = name + ' - %s' % (d['variants'],)
156
return (d['id'], name)
158
partner_id = context.get('partner_id', False)
161
for product in self.browse(cr, user, ids, context=context):
164
'name': product.name,
165
'default_code': product.default_code,
166
'variants': product.variants
168
result.append(_name_get(mydict))