[Group] member_ident ok for associate members
[burette/remembership.git] / remembership.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Remembership module for OpenERP, Overload membership module
5 # Copyright (C) 2012 L'Heureux Cyclage (<http://www.heureux-cyclage.org>) Ludovic CHEVALIER
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 osv import osv
25 from osv import fields
26
27
28 class Partner(osv.osv):
29 _inherit = 'res.partner'
30
31 _columns = {
32 'member_ident': fields.char('Member identifier', size=64),
33 }
34
35 _sql_constraints = [
36 ('member_ident_uniq', 'unique(member_ident, company_id)', 'The member identifier must be unique !'),
37 ]
38
39 Partner()
40
41
42 class Product(osv.osv):
43 _inherit = 'product.product'
44
45 _columns = {
46 'membership_grouped': fields.boolean('Grouped membership product', help='Check if it\'s a grouped membership product.'),
47 'membership_date2date': fields.boolean('Date to date membership product', help='Check if it\'s a date to date membership product.'),
48 }
49
50 Product()
51
52
53 class account_invoice_line(osv.osv):
54 _inherit = 'account.invoice.line'
55
56 def create(self, cr, uid, vals, context=None):
57 res = super(account_invoice_line, self).create(cr, uid, vals, context=context)
58 line = self.browse(cr, uid, res, context=context)
59
60 if line.invoice_id.type == 'out_invoice' and line.product_id and line.product_id.membership:
61 partners = [line.invoice_id.partner_id]
62 partners.extend(line.invoice_id.partner_id.associate_members)
63 for i in partners:
64 if not i.member_ident:
65 mbr_id = self.pool.get('ir.sequence').get(cr, uid, 'member_ident')
66 self.pool.get('res.partner').write(cr, uid, i.id, {'member_ident': mbr_id})
67 return res
68
69 account_invoice_line()
70
71
72 class pos_make_payment(osv.osv_memory):
73 _inherit = 'pos.make.payment'
74
75 def check(self, cr, uid, ids, context=None):
76 """
77 Auto invoice orders. Temporarly solution before make partner members just with orders, without invoice.
78 """
79 res = super(pos_make_payment, self).check(cr, uid, ids, context=context)
80
81 order_obj = self.pool.get('pos.order')
82 order_obj.action_invoice(cr, uid, ids, context=context)
83
84 return res
85
86 pos_make_payment()
87
88 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: