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 openerp.osv import fields, osv
23 import openerp.addons.decimal_precision as dp
25 class membership_invoice(osv.osv_memory):
26 """Membership Invoice"""
28 _name = "membership.invoice"
29 _description = "Membership Invoice"
31 'product_id': fields.many2one('product.product','Membership', required=True),
32 'member_price': fields.float('Member Price', digits_compute= dp.get_precision('Product Price'), required=True),
34 def onchange_product(self, cr, uid, ids, product_id=False):
35 """This function returns value of product's member price based on product id.
38 return {'value': {'member_price': False}}
39 return {'value': {'member_price': self.pool.get('product.product').price_get(cr, uid, [product_id])[product_id]}}
41 def membership_invoice(self, cr, uid, ids, context=None):
42 mod_obj = self.pool.get('ir.model.data')
43 partner_obj = self.pool.get('res.partner')
47 data = self.browse(cr, uid, ids, context=context)
51 'membership_product_id': data.product_id.id,
52 'amount': data.member_price
54 invoice_list = partner_obj.create_membership_invoice(cr, uid, context.get('active_ids', []), datas=datas, context=context)
57 search_view_id = mod_obj.get_object_reference(cr, uid, 'account', 'view_account_invoice_filter')[1]
59 search_view_id = False
61 form_view_id = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form')[1]
66 'domain': [('id', 'in', invoice_list)],
67 'name': 'Membership Invoices',
69 'view_mode': 'tree,form',
70 'res_model': 'account.invoice',
71 'type': 'ir.actions.act_window',
72 'views': [(False, 'tree'), (form_view_id, 'form')],
73 'search_view_id': search_view_id,
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: