1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # etudesetchantiersidf module for OpenERP, Custom module for Étude et
5 # Chantiers île-de-France
6 # Copyright (C) 2014-2023 etudesetchantiersidf
7 # (<http://etudesetchantiersiledefrance.unarec.org/>)
9 # This file is a part of etudesetchantiersidf
11 # etudesetchantiersidf is free software: you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as published
13 # by the Free Software Foundation, either version 3 of the License, or (at
14 # your option) any later version.
16 # etudesetchantiersidf is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 ##############################################################################
26 from openerp
.osv
import osv
27 from openerp
.osv
import orm
28 from openerp
.osv
import fields
31 class Partner(osv
.osv
):
33 _inherit
= 'res.partner'
35 def _get_partner_id(self
, cr
, uid
, ids
, context
=None):
36 return super(Partner
, self
.pool
['res.partner'])._get
_partner
_id
(cr
, uid
, ids
, context
=context
)
38 def _get_invoice_partner(self
, cr
, uid
, ids
, context
=None):
39 return super(Partner
, self
.pool
['res.partner'])._get
_invoice
_partner
(cr
, uid
, ids
, context
=context
)
41 def _get_order_partner(self
, cr
, uid
, ids
, context
=None):
42 return super(Partner
, self
.pool
['res.partner'])._get
_order
_partner
(cr
, uid
, ids
, context
=context
)
44 def _get_last_mb_product(self
, cr
, uid
, ids
, name
, args
, context
=None):
45 """Return the last membership product buy by a user"""
48 member_line_obj
= self
.pool
.get('membership.membership_line')
49 for partner
in self
.browse(cr
, uid
, ids
, context
=context
):
50 partner_id
= partner
.id
51 line_id
= member_line_obj
.search(cr
, uid
, [
52 ('partner', '=', partner_id
),
53 ('date_cancel', '=', False)
54 ], limit
=1, order
='date_from desc', context
=context
)
56 product_id
= member_line_obj
.read(cr
, uid
, line_id
[0], [name
], context
=context
)[name
][0]
57 res
[partner
.id] = {name
: product_id
}
59 res
[partner
.id] = {name
: None} #Not needed in recent version of OpenERP7 (greater than 2016-01-01)
63 'membership_id': fields
.function(
64 _get_last_mb_product
, multi
='membership_id',
65 string
='Last membership product',
67 obj
='product.product',
69 'account.invoice': (_get_invoice_partner
, ['state'], 11),
70 'pos.order': (_get_order_partner
, ['state', 'partner_id'], 11),
71 'membership.membership_line': (_get_partner_id
, ['state'], 10),
72 'res.partner': (lambda self
, cr
, uid
, ids
, c
={}: ids
, ['free_member'], 10)
75 'newsletter': fields
.boolean('Want to subsribe to the newsletter?'),
79 'newsletter': lambda *a
: True,
82 def _check_email(self
, cr
, uid
, ids
, context
=None):
83 #TODO : check condition and return boolean accordingly
86 for partner
in self
.browse(cr
, uid
, ids
, context
=context
):
87 if partner
.newsletter
and not partner
.email
:
92 (_check_email
, 'Error: you can\'t subscribe to the newsletter without email!', ['newsletter']),
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: