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 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
27 class auction_pay_buy(osv.osv_memory):
28 _name = "auction.pay.buy"
29 _description = "Pay buy"
31 'amount': fields.float('Amount', digits= (16, 2), help="Amount For First Bank Statement"),
32 'buyer_id':fields.many2one('res.partner', 'Buyer'),
33 'statement_id1':fields.many2one('account.bank.statement', 'Statement', required=True, help="First Bank Statement For Buyer"),
34 'amount2': fields.float('Amount', digits= (16, 2), help="Amount For Second Bank Statement"),
35 'statement_id2':fields.many2one('account.bank.statement', 'Statement', help="Second Bank Statement For Buyer"),
36 'amount3': fields.float('Amount', digits = (16, 2), help="Amount For Third Bank Statement"),
37 'statement_id3':fields.many2one('account.bank.statement', 'Statement', help="Third Bank Statement For Buyer"),
38 'total': fields.float('Total Amount', digits = (16, 2), readonly =True),
41 def default_get(self, cr, uid, fields, context=None):
43 To get default values for the object.
44 @param self: The object pointer.
45 @param cr: A database cursor
46 @param uid: ID of the user currently logged in
47 @param fields: List of fields for which we want default values
48 @param context: A standard dictionary
49 @return: A dictionary which of fields with values.
53 res = super(auction_pay_buy, self).default_get(cr, uid, fields, context=context)
54 auction_lots_obj= self.pool.get('auction.lots')
55 for lot in auction_lots_obj.browse(cr, uid, context.get('active_ids', []), context=context):
56 if 'amount' in fields:
57 res.update({'amount': lot.buyer_price})
58 if 'buyer_id' in fields:
59 res.update({'buyer_id': lot.ach_uid and lot.ach_uid.id or False})
61 res.update({'total': lot.buyer_price})
64 def pay_and_reconcile(self, cr, uid, ids, context=None):
67 @param cr: the current row, from the database cursor.
68 @param uid: the current user’s ID for security checks.
69 @param ids: the ID or list of IDs
70 @param context: A standard dictionary
73 if context is None: context = {}
74 lot_obj = self.pool.get('auction.lots')
75 bank_statement_line_obj = self.pool.get('account.bank.statement.line')
77 for datas in self.read(cr, uid, ids, context=context):
78 if not abs(datas['total'] - (datas['amount'] + datas['amount2'] + datas['amount3'])) <0.01:
79 rest = datas['total'] - (datas['amount'] + datas['amount2'] + datas['amount3'])
80 raise osv.except_osv(_('Payment aborted !'), _('You should pay all the total: "%.2f" are missing to accomplish the payment.') %(round(rest, 2)))
82 lots = lot_obj.browse(cr, uid, context.get('active_ids', []), context=context)
85 lot_obj.write(cr, uid, [lot.id], {'ach_uid': datas['buyer_id']})
86 if not lot.auction_id:
87 raise osv.except_osv(_('Error!'), _('No auction date for "%s": Please set one.') % (lot.name))
88 lot_obj.write(cr, uid, [lot.id], {'is_ok':True})
90 for st, stamount in [('statement_id1', 'amount'), ('statement_id2', 'amount2'), ('statement_id3', 'amount3')]:
92 new_id = bank_statement_line_obj.create(cr, uid, {
93 'name':'Buyer:'+ str(lot.ach_login or '')+', auction:'+ lots[0].auction_id.name,
94 'date': time.strftime('%Y-%m-%d'),
95 'partner_id': datas['buyer_id'] or False,
97 'statement_id': datas[st],
98 'account_id': lot.auction_id.acc_income.id,
99 'amount': datas[stamount]
102 lot_obj.write(cr, uid, [lot.id], {'statement_id':[(4, new_id)]})
103 return {'type': 'ir.actions.act_window_close'}
106 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: