1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
29 pay_form = '''<?xml version="1.0"?>
30 <form string="Pay objects">
31 <field name="amount"/>
32 <field name="statement_id1" domain="[('state','=','draft')]"/>
33 <field name="amount2"/>
34 <field name="statement_id2" domain="[('state','=','draft')]"/>
35 <field name="amount3"/>
36 <field name="statement_id3" domain="[('state','=','draft')]"/>
38 <field name="buyer_id"/>
42 def _start(self,cr,uid,data,context):
43 pool = pooler.get_pool(cr.dbname)
44 rec=pool.get('auction.lots').browse(cr,uid,data['ids'],context)
47 amount1+=r.buyer_price
48 buyer= r and r.ach_uid.id or False
50 raise wizard.except_wizard('Error !', 'Some lots of the selection are already paid.')
51 return {'amount':amount1, 'total':amount1,'buyer_id':buyer}
54 'amount': {'string': 'Amount paid', 'type':'float'},
55 'buyer_id': {'string': 'Buyer', 'type': 'many2one', 'relation':'res.partner'},
56 'statement_id1': {'string':'Statement', 'type':'many2one', 'required':True, 'relation':'account.bank.statement'},
57 'amount2': {'string': 'Amount paid', 'type':'float'},
58 'statement_id2': {'string':'Statement', 'type':'many2one', 'relation':'account.bank.statement'},
59 'amount3': {'string': 'Amount paid', 'type':'float'},
60 'statement_id3': {'string':'Statement', 'type':'many2one', 'relation':'account.bank.statement'},
61 'total': {'string': 'Amount to paid', 'type':'float','readonly':True}
64 def _pay_and_reconcile(self, cr, uid, data, context):
65 if not abs(data['form']['total'] - (data['form']['amount']+data['form']['amount2']+data['form']['amount3']))<0.01:
66 rest=data['form']['total']-(data['form']['amount']+data['form']['amount2']+data['form']['amount3'])
67 raise wizard.except_wizard('Payment aborted !', 'You should pay all the total: "%.2f" are missing to accomplish the payment.' %(round(rest,2)))
69 pool = pooler.get_pool(cr.dbname)
70 lots = pool.get('auction.lots').browse(cr,uid,data['ids'],context)
71 ref_bk_s=pooler.get_pool(cr.dbname).get('account.bank.statement.line')
74 if data['form']['buyer_id']:
75 pool.get('auction.lots').write(cr,uid,[lot.id],{'ach_uid':data['form']['buyer_id']})
76 if not lot.auction_id:
77 raise wizard.except_wizard('Error !', 'No auction date for "%s": Please set one.'%(lot.name))
78 pool.get('auction.lots').write(cr,uid,[lot.id],{'is_ok':True})
80 for st,stamount in [('statement_id1','amount'),('statement_id2','amount2'),('statement_id3','amount3')]:
82 new_id=ref_bk_s.create(cr,uid,{
83 'name':'Buyer:'+str(lot.ach_login or '')+', auction:'+ lots[0].auction_id.name,
84 'date': time.strftime('%Y-%m-%d'),
85 'partner_id':data['form']['buyer_id'] or False,
87 'statement_id':data['form'][st],
88 'account_id':lot.auction_id.acc_income.id,
89 'amount':data['form'][stamount]
92 pool.get('auction.lots').write(cr,uid,[lot.id],{'statement_id':[(4,new_id)]})
96 class wiz_auc_lots_pay(wizard.interface):
100 'result': {'type': 'form', 'arch':pay_form, 'fields': pay_fields, 'state':[('end','Cancel'),('pay','Pay')]}
103 'actions': [_pay_and_reconcile],
104 'result': {'type': 'state', 'state':'end'}
106 wiz_auc_lots_pay('auction.pay.buy')
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: