1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
# encoding: utf-8
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 MSF, TeMPO consulting
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
import re
from tools.translate import _
class product_section_code(osv.osv):
_name = "product.section.code"
_columns = {
'code': fields.char('Code', size=4),
'section': fields.char('Section', size=32),
'description': fields.char('Description', size=128),
}
product_section_code()
class product_supply_source(osv.osv):
_name = "product.supply.source"
_columns = {
'source': fields.char('Supply source', size=32),
}
product_supply_source()
class product_justification_code(osv.osv):
_name = "product.justification.code"
_columns = {
'code': fields.char('Justification Code', size=32),
'description': fields.char('Justification Description', size=256),
}
def name_get(self, cr, user, ids, context=None):
if not ids:
return []
reads = self.read(cr, user, ids, ['code'], context=context)
res = []
for record in reads:
code = record['code']
res.append((record['id'], code))
return res
product_justification_code()
class product_attributes_template(osv.osv):
_inherit = "product.template"
_columns = {
'type': fields.selection([('product','Stockable Product'),('consu', 'Non-Stockable')], 'Product Type', required=True, help="Will change the way procurements are processed. Consumables are stockable products with infinite stock, or for use when you have no inventory management in the system."),
}
_defaults = {
'type': 'product',
'cost_method': lambda *a: 'average',
}
product_attributes_template()
class product_country_restriction(osv.osv):
_name = 'res.country.restriction'
_columns = {
'name': fields.char(size=128, string='Restriction'),
'product_ids': fields.one2many('product.product', 'country_restriction', string='Products'),
}
product_country_restriction()
class product_attributes(osv.osv):
_inherit = "product.product"
def _get_nomen(self, cr, uid, ids, field_name, args, context=None):
res = {}
for product in self.browse(cr, uid, ids, context=context):
res[product.id] = []
res[product.id].append(product.nomen_manda_0.id)
res[product.id].append(product.nomen_manda_1.id)
res[product.id].append(product.nomen_manda_2.id)
res[product.id].append(product.nomen_manda_3.id)
res[product.id].append(product.nomen_sub_0.id)
res[product.id].append(product.nomen_sub_1.id)
res[product.id].append(product.nomen_sub_2.id)
res[product.id].append(product.nomen_sub_3.id)
res[product.id].append(product.nomen_sub_4.id)
res[product.id].append(product.nomen_sub_5.id)
return res
def _search_nomen(self, cr, uid, obj, name, args, context=None):
'''
Filter the search according to the args parameter
'''
if not context:
context = {}
ids = []
for arg in args:
if arg[0] == 'nomen_ids' and arg[1] == '=' and arg[2]:
nomen = self.pool.get('product.nomenclature').browse(cr, uid, arg[2], context=context)
if nomen.type == 'mandatory':
ids = self.search(cr, uid, [('nomen_manda_%s' % nomen.level, '=', nomen.id)], context=context)
else:
ids = self.search(cr, uid, [('nomen_sub_0', '=', nomen.id)], context=context)
ids.append(self.search(cr, uid, [('nomen_sub_1', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_2', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_3', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_4', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_5', '=', nomen.id)], context=context))
elif arg[0] == 'nomen_ids' and arg[1] == 'in' and arg[2]:
for nomen in self.pool.get('product.nomenclature').browse(cr, uid, arg[2], context=context):
if nomen.type == 'mandatory':
ids = self.search(cr, uid, [('nomen_manda_%s' % nomen.level, '=', nomen.id)], context=context)
else:
ids = self.search(cr, uid, [('nomen_sub_0', '=', nomen.id)], context=context)
ids.append(self.search(cr, uid, [('nomen_sub_1', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_2', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_3', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_4', '=', nomen.id)], context=context))
ids.append(self.search(cr, uid, [('nomen_sub_5', '=', nomen.id)], context=context))
else:
return []
return [('id', 'in', ids)]
_columns = {
'duplicate_ok': fields.boolean('Is a duplicate'),
'loc_indic': fields.char('Indicative Location', size=64),
'description2': fields.text('Description 2'),
'old_code' : fields.char('Old code', size=64),
'new_code' : fields.char('New code', size=64),
'international_status': fields.selection([('itc','ITC'),('esc', 'ESC'),('hq', 'HQ'),('local','Local'),('temp','Temporary')],
string='Product Creator', required=True),
'state': fields.selection([('',''),
('draft','Introduction'),
('sellable','Normal'),
('transfer','Transfer'),
('end_alternative','End of Life (alternative available)'),
('end','End of Life (not supplied anymore)'),
('obsolete','Warning list')], 'Status', help="Tells the user if he can use the product or not."),
'perishable': fields.boolean('Expiry Date Mandatory'),
'batch_management': fields.boolean('Batch Number Mandatory'),
'product_catalog_page' : fields.char('Product Catalog Page', size=64),
'product_catalog_path' : fields.char('Product Catalog Path', size=64),
'short_shelf_life': fields.boolean('Short Shelf Life'),
'criticism': fields.selection([('',''),
('exceptional','1-Exceptional'),
('specific','2-Specific'),
('important','3-Important'),
('medium','4-Medium'),
('common','5-Common'),
('other','X-Other')], 'Criticality'),
'narcotic': fields.boolean('Narcotic/Psychotropic'),
'abc_class': fields.selection([('',''),
('a','A'),
('b','B'),
('c','C')], 'ABC Class'),
'section_code_ids': fields.many2many('product.section.code','product_section_code_rel','product_id','section_code_id','Section Code'),
'library': fields.selection([('',''),
('l1','L1'),
('l2','L2'),
('l3','L3'),
('l4','L4')], 'Library'),
'supply_source_ids': fields.many2many('product.supply.source','product_supply_source_rel','product_id','supply_source_id','Supply Source'),
'sublist' : fields.char('Sublist', size=64),
'composed_kit': fields.boolean('Kit Composed of Kits/Modules'),
'options_ids': fields.many2many('product.product','product_options_rel','product_id','product_option_id','Options'),
'heat_sensitive_item': fields.selection([('',''),
('KR','Keep refrigerated but not cold chain (+2 to +8°C) for transport'),
('*','Keep Cool'),
('**','Keep Cool, airfreight'),
('***','Cold chain, 0° to 8°C strict')], string='Temperature sensitive item'),
'cold_chain': fields.selection([('',''),
('3*','3* Cold Chain * - Keep Cool: used for a kit containing cold chain module or item(s)'),
('6*0','6*0 Cold Chain *0 - Problem if any window blue'),
('7*0F','7*0F Cold Chain *0F - Problem if any window blue or Freeze-tag = ALARM'),
('8*A','8*A Cold Chain *A - Problem if B, C and/or D totally blue'),
('9*AF','9*AF Cold Chain *AF - Problem if B, C and/or D totally blue or Freeze-tag = ALARM'),
('10*B','10*B Cold Chain *B - Problem if C and/or D totally blue'),
('11*BF','11*BF Cold Chain *BF - Problem if C and/or D totally blue or Freeze-tag = ALARM'),
('12*C','12*C Cold Chain *C - Problem if D totally blue'),
('13*CF','13*CF Cold Chain *CF - Problem if D totally blue or Freeze-tag = ALARM'),
('14*D','14*D Cold Chain *D - Store and transport at -25°C (store in deepfreezer, transport with dry-ice)'),
('15*F','15*F Cold Chain *F - Cannot be frozen: check Freeze-tag '),
('16*25','16*25 Cold Chain *25 - Must be kept below 25°C (but not necesseraly in cold chain)'),
('17*25F','17*25F Cold Chain *25F - Must be kept below 25°C and cannot be frozen: check Freeze-tag '),
], 'Cold Chain'),
'sterilized': fields.selection([('yes', 'Yes'), ('no', 'No')], string='Sterile'),
'single_use': fields.selection([('yes', 'Yes'),('no', 'No')], string='Single Use'),
'justification_code_id': fields.many2one('product.justification.code', 'Justification Code'),
'med_device_class': fields.selection([('',''),
('I','Class I (General controls)'),
('II','Class II (General control with special controls)'),
('III','Class III (General controls and premarket)')], 'Medical Device Class'),
'closed_article': fields.selection([('yes', 'Yes'), ('no', 'No'),],string='Closed Article'),
'dangerous_goods': fields.boolean('Dangerous Goods'),
'restricted_country': fields.boolean('Restricted in the Country'),
'country_restriction': fields.many2one('res.country.restriction', 'Country Restriction'),
# TODO: validation on 'un_code' field
'un_code': fields.char('UN Code', size=7),
'gmdn_code' : fields.char('GMDN Code', size=5),
'gmdn_description' : fields.char('GMDN Description', size=64),
'life_time': fields.integer('Product Life Time',
help='The number of months before a production lot may become dangerous and should not be consumed.'),
'use_time': fields.integer('Product Use Time',
help='The number of months before a production lot starts deteriorating without becoming dangerous.'),
'removal_time': fields.integer('Product Removal Time',
help='The number of months before a production lot should be removed.'),
'alert_time': fields.integer('Product Alert Time', help="The number of months after which an alert should be notified about the production lot."),
'currency_id': fields.many2one('res.currency', string='Currency', readonly=True),
'field_currency_id': fields.many2one('res.currency', string='Currency', readonly=True),
'nomen_ids': fields.function(_get_nomen, fnct_search=_search_nomen,
type='many2many', relation='product.nomenclature', method=True, string='Nomenclatures'),
'controlled_substance': fields.boolean(string='Controlled substance'),
}
_defaults = {
'international_status': 'itc',
'duplicate_ok': True,
'perishable': False,
'batch_management': False,
'short_shelf_life': False,
'narcotic': False,
'composed_kit': False,
'dangerous_goods': False,
'restricted_country': False,
'currency_id': lambda obj, cr, uid, c: obj.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id,
'field_currency_id': lambda obj, cr, uid, c: obj.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id,
}
def _check_gmdn_code(self, cr, uid, ids, context=None):
int_pattern = re.compile(r'^\d*$')
for product in self.browse(cr, uid, ids, context=context):
if product.gmdn_code and not int_pattern.match(product.gmdn_code):
return False
return True
def create(self, cr, uid, vals, context=None):
if 'batch_management' in vals:
vals['track_production'] = vals['batch_management']
vals['track_incoming'] = vals['batch_management']
vals['track_outgoing'] = vals['batch_management']
if vals['batch_management']:
vals['perishable'] = True
if 'default_code' in vals:
if vals['default_code'] == 'XXX':
vals.update({'duplicate_ok': True})
else:
vals.update({'duplicate_ok': False})
return super(product_attributes, self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
if 'batch_management' in vals:
vals['track_production'] = vals['batch_management']
vals['track_incoming'] = vals['batch_management']
vals['track_outgoing'] = vals['batch_management']
if vals['batch_management']:
vals['perishable'] = True
if 'default_code' in vals:
if vals['default_code'] == 'XXX':
vals.update({'duplicate_ok': True})
else:
vals.update({'duplicate_ok': False})
return super(product_attributes, self).write(cr, uid, ids, vals, context=context)
def onchange_batch_management(self, cr, uid, ids, batch_management, context=None):
'''
batch management is modified -> modification of Expiry Date Mandatory (perishable)
'''
if batch_management:
return {'value': {'perishable': True}}
return {}
def copy(self, cr, uid, id, default=None, context=None):
product_xxx = self.search(cr, uid, [('default_code', '=', 'XXX')])
if product_xxx:
raise osv.except_osv(_('Warning'), _('A product with a code "XXX" already exists please edit this product to change its Code.'))
product2copy = self.read(cr, uid, [id], ['default_code', 'name'])[0]
if default is None:
default = {}
copy_pattern = _("%s (copy)")
copydef = dict(name=(copy_pattern % product2copy['name']),
default_code="XXX",
# we set international_status to "temp" so that it won't be synchronized with this status
international_status='temp',
)
copydef.update(default)
return super(product_attributes, self).copy(cr, uid, id, copydef, context)
def onchange_code(self, cr, uid, ids, default_code):
'''
Check if the code already exists
'''
res = {}
if default_code:
cr.execute("SELECT * FROM product_product pp where pp.default_code = '%s'" % default_code)
duplicate = cr.fetchall()
if duplicate:
res.update({'warning': {'title': 'Warning', 'message':'The Code already exists'}})
return res
_constraints = [
(_check_gmdn_code, 'Warning! GMDN code must be digits!', ['gmdn_code'])
]
product_attributes()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|