1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 ##############################################################################
27 numerotate_form_cont = '''<?xml version="1.0"?>
29 <field name="number" string="%s"/>
30 </form>''' % ('Continuous Numerotation','First Number')
32 numerotate_fields_cont = {
33 'number': {'string':'First Number', 'type':'integer', 'required':True}
36 numerotate_not_exist = '''<?xml version="1.0"?>
38 <label string="This lot does not exist !" colspan="4"/>
39 </form>''' % ('Catalog Numerotation',)
42 numerotate_form = '''<?xml version="1.0"?>
44 <separator string="%s" colspan="4"/>
45 <field name="bord_vnd_id"/>
47 <field name="lot_num"/>
48 </form>''' % ('Catalog Numerotation','Object Reference')
51 'bord_vnd_id': {'string':'Depositer Inventory', 'type':'many2one', 'required':True, 'relation':'auction.deposit'},
52 'lot_num': {'string':'Lot Number', 'type':'integer', 'required':True},
55 numerotate_form2 = '''<?xml version="1.0"?>
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"/>
68 </form>''' % ('Catalog Numerotation','Object Reference','Object Reference')
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}
80 def _read_record(self,cr,uid,datas,context={}):
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']]
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'])
89 def _test_exist(self,cr,uid,datas,context={}):
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']]
97 def _numerotate(self,cr,uid,datas,context={}):
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']]
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':''}
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})
115 class wiz_auc_lots_numerotate(wizard.interface):
119 'result': {'type': 'form', 'arch':numerotate_form, 'fields': numerotate_fields, 'state':[('end','Cancel'),('choice','Continue')]}
122 'actions': [_read_record],
123 'result': {'type': 'form', 'arch':numerotate_form2, 'fields': numerotate_fields2, 'state':[('end','Exit'),('init','Back'),('set_number','Numerotate')]}
127 'result' : {'type' : 'choice', 'next_state': _test_exist }
131 'result': {'type': 'form', 'arch':numerotate_not_exist, 'fields': {}, 'state':[('end','Exit'),('init','Retry')]}
134 'actions': [_numerotate],
135 'result': {'type': 'state', 'state':'init'}
138 wiz_auc_lots_numerotate('auction.lots.numerotate');
141 class wiz_auc_lots_numerotate(wizard.interface):
145 'result': {'type': 'form', 'arch':numerotate_form_cont, 'fields': numerotate_fields_cont, 'state':[('end','Exit'),('set_number','Numerotation')]}
148 'actions': [_numerotate_cont],
149 'result': {'type': 'state', 'state':'end'}
152 wiz_auc_lots_numerotate('auction.lots.numerotate_cont');
153 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: