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 osv, fields
24 from tools.translate import _
26 class auction_lots_invoice(osv.osv_memory):
27 _name = 'auction.lots.invoice'
28 _description = "Auction Lots Invoice"
31 'amount': fields.float('Invoiced Amount', required=True, readonly=True),
32 'amount_topay': fields.float('Amount to pay', required=True, readonly=True),
33 'amount_paid': fields.float('Amount paid', readonly=True),
34 'objects': fields.integer('# of objects', required=True, readonly=True),
35 'ach_uid': fields.many2one('res.partner','Buyer Name', required=True ),
36 'number': fields.integer('Invoice Number'),
39 def default_get(self, cr, uid, fields, context=None):
41 To get default values for the object.
42 @param self: The object pointer.
43 @param cr: A database cursor
44 @param uid: ID of the user currently logged in
45 @param fields: List of fields for which we want default values
46 @param context: A standard dictionary
47 @return: A dictionary which of fields with values.
51 res = super(auction_lots_invoice, self).default_get(cr, uid, fields, context=context)
52 lots = self.pool.get('auction.lots').read(cr, uid, context.get('active_ids', []))
53 auction = self.pool.get('auction.dates').read(cr, uid, [lots[0]['auction_id'][0]])[0]
59 price_lot = lot['obj_price'] or 0.0
61 costs = self.pool.get('auction.lots').compute_buyer_costs(cr, uid, [lot['id']])
62 price_lot += costs['amount']
66 if uid and (lot['ach_uid'][0]<>uid):
67 raise osv.except_osv(_('UserError'), _('Two different buyers for the same invoice !\nPlease correct this problem before invoicing'))
68 uid = lot['ach_uid'][0]
69 elif lot['ach_login']:
70 refs = self.pool.get('res.partner').search(cr, uid, [('ref','=',lot['ach_login'])])
73 if 'ach_pay_id' in lot and lot['ach_pay_id']:
74 price_paid += price_lot
77 price_topay += price_lot
80 #TODO: recuperer id next invoice (de la sequence)???
81 invoice_number = False
82 for lot in self.pool.get('auction.lots').browse(cr, uid, context.get('active_ids', []), context=context):
83 if 'objects' in fields:
84 res.update({'objects':len(context.get('active_ids', []))})
85 if 'amount' in fields:
86 res.update({'amount': price})
87 if 'ach_uid' in fields:
88 res.update({'ach_uid': uid})
89 if 'amount_topay' in fields:
90 res.update({'amount_topay':price_topay})
91 if 'amount_paid' in fields:
92 res.update({'amount_paid':price_paid})
93 if 'number' in fields:
94 res.update({'number':invoice_number})
97 def print_report(self, cr, uid, ids, context=None):
99 Create an invoice report.
100 @param cr: the current row, from the database cursor.
101 @param uid: the current user’s ID for security checks.
102 @param ids: List of Auction lots make invoice buyer’s IDs
103 @return: dictionary of account invoice form.
107 datas = {'ids' : context.get('active_ids',[])}
108 res = self.read(cr, uid, ids, ['number','ach_uid'])
109 res = res and res[0] or {}
112 'type' : 'ir.actions.report.xml',
113 'report_name':'auction.invoice',
117 auction_lots_invoice()
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: