1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 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 ##############################################################################
22 from osv import fields
27 def _invoice_membership(self, cr, uid, data, context):
28 partner_ids = data['ids']
29 product_id = data['form']['product']
31 pool = pooler.get_pool(cr.dbname)
34 SELECT partner_id, id, type
35 FROM res_partner_address
36 WHERE partner_id IN (%s)
37 ''' % ','.join([str(id) for id in partner_ids])
39 fetchal = cr.fetchall()
41 raise wizard.except_wizard('Error !', 'No Address defined for this partner')
42 partner_address_ids = {}
43 for x in range(len(fetchal)):
48 if partner_address_ids.has_key(pid) and partner_address_ids[pid]['type'] == 'invoice':
50 partner_address_ids[pid] = {'id': id, 'type': type}
54 invoice_obj = pool.get('account.invoice')
55 partner_obj = pool.get('res.partner')
56 product_obj = pool.get('product.product')
57 invoice_line_obj = pool.get(('account.invoice.line'))
58 invoice_tax_obj = pool.get(('account.invoice.tax'))
59 product = product_obj.read(cr, uid, product_id, ['uom_id'])
61 for partner_id in partner_ids:
62 account_id = partner_obj.read(cr, uid, partner_id, ['property_account_receivable'])['property_account_receivable'][0]
63 invoice_id = invoice_obj.create(cr, uid, {
64 'partner_id' : partner_id,
65 'address_invoice_id': partner_address_ids[partner_id]['id'],
66 'account_id': account_id,
71 'invoice_id' : invoice_id,
72 'product_id' : product_id,
77 line_dict = invoice_line_obj.product_id_change(cr, uid, {}, product_id, product['uom_id'][0], quantity, '', 'out_invoice', partner_id, context=context)
79 line_value.update(line_dict['value'])
80 if line_value['invoice_line_tax_id']:
81 tax_tab = [(6, 0, line_value['invoice_line_tax_id'])]
82 line_value['invoice_line_tax_id'] = tax_tab
85 invoice_line_id = invoice_line_obj.create(cr, uid, line_value)
86 invoice_list.append(invoice_id)
87 if line_value['invoice_line_tax_id']:
88 invoice_obj.write(cr, uid, [invoice_id], {'tax_line':tax_tab})
89 tax_value = invoice_tax_obj.compute(cr, uid, invoice_id).values()[0]
90 invoice_tax_obj.create(cr, uid, tax_value)
94 ('id', 'in', invoice_list),
96 'name': 'Membership invoice',
98 'view_mode': 'tree,form',
99 'res_model': 'account.invoice',
100 'type': 'ir.actions.act_window',
105 wizard_arch= """<?xml version="1.0"?>
106 <form string="Choose invoice details">
109 domain="[('membership','=','True')]"
110 context="product='membership_product'"
116 class wizard_invoice_membership(wizard.interface):
124 'arch' : wizard_arch,
127 'string': 'Membership product',
129 'relation': 'product.product',
133 'state' : [('end', 'Cancel'),('ok', 'Confirm') ]}
138 'result' : {'type' : 'action',
139 'action': _invoice_membership,
146 wizard_invoice_membership("wizard_invoice_membership")
148 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: