Launchpad automatic translations update.
[odoo/odoo.git] / addons / auction / wizard / auction_lots_make_invoice_buyer.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 from osv import fields, osv
22
23 class auction_lots_make_invoice_buyer(osv.osv_memory):
24     """Make Invoice for Buyer"""
25     
26     _name = "auction.lots.make.invoice.buyer"
27     _description = __doc__
28     _columns= {
29        'amount': fields.float('Invoiced Amount', required =True, readonly=True, help="Buyer Price"), 
30        'objects':fields.integer('# of objects', required =True, readonly=True), 
31        'number':fields.char('Invoice Number', size=64), 
32        'buyer_id':fields.many2one('res.partner', 'Buyer', required=True), 
33     }
34     _defaults={
35        'number': lambda *a: False,
36     }
37     
38     def default_get(self, cr, uid, fields, context=None):
39         """ 
40          To get default values for the object.
41          @param self: The object pointer.
42          @param cr: A database cursor
43          @param uid: ID of the user currently logged in
44          @param fields: List of fields for which we want default values 
45          @param context: A standard dictionary 
46          @return: A dictionary which of fields with values. 
47         """        
48         if context is None:
49             context={}
50         res = super(auction_lots_make_invoice_buyer, self).default_get(cr, uid, fields, context=context)
51         lots_obj=self.pool.get('auction.lots')
52         for lot in lots_obj.browse(cr, uid, context.get('active_ids', []), context=context):
53             if 'amount' in fields:
54                 res.update({'amount': lot.buyer_price})                
55             if 'buyer_id' in fields:
56                 res.update({'buyer_id': lot.ach_uid and lot.ach_uid.id or False})                        
57             if 'objects' in fields:
58                 res.update({'objects': len(context.get('active_ids', []))})   
59         return res
60
61     def makeInvoices(self, cr, uid, ids, context=None):
62         """
63         Create an invoice for selected lots (IDS) to BUYER_ID .
64         @param cr: the current row, from the database cursor.
65         @param uid: the current user’s ID for security checks.
66         @param ids: List of Auction lots make invoice buyer’s IDs
67         @return: dictionary of  account invoice form.
68         """    
69         order_obj = self.pool.get('auction.lots')
70         mod_obj = self.pool.get('ir.model.data') 
71         result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter')
72         id = mod_obj.read(cr, uid, result, ['res_id'])
73         lots = order_obj.browse(cr, uid, context.get('active_ids', []), context=context)
74         for current in self.browse(cr, uid, ids, context=context):
75             invoice_number = current.number
76             for lot in lots:
77                 up_auction = order_obj.write(cr, uid, [lot.id], {'ach_uid': current.buyer_id.id})
78             lots_ids = order_obj.lots_invoice(cr, uid, context.get('active_ids', []), context, current.number)
79             return  {
80                 'domain': "[('id','in', ["+','.join(map(str, lots_ids))+"])]", 
81                 'name': 'Buyer invoices', 
82                 'view_type': 'form', 
83                 'view_mode': 'tree,form', 
84                 'res_model': 'account.invoice', 
85                 'view_id': False, 
86                 'context': "{'type':'in_refund'}", 
87                 'type': 'ir.actions.act_window', 
88                 'search_view_id': id['res_id']         
89             }
90
91 auction_lots_make_invoice_buyer()