1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO Consulting.
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 osv import osv, fields
23
from tools.translate import _
25
class wizard_consumption_nomenclature(osv.osv_memory):
26
_name ='wizard_consumption.nomenclature'
27
_table = 'wizard_consumption_nomenclature'
30
'rac_id': fields.many2one('real.average.consumption', 'RAC'),
31
'nomen_manda_0': fields.many2one('wizard_consumption.nomenclature.line', 'Main Type'),
32
'nomen_manda_1': fields.many2one('wizard_consumption.nomenclature.line', 'Group'),
33
'nomen_manda_2': fields.many2one('wizard_consumption.nomenclature.line', 'Family'),
34
'nomen_manda_3': fields.many2one('wizard_consumption.nomenclature.line', 'Root'),
36
# 'nomen_sub_0': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 1'),
37
# 'nomen_sub_1': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 2'),
38
# 'nomen_sub_2': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 3'),
39
# 'nomen_sub_3': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 4'),
40
# 'nomen_sub_4': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 5'),
41
# 'nomen_sub_5': fields.many2one('wizard_consumption.nomenclature.line', 'Sub Class 6'),
44
def onChangeSearchNomenclature(self, cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context=None):
47
prod = self.pool.get('product.product')
48
return prod.onChangeSearchNomenclature(cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, context)
50
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
53
line = self.pool.get('wizard_consumption.nomenclature.line')
54
ret = super(wizard_consumption_nomenclature, self).fields_view_get( cr, uid, view_id, view_type, context, toolbar, submenu)
55
if context.get('rac_id'):
56
obj = self.browse(cr, uid, context['rac_id'])
58
if obj['nomen_manda_%s'%(x,)]:
59
dom = [('parent_id', '=', obj['nomen_manda_%s'%(x,)].id), ('level', '=', x+1)]
60
ret['fields']['nomen_manda_%s'%(x+1,)]['selection'] = [(False, '')]+line._name_search(cr, uid, '', dom, context={}, limit=None, name_get_uid=1)
63
def set_nomenclature(self, cr, uid, ids, context={}):
64
nom = self.browse(cr, uid, ids[0])
65
rac = self.pool.get('real.average.consumption')
67
for f in ['nomen_manda_3', 'nomen_manda_2', 'nomen_manda_1', 'nomen_manda_0']:
69
rac.write(cr, uid, nom.rac_id.id, {'nomen_id': nom[f].id})
73
rac.write(cr, uid, nom.rac_id.id, {'nomen_id': False})
75
return {'type': 'ir.actions.act_window_close'}
77
wizard_consumption_nomenclature()
79
class wizard_consumption_nomenclature_nome(osv.osv):
80
_name = 'wizard_consumption.nomenclature.line'
81
_inherit = 'product.nomenclature'
82
_table = 'product_nomenclature'
84
def name_get(self, cr, uid, ids, *a, **b):
86
for nom in self.read(cr, uid, ids, ['name', 'number_of_products']):
87
res.append((nom['id'],'%s (%s)'%(nom['name'], nom['number_of_products'])))
93
wizard_consumption_nomenclature_nome()