From: Ludovic CHEVALIER Date: Tue, 29 Dec 2015 17:01:54 +0000 (+0100) Subject: [MODULE] +last membership product field in res_partner object X-Git-Url: https://git.cyclocoop.org/?p=burette%2Fetudesetchantiersidf.git;a=commitdiff_plain;h=27da42444afa9508c4b12318645f651440a1d0d7 [MODULE] +last membership product field in res_partner object --- diff --git a/__init__.py b/__init__.py index f6eefa1..a6f4357 100644 --- a/__init__.py +++ b/__init__.py @@ -8,10 +8,10 @@ # # This file is a part of etudesetchantiersidf # -# etudesetchantiersidf is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# etudesetchantiersidf is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. # # etudesetchantiersidf is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,4 +23,7 @@ # ############################################################################## +import etudesetchantiersidf +import account + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/etudesetchantiersidf.py b/etudesetchantiersidf.py new file mode 100644 index 0000000..1f40102 --- /dev/null +++ b/etudesetchantiersidf.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# etudesetchantiersidf module for OpenERP, Custom module for Étude et +# Chantiers île-de-France +# Copyright (C) 2014-2015 etudesetchantiersidf +# () +# +# This file is a part of etudesetchantiersidf +# +# etudesetchantiersidf is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# etudesetchantiersidf is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import osv +from openerp.osv import orm +from openerp.osv import fields + + +class Partner(osv.osv): + '''Partner''' + _inherit = 'res.partner' + ''' + def _get_invoice_partner(self, cr, uid, ids, context=None): + res = super(Partner, self)._get_invoice_partner(cr, uid, ids, context=context) + return res + + def _get_partner_id(self, cr, uid, ids, context=None): + res = super(Partner, self)._get_partner_id(cr, uid, ids, context=context) + return res + ''' + + def _get_last_mb_product(self, cr, uid, ids, name, args, context=None): + """Return the last membership product buy by a user""" + name=name[0] + res ={} + member_line_obj = self.pool.get('membership.membership_line') + for partner in self.browse(cr, uid, ids, context=context): + partner_id = partner.id + line_id = member_line_obj.search(cr, uid, [ + ('partner', '=', partner_id), + ('date_cancel', '=', False) + ], limit=1, order='date_from', context=context) + if line_id: + product_id = member_line_obj.read(cr, uid, line_id[0], [name], context=context)[name][0] + res[partner.id] = {name: product_id} + return res + + + _columns = { + 'membership_id': fields.function( + _get_last_mb_product, multi='membership_id', + string='Last membership product', + type='many2one', + obj='product.product', + store=True, + ), + } +''' +store = { + 'account.invoice': (_get_invoice_partner, ['state'], 10), + 'membership.membership_line': (_get_partner_id, ['state'], 10, ) + } +''' + +Partner() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/view/bikecoop.xml b/view/bikecoop.xml index fc335a2..ee9e9d7 100644 --- a/view/bikecoop.xml +++ b/view/bikecoop.xml @@ -16,6 +16,9 @@ res.partner + + +