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

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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# -*- coding: 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 Affero 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import time
from datetime import datetime
from dateutil.relativedelta import relativedelta

from osv import osv, fields
import netsvc
import pooler
from tools.translate import _
import decimal_precision as dp
from osv.orm import browse_record, browse_null

import product_nomenclature as pn

def _order_nomenclature_get_product_code_name(module, cr, uid, ids, fieldname, args, context=None):
    res = {}
    if not ids:
        return res
    fields = {  # field to read /res field
        'default_code': 'default_code',
        'name': 'default_name',
    }
    if isinstance(ids, (int, long)):
        ids = [ids]
    for rpol in module.read(cr, uid, ids, ['product_id'], context=context):
        res[rpol['id']] = {}
        for f in fields:
            res[rpol['id']][fields[f]] = ''
        if rpol['product_id']:
            rp = module.pool.get('product.product').read(cr, uid,
                [rpol['product_id'][0]], fields.keys(), context=context)
            if rp and rp[0]:
                for f in fields:
                   res[rpol['id']][fields[f]] = rp[0].get(f, '')
    return res

#
# PO
#
class purchase_order_line(osv.osv):
    '''
    1. add new fields :
       - nomenclature_id : contains the nomenclature id
       - nomenclature_code : contains the corresponding code
       - nomenclature_description : contains the corresponding description
    '''
    def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order=False, fiscal_position=False, date_planned=False,
            name=False, price_unit=False, notes=False):
        '''
        overriden on_change function
        '''
        result = super(purchase_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order, fiscal_position, date_planned,
            name, price_unit, notes)

        # comment is cleared
        result['value'].update({'comment':False})

        # change nomenclature_description to correspond to the product
        # for now simply clear nomenclature if a product has been selected
        if product:
            result['value'].update({'nomenclature_description':False})
            # product has been selected, nomenclatures are readonly and empty
            self.pool.get('product.product')._resetNomenclatureFields(result['value'])
            productObj = self.pool.get('product.product').browse(cr, uid, product)
            # name is the name of the product
            result['value'].update({'name':productObj.name})
            result['value'].update({'default_code':productObj.default_code})
            result['value'].update({'default_name':productObj.name})
        else:
            result['value'].update({'default_code':False})
            result['value'].update({'default_name':False})

        return result

    def product_uom_change(self, cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order=False, fiscal_position=False, date_planned=False,
            name=False, price_unit=False, notes=False):
        '''
        override product_uom_change to avoid the reset of Comment when the UOM is changed
        '''
        # call to super
        result = super(purchase_order_line, self).product_uom_change(cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order, fiscal_position, date_planned,
            name, price_unit, notes)
        # drop modification to name attribute
        if 'name' in result['value']:
            del result['value']['name']
        # drop modification to comment attribute
        if 'comment' in result['value']:
            del result['value']['comment']

        if qty:
            result = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom, qty, 'product_qty', result=result)

        return result

    def product_qty_change(self, cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order=False, fiscal_position=False, date_planned=False,
            name=False, price_unit=False, notes=False, state=False, old_unit_price=False,
            nomen_manda_0=False, comment=False,context=None):
        '''
        interface product_id_change to avoid the reset of Comment field when the qty is changed
        '''
        if not context:
            context = {}

        if not product and not comment and not nomen_manda_0 and qty != 0.00:
            return {}

        prod_context = context.copy()
        if 'categ' in prod_context:
            del prod_context['categ']

        result = self.product_id_on_change(cr, uid, ids, pricelist, product, qty, uom,
            partner_id, date_order, fiscal_position, date_planned,
            name, price_unit, notes, state, old_unit_price,nomen_manda_0,comment,context=prod_context)

        # drop modification to name attribute
        if 'name' in result['value']:
            del result['value']['name']
        # drop modification to comment attribute
        if 'comment' in result['value']:
            del result['value']['comment']

        if qty:
            uom = uom or result.get('value', {}).get('product_uom')
            result = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom, qty, 'product_qty', result=result)

        return result

    def _relatedFields(self, cr, uid, vals, context=None):
        '''
        related fields for create and write
        '''
        # recreate description because in readonly
        if ('product_id' in vals) and (vals['product_id']):
            # no nomenclature description
            vals.update({'nomenclature_description':False})
            # update the name (comment) of order line
            # the 'name' is no more the get_name from product, but instead
            # the name of product
            productObj = self.pool.get('product.product').browse(cr, uid, vals['product_id'], context=context)
            vals.update({'name':productObj.name})
            vals.update({'default_code':productObj.default_code})
            vals.update({'default_name':productObj.name})
            # erase the nomenclature - readonly
            self.pool.get('product.product')._resetNomenclatureFields(vals)
        elif ('product_id' in vals) and (not vals['product_id']):
            sale = self.pool.get('sale.order.line')
            sale._setNomenclatureInfo(cr, uid, vals, context)
            # erase default code
            vals.update({'default_code':False})
            vals.update({'default_name':False})

            if 'comment' in vals:
                vals.update({'name':vals['comment']})
        # clear nomenclature filter values
        #self.pool.get('product.product')._resetNomenclatureFields(vals)

    def create(self, cr, uid, vals, context=None):
        '''
        override create. don't save filtering data
        '''
        self._relatedFields(cr, uid, vals, context)

        return super(purchase_order_line, self).create(cr, uid, vals, context=context)

    def write(self, cr, uid, ids, vals, context=None):
        '''
        override write. don't save filtering data
        '''
        self._relatedFields(cr, uid, vals, context)

        return super(purchase_order_line, self).write(cr, uid, ids, vals, context=context)

    def nomenChange(self, cr, uid, id, fieldNumber, nomenclatureId, nomenclatureType,
                    nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context=None, *optionalList):
        '''
        direct call to sale processes
        '''
        sale = self.pool.get('sale.order.line')
        return sale.nomenChange(cr, uid, id, fieldNumber, nomenclatureId, nomenclatureType,
                                nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context, *optionalList)

    def codeChange(self, cr, uid, id, fieldNumber, code, nomenclatureType,
                   nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context=None, *optionalList):
        '''
        direct call to sale processes
        '''
        sale = self.pool.get('sale.order.line')
        return sale.codeChange(cr, uid, id, fieldNumber, code, nomenclatureType,
                   nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context, *optionalList)

    def _get_product_code_name(self, cr, uid, ids, fieldname, args, context=None):
        return _order_nomenclature_get_product_code_name(self, cr, uid, ids, fieldname, args, context=context)

    # PO/SO - IDENTICAL
    _columns = {
        'nomenclature_code': fields.char('Nomenclature code', size=1024),
        'comment': fields.char('Comment', size=1024),
        'name': fields.char('Comment', size=1024, required=True),
        'default_code': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Code', multi="product",),
        'default_name': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Description', multi="product",),

        ### EXACT COPY-PASTE FROM product_nomenclature -> product_template
        # mandatory nomenclature levels -> not mandatory on screen here
        'nomen_manda_0': fields.many2one('product.nomenclature', 'Main Type'),
        'nomen_manda_1': fields.many2one('product.nomenclature', 'Group'),
        'nomen_manda_2': fields.many2one('product.nomenclature', 'Family'),
        'nomen_manda_3': fields.many2one('product.nomenclature', 'Root'),

        # optional nomenclature levels
        'nomen_sub_0': fields.many2one('product.nomenclature', 'Sub Class 1'),
        'nomen_sub_1': fields.many2one('product.nomenclature', 'Sub Class 2'),
        'nomen_sub_2': fields.many2one('product.nomenclature', 'Sub Class 3'),
        'nomen_sub_3': fields.many2one('product.nomenclature', 'Sub Class 4'),
        'nomen_sub_4': fields.many2one('product.nomenclature', 'Sub Class 5'),
        'nomen_sub_5': fields.many2one('product.nomenclature', 'Sub Class 6'),

        # concatenation of nomenclature in a visible way
        'nomenclature_description': fields.char('Nomenclature', size=1024),
    }
    ### END OF COPY

    _defaults = {
    }

    _inherit = 'purchase.order.line'
    _description = 'Purchase Order Line'

    def get_nomen(self, cr, uid, id, field):
        return self.pool.get('product.nomenclature').get_nomen(cr, uid, self, id, field)

    def get_sub_nomen(self, cr, uid, id, field):
        return self.pool.get('product.nomenclature').get_sub_nomen(cr, uid, self, id, field)

    def onChangeSearchNomenclature(self, cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=True, context=None):
        return self.pool.get('sale.order.line').onChangeSearchNomenclature(cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=num, context=context)

    def onChangeSubNom(self, cr, uid, id, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, nomen_sub_0, nomen_sub_1, nomen_sub_2, nomen_sub_3, nomen_sub_4, nomen_sub_5, context=None):
        return self.pool.get('sale.order.line').onChangeSubNom(cr, uid, id, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, nomen_sub_0, nomen_sub_1, nomen_sub_2, nomen_sub_3, nomen_sub_4, nomen_sub_5, context)
purchase_order_line()


class purchase_order_merged_line(osv.osv):
    _name = 'purchase.order.merged.line'
    _inherit = 'purchase.order.merged.line'

    def _get_product_code_name(self, cr, uid, ids, fieldname, args, context=None):
        return _order_nomenclature_get_product_code_name(self, cr, uid, ids, fieldname, args, context=context)

    _columns = {
        'nomenclature_code': fields.char('Nomenclature code', size=1024),
        'comment': fields.char('Comment', size=1024),
        'name': fields.char('Comment', size=1024, required=True),
        'default_code': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Code', multi="product",),
        'default_name': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Description', multi="product",),

        ### EXACT COPY-PASTE FROM product_nomenclature -> product_template
        # mandatory nomenclature levels -> not mandatory on screen here
        'nomen_manda_0': fields.many2one('product.nomenclature', 'Main Type'),
        'nomen_manda_1': fields.many2one('product.nomenclature', 'Group'),
        'nomen_manda_2': fields.many2one('product.nomenclature', 'Family'),
        'nomen_manda_3': fields.many2one('product.nomenclature', 'Root'),

        # optional nomenclature levels
        'nomen_sub_0': fields.many2one('product.nomenclature', 'Sub Class 1'),
        'nomen_sub_1': fields.many2one('product.nomenclature', 'Sub Class 2'),
        'nomen_sub_2': fields.many2one('product.nomenclature', 'Sub Class 3'),
        'nomen_sub_3': fields.many2one('product.nomenclature', 'Sub Class 4'),
        'nomen_sub_4': fields.many2one('product.nomenclature', 'Sub Class 5'),
        'nomen_sub_5': fields.many2one('product.nomenclature', 'Sub Class 6'),

        # concatenation of nomenclature in a visible way
        'nomenclature_description': fields.char('Nomenclature', size=1024),
    }

purchase_order_merged_line()

#
# SO
#
class sale_order_line(osv.osv):
    '''
    1. add new fields :
       - nomenclature_id : contains the nomenclature id
       - nomenclature_code : contains the corresponding code
       - nomenclature_description : contains the corresponding description
    '''
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
        '''
        overriden on_change function
        '''
        result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
            uom, qty_uos, uos, name, partner_id,
            lang, update_tax, date_order, packaging, fiscal_position, flag)

        # comment is cleared
        result['value'].update({'comment':False})

        # change nomenclature_description to correspond to the product
        # for now simply clear nomenclature if a product has been selected
        if product:
            result['value'].update({'nomenclature_description':False})
            # product has been selected, nomenclatures are readonly and empty
            self.pool.get('product.product')._resetNomenclatureFields(result['value'])
            productObj = self.pool.get('product.product').browse(cr, uid, product)
            # name is the name of the product
            result['value'].update({'name':productObj.name})
            result['value'].update({'default_code':productObj.default_code})
            result['value'].update({'default_name':productObj.name})
        else:
            result['value'].update({'default_code':False})
            result['value'].update({'default_name':False})

        return result

    def product_uom_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False):
        '''
        override product_uom_change to avoid the reset of Comment when the UOM is changed
        '''
        # call to super
        result = super(sale_order_line, self).product_uom_change(cr, uid, ids, pricelist, product, qty,
            uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order)
        # drop modification to name attribute
        if 'name' in result['value']:
            del result['value']['name']
        # drop modification to comment attribute
        if 'comment' in result['value']:
            del result['value']['comment']

        # Round up the quantity
        if qty:
            result = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom, qty, 'product_qty', result=result)

        return result

    def product_qty_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
        '''
        interface product_id_change to avoid the reset of Comment field when the qty is changed
        '''
        result = self.product_id_change(cr, uid, ids, pricelist, product, qty,
                                        uom, qty_uos, uos, name, partner_id,
                                        lang, update_tax, date_order, packaging, fiscal_position, flag)

        # drop modification to name attribute
        if 'name' in result['value']:
            del result['value']['name']
        # drop modification to comment attribute
        if 'comment' in result['value']:
            del result['value']['comment']
        # drop modification to qty
        if 'product_uos_qty' in result['value']:
            del result['value']['product_uos_qty']
        # drop modification to qty
        if 'product_uom_qty' in result['value']:
            del result['value']['product_uom_qty']

        # Round up the quantity
        if qty:
            result = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom, qty, ['product_uom_qty', 'product_uos_qty'], result=result)

        return result

    def product_packaging_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
        '''
        interface product_id_change to avoid the reset of Comment field when the qty is changed
        '''
        result = self.product_qty_change(cr, uid, ids, pricelist, product, qty,
                                        uom, qty_uos, uos, name, partner_id,
                                        lang, update_tax, date_order, packaging, fiscal_position, flag)

        return result

    def _relatedFields(self, cr, uid, vals, context=None):
        '''
        related fields for create and write
        '''
        # recreate description because in readonly
        if ('product_id' in vals) and (vals['product_id']):
            # no nomenclature description
            vals.update({'nomenclature_description':False})
            # update the name (comment) of order line
            # the 'name' is no more the get_name from product, but instead
            # the name of product
            productObj = self.pool.get('product.product').browse(cr, uid, vals['product_id'], context=context)
            vals.update({'name':productObj.name})
            vals.update({'default_code':productObj.default_code})
            vals.update({'default_name':productObj.name})
            # erase the nomenclature - readonly
            self.pool.get('product.product')._resetNomenclatureFields(vals)
        elif ('product_id' in vals) and (not vals['product_id']):
            self._setNomenclatureInfo(cr, uid, vals, context)
            # erase default code
            vals.update({'default_code':False})
            vals.update({'default_name':False})

            if 'comment' in vals:
                vals.update({'name':vals['comment']})
        # clear nomenclature filter values
        #self.pool.get('product.product')._resetNomenclatureFields(vals)

    def create(self, cr, uid, vals, context=None):
        '''
        override create. don't save filtering data
        '''
        self._relatedFields(cr, uid, vals, context)

        return super(sale_order_line, self).create(cr, uid, vals, context=context)

    def write(self, cr, uid, ids, vals, context=None):
        '''
        override write. don't save filtering data
        '''
        self._relatedFields(cr, uid, vals, context)

        return super(sale_order_line, self).write(cr, uid, ids, vals, context=context)

    def _setNomenclatureInfo(self, cr, uid, values, context=None):
        '''
        set nomenclature_description
        '''
        if not values:
            return {}

        constants = self.pool.get('product.nomenclature')._returnConstants()

        # the last selected level
        mandaDesc = ''
        levels = constants['levels']
        ids = filter(lambda x: ('nomen_manda_%i'%x in values) and (values['nomen_manda_%i'%x]), range(levels))
        if len(ids) > 0:
            id = values['nomen_manda_%i'%max(ids)]
            mandaDesc = self.pool.get('product.nomenclature').name_get(cr, uid, [id], context)[0][1]

        description = [mandaDesc]

        # add optional names
        sublevels = constants['sublevels']
        ids = filter(lambda x: ('nomen_sub_%i'%x in values) and (values['nomen_sub_%i'%x]), range(sublevels))
        ids = map(lambda x: values['nomen_sub_%i'%x], ids)
        subNomenclatures = self.pool.get('product.nomenclature').read(cr, uid, ids, ['name'], context=context)

        for n in subNomenclatures:
            description.append(n['name'])

        values.update({'nomenclature_description': ':'.join(description)})

    def _productDomain(self, cr, uid, id, context=None):
        '''
        product the dynamic product's domain
        '''
        # all values are updated from 'result' in context
        # loop through these values
        # if the value is not False, create a new domain rule
        assert context, 'No context, error on function call'

        # check and create domain dictionary
        if 'domain' in context['result']:
            domain = context['result']['domain']
        else:
            domain = {}
            context['result']['domain'] = domain

        # empty product domain list
        productList = []
        domain.update({'product_id': productList})


        values = context['result']['value']
        for k,v in values.items():
            if v:
                newRule = (k, '=', v)
                productList.append(newRule)

    def nomenChange(self, cr, uid, id, fieldNumber, nomenclatureId, nomenclatureType,
                    nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context=None, *optionalList):
        '''
        first call the standard product_nomenclature process
        secondly complete dynamic domain
        '''
        assert context, 'No context, error on function call'

        product = self.pool.get('product.product')
        product.nomenChange(cr, uid, id, fieldNumber, nomenclatureId, nomenclatureType,
                            nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context, *optionalList)
        #self._productDomain(cr, uid, id, context)
        self._setNomenclatureInfo(cr, uid, context['result']['value'], context)

        result = context['result']

        return result

    def codeChange(self, cr, uid, id, fieldNumber, code, nomenclatureType,
                   nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context=None, *optionalList):
        '''
        first call the standard product_nomenclature process
        secondly complete dynamic domain
        '''
        assert context, 'No context, error on function call'


        product = self.pool.get('product.product')
        product.codeChange(cr, uid, id, fieldNumber, code, nomenclatureType,
                           nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context, *optionalList)
        #self._productDomain(cr, uid, id, context)
        self._setNomenclatureInfo(cr, uid, context['result']['value'], context)

        result = context['result']
        return result

    def _get_product_code_name(self, cr, uid, ids, fieldname, args, context=None):
        return _order_nomenclature_get_product_code_name(self, cr, uid, ids, fieldname, args, context=context)

    # PO/SO - IDENTICAL
    _columns = {
        'nomenclature_code': fields.char('Nomenclature code', size=1024),
        'comment': fields.char('Comment', size=1024),
        'name': fields.char('Comment', size=1024, required=True, select=True, readonly=True, states={'draft': [('readonly', False)]}),
        'default_code': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Code', multi="product",),
        'default_name': fields.function(_get_product_code_name, type='char', size=1024,
            method=True, string='Product Description', multi="product",),

        ### EXACT COPY-PASTE FROM product_nomenclature -> product_template
        # mandatory nomenclature levels -> not mandatory on screen here
        'nomen_manda_0': fields.many2one('product.nomenclature', 'Main Type'),
        'nomen_manda_1': fields.many2one('product.nomenclature', 'Group'),
        'nomen_manda_2': fields.many2one('product.nomenclature', 'Family'),
        'nomen_manda_3': fields.many2one('product.nomenclature', 'Root'),

        # optional nomenclature levels
        'nomen_sub_0': fields.many2one('product.nomenclature', 'Sub Class 1'),
        'nomen_sub_1': fields.many2one('product.nomenclature', 'Sub Class 2'),
        'nomen_sub_2': fields.many2one('product.nomenclature', 'Sub Class 3'),
        'nomen_sub_3': fields.many2one('product.nomenclature', 'Sub Class 4'),
        'nomen_sub_4': fields.many2one('product.nomenclature', 'Sub Class 5'),
        'nomen_sub_5': fields.many2one('product.nomenclature', 'Sub Class 6'),

        # concatenation of nomenclature in a visible way
        'nomenclature_description': fields.char('Nomenclature', size=1024),
    }
    ### END OF COPY

    _defaults = {
    }

    _inherit = 'sale.order.line'
    _description = 'Sale Order Line'

    def get_nomen(self, cr, uid, id, field):
        return self.pool.get('product.nomenclature').get_nomen(cr, uid, self, id, field)

    def get_sub_nomen(self, cr, uid, id, field):
        return self.pool.get('product.nomenclature').get_sub_nomen(cr, uid, self, id, field)

    def onChangeSearchNomenclature(self, cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=False, context=None):
        ret = self.pool.get('product.product').onChangeSearchNomenclature(cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=num, context=context)
        newval = {}
        for i in range(0, 4):
            if 'nomen_manda_%s'%i not in ret.get('value',{}):
                newval['nomen_manda_%s'%i] = eval('nomen_manda_%s'%i)
        self._setNomenclatureInfo(cr, uid, newval)
        if 'value' not in ret:
            ret['value'] = {}
        ret['value']['nomenclature_description'] = newval.get('nomenclature_description')
        return ret

    def onChangeSubNom(self, cr, uid, id, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, nomen_sub_0, nomen_sub_1, nomen_sub_2, nomen_sub_3, nomen_sub_4, nomen_sub_5, context=None):
        newval = {}
        for i in range(0, 6):
            if i < 4:
                newval['nomen_manda_%s'%i] = eval('nomen_manda_%s'%i)
            newval['nomen_sub_%s'%i] = eval('nomen_sub_%s'%i)
        self._setNomenclatureInfo(cr, uid, newval)
        ret = {'value': {}}
        ret['value']['nomenclature_description'] = newval.get('nomenclature_description')
        return ret



sale_order_line()