[REF]
[odoo/odoo.git] / addons / auction / wizard / wizard_lots_numerotate.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 import wizard
23 import netsvc
24 import pooler
25 import sql_db
26
27 numerotate_form_cont = '''<?xml version="1.0"?>
28 <form title="%s">
29     <field name="number" string="%s"/>
30 </form>''' % ('Continuous Numerotation','First Number')
31
32 numerotate_fields_cont = {
33     'number': {'string':'First Number', 'type':'integer', 'required':True}
34 }
35
36 numerotate_not_exist = '''<?xml version="1.0"?>
37 <form title="%s">
38     <label string="This lot does not exist !" colspan="4"/>
39 </form>''' % ('Catalog Numerotation',)
40
41
42 numerotate_form = '''<?xml version="1.0"?>
43 <form title="%s">
44     <separator string="%s" colspan="4"/>
45     <field name="bord_vnd_id"/>
46     <newline/>
47     <field name="lot_num"/>
48 </form>''' % ('Catalog Numerotation','Object Reference')
49
50 numerotate_fields = {
51     'bord_vnd_id': {'string':'Depositer Inventory', 'type':'many2one', 'required':True, 'relation':'auction.deposit'},
52     'lot_num': {'string':'Lot Number', 'type':'integer', 'required':True},
53 }
54
55 numerotate_form2 = '''<?xml version="1.0"?>
56 <form title="%s">
57     <group>
58         <separator string="%s" colspan="4"/>
59         <field name="bord_vnd_id" readonly="1"/>
60         <field name="lot_num" readonly="1"/>
61         <field name="name" readonly="1" colspan="3"/>
62         <field name="obj_desc" readonly="1" colspan="3"/>
63         <field name="lot_est1" readonly="1"/>
64         <field name="lot_est2" readonly="1"/>
65         <separator string="%s" colspan="4"/>
66         <field name="obj_num"/>
67     </group>
68 </form>''' % ('Catalog Numerotation','Object Reference','Object Reference')
69
70 numerotate_fields2 = {
71     'bord_vnd_id': {'string':'Object Inventory', 'type':'many2one', 'relation':'auction.deposit', 'readonly':True},
72     'lot_num': {'string':'Inventory Number', 'type':'integer', 'readonly':True},
73     'lot_est1': {'string':'Minimum Estimation', 'type':'float', 'readonly':True},
74     'lot_est2': {'string':'Maximum Estimation', 'type':'float', 'readonly':True},
75     'name': {'string':'Short Description', 'type':'char', 'size':64, 'readonly':True},
76     'obj_desc': {'string':'Description', 'type':'text', 'readonly':True},
77     'obj_num': {'string':'Catalog Number', 'type':'integer', 'required':True}
78 }
79
80 def _read_record(self,cr,uid,datas,context={}):
81     form = datas['form']
82     res = pooler.get_pool(cr.dbname).get('auction.lots').search(cr,uid,[('bord_vnd_id','=',form['bord_vnd_id']), ('lot_num','=',int(form['lot_num']))])
83     found = [r for r in res if r in datas['ids']]
84     if len(found)==0:
85         raise wizard.except_wizard('UserError', 'This record does not exist !')
86     datas = pooler.get_pool(cr.dbname).get('auction.lots').read(cr,uid,found,['obj_num', 'name', 'lot_est1', 'lot_est2', 'obj_desc'])
87     return datas[0]
88
89 def _test_exist(self,cr,uid,datas,context={}):
90     form = datas['form']
91     res = pooler.get_pool(cr.dbname).get('auction.lots').search(cr,uid,[('bord_vnd_id','=',form['bord_vnd_id']), ('lot_num','=',int(form['lot_num']))])
92     found = [r for r in res if r in datas['ids']]
93     if len(found)==0:
94         return 'not_exist'
95     return 'search'
96
97 def _numerotate(self,cr,uid,datas,context={}):
98     form = datas['form']
99     res = pooler.get_pool(cr.dbname).get('auction.lots').search(cr,uid,[('bord_vnd_id','=',form['bord_vnd_id']), ('lot_num','=',int(form['lot_num']))])
100     found = [r for r in res if r in datas['ids']]
101     if len(found)==0:
102         raise wizard.except_wizard('UserError', 'This record does not exist !')
103     pooler.get_pool(cr.dbname).get('auction.lots').write(cr,uid,found,{'obj_num':int(form['obj_num'])} )
104     return {'lot_inv':'', 'lot_num':''}
105
106 def _numerotate_cont(self,cr,uid,datas,context={}):
107     nbr = int(datas['form']['number'])
108     refs = pooler.get_pool(cr.dbname).get('auction.lots')
109     rec_ids = refs.browse(cr,uid,datas['ids'])
110     for rec_id in rec_ids:
111         refs.write(cr,uid,[rec_id.id],{'obj_num':nbr})
112         nbr+=1
113     return {}
114
115 class wiz_auc_lots_numerotate(wizard.interface):
116     states = {
117         'init': {
118             'actions': [],
119             'result': {'type': 'form', 'arch':numerotate_form, 'fields': numerotate_fields, 'state':[('end','Cancel'),('choice','Continue')]}
120         },
121         'search': {
122             'actions': [_read_record],
123             'result': {'type': 'form', 'arch':numerotate_form2, 'fields': numerotate_fields2, 'state':[('end','Exit'),('init','Back'),('set_number','Numerotate')]}
124         },
125         'choice' : {
126             'actions' : [],
127             'result' : {'type' : 'choice', 'next_state': _test_exist }
128         },
129         'not_exist' : {
130             'actions': [],
131             'result': {'type': 'form', 'arch':numerotate_not_exist, 'fields': {}, 'state':[('end','Exit'),('init','Retry')]}
132         },
133         'set_number': {
134             'actions': [_numerotate],
135             'result': {'type': 'state', 'state':'init'}
136         }
137     }
138 wiz_auc_lots_numerotate('auction.lots.numerotate');
139
140
141 class wiz_auc_lots_numerotate(wizard.interface):
142     states = {
143         'init': {
144             'actions': [],
145             'result': {'type': 'form', 'arch':numerotate_form_cont, 'fields': numerotate_fields_cont, 'state':[('end','Exit'),('set_number','Numerotation')]}
146         },
147         'set_number': {
148             'actions': [_numerotate_cont],
149             'result': {'type': 'state', 'state':'end'}
150         }
151     }
152 wiz_auc_lots_numerotate('auction.lots.numerotate_cont');
153 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
154