[PYTHON] ~fix update_membership_state function
[burette/remembership.git] / wizard / remembership_invoice.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Remembership module for OpenERP, Membership module enhancement and bug fixes
5 # Copyright (C) 2012-2018 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
6 #
7 # This file is a part of Remembership
8 #
9 # Remembership is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Remembership is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 from openerp.osv import osv
25 from openerp.osv import fields
26 from datetime import datetime
27
28
29 class membership_invoice(osv.osv):
30 _inherit = 'membership.invoice'
31
32 _columns = {
33 'date_from': fields.date('This membership start date'),
34 'is_date2date': fields.boolean('This membership product is date to date.', readonly=True),
35 }
36
37 _defaults = {
38 'date_from': datetime.today().strftime('%Y-%m-%d'),
39 }
40
41 def onchange_product(self, cr, uid, ids, product_id=False):
42 res = super(membership_invoice, self).onchange_product(cr, uid, ids, product_id)
43 if product_id:
44 res['value']['is_date2date'] = self.pool.get('product.product').browse(cr, uid, [product_id], context=None)[0].membership_date2date
45 else:
46 res['value']['is_date2date'] = False
47
48 return res
49
50 def membership_invoice(self, cr, uid, ids, context=None):
51 """NOTE: Copy of orginial function for overwrite it by adding
52 date_from value for date to date membership products. Keep an eye of it
53 for taking advantage of its enhancements (2013-01-11)"""
54 mod_obj = self.pool.get('ir.model.data')
55 partner_obj = self.pool.get('res.partner')
56 datas = {}
57 if context is None:
58 context = {}
59 data = self.browse(cr, uid, ids, context=context)
60 if data:
61 data = data[0]
62 datas = {
63 'membership_product_id': data.product_id.id,
64 'amount': data.member_price,
65 'date_from': data.date_from
66 }
67 invoice_list = partner_obj.create_membership_invoice(cr, uid, context.get('active_ids', []), datas=datas, context=context)
68
69 res = mod_obj.get_object_reference(cr, uid, 'account', 'view_account_invoice_filter')
70
71 return {
72 'domain': [('id', 'in', invoice_list)],
73 'name': 'Membership Invoices',
74 'view_type': 'form',
75 'view_mode': 'tree,form',
76 'res_model': 'account.invoice',
77 'type': 'ir.actions.act_window',
78 'search_view_id': res and res[1] or False
79 }
80
81 membership_invoice()