~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to purchase_msf/purchase_msf.py

[IMP] UF-33-48-103: Added dependencies and removed some blank lines in code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 TeMPO Consulting, MSF
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
 
20
##############################################################################
 
21
 
 
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
 
28
import netsvc
 
29
import pooler
 
30
import time
 
31
 
 
32
 
 
33
#
 
34
# Model definition
 
35
#
 
36
 
 
37
class purchase_order_line(osv.osv):
 
38
 
 
39
    _inherit = 'purchase.order.line'
 
40
    #_name = 'purchase.order.line'
 
41
    _description = 'Purchase Order Line modified for MSF'
 
42
    
 
43
    def _getProductInfo(self, cr, uid, ids, field_name, arg, context):
 
44
        
 
45
        # ACCESS to product_id ??
 
46
        
 
47
        # the name of the field is used to select the data to display
 
48
        result = {}
 
49
        for i in ids:
 
50
            result[i] = i
 
51
            
 
52
        return result
 
53
 
 
54
    _columns = {
 
55
        #function test column
 
56
        #'temp': fields.function(_getProductInfo,
 
57
        #                        type='char',
 
58
        #                        obj=None,
 
59
        #                        method=True,
 
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),
 
69
    }
 
70
    
 
71
    _defaults = {
 
72
    }
 
73
    
 
74
    
 
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):
 
78
        
 
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,
 
84
                                                                      notes=False)
 
85
        
 
86
        # when we erase the field, it is empty, so no product information but modified
 
87
        if not product:
 
88
            return result
 
89
        
 
90
        # 2. complete the new fields
 
91
        # - internal code
 
92
        # - internal name
 
93
        # - supplier code
 
94
        # - supplier name
 
95
        
 
96
        #@@@override@purchase>purchase.py>purchase_order_line.product_id_change : copied from original method, is everything needed ?
 
97
        if partner_id:
 
98
            lang=self.pool.get('res.partner').read(cr, uid, partner_id, ['lang'])['lang']
 
99
        context={'lang':lang}
 
100
        context['partner_id'] = partner_id
 
101
        
 
102
        prod = self.pool.get('product.product').browse(cr, uid, product, context=context)
 
103
        #@@@end
 
104
        
 
105
        # new fields
 
106
        internal_code = prod.default_code
 
107
        internal_name = prod.name
 
108
        supplier_code = '' 
 
109
        supplier_name = ''
 
110
        
 
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
 
114
        if prod.seller_ids:
 
115
            sellers = filter(lambda x: x.name.id == partner_id, prod.seller_ids)
 
116
            if sellers:
 
117
                seller = sellers[0]
 
118
                supplier_code = seller.product_code
 
119
                supplier_name = seller.product_name
 
120
            
 
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}
 
129
        
 
130
        innerDic.update(updateDic)
 
131
        
 
132
        # return the dictionary to update the view
 
133
        return result
 
134
        
 
135
 
 
136
purchase_order_line()
 
137
 
 
138
 
 
139
class product_product(osv.osv):
 
140
 
 
141
    _inherit = 'product.product'
 
142
    _description = 'Product'
 
143
    
 
144
    def name_get(self, cr, user, ids, context=None):
 
145
        if context is None:
 
146
            context = {}
 
147
        if not len(ids):
 
148
            return []
 
149
        def _name_get(d):
 
150
            name = d.get('name','')
 
151
            code = d.get('default_code',False)
 
152
            if code:
 
153
                name = '[%s] %s' % (code,name)
 
154
            if d.get('variants'):
 
155
                name = name + ' - %s' % (d['variants'],)
 
156
            return (d['id'], name)
 
157
 
 
158
        partner_id = context.get('partner_id', False)
 
159
 
 
160
        result = []
 
161
        for product in self.browse(cr, user, ids, context=context):
 
162
            mydict = {
 
163
                      'id': product.id,
 
164
                      'name': product.name,
 
165
                      'default_code': product.default_code,
 
166
                      'variants': product.variants
 
167
                      }
 
168
            result.append(_name_get(mydict))
 
169
        return result
 
170
    
 
171
product_product()
 
172
    
 
173
    
 
174