[MODULE] +last membership product field in res_partner object
authorLudovic CHEVALIER <ludovic@beurresarrasin.net>
Tue, 29 Dec 2015 17:01:54 +0000 (18:01 +0100)
committerLudovic CHEVALIER <ludovic@beurresarrasin.net>
Tue, 29 Dec 2015 17:01:54 +0000 (18:01 +0100)
__init__.py
etudesetchantiersidf.py [new file with mode: 0644]
view/bikecoop.xml

index f6eefa1..a6f4357 100644 (file)
@@ -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 (file)
index 0000000..1f40102
--- /dev/null
@@ -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
+#    (<http://etudesetchantiersiledefrance.unarec.org/>)
+#
+#    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 <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+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:
index fc335a2..ee9e9d7 100644 (file)
@@ -16,6 +16,9 @@
             <field name="model">res.partner</field>
             <field name="inherit_id" ref="bikecoop_l10n_fr.view_bikecoop_l10n_fr_members_form"/>
             <field name="arch" type="xml">
+                <xpath expr="//field[@name='membership_state']" position="after">
+                    <field name="membership_id"/>
+                </xpath>
                 <xpath expr="//field[@name='occupation_id']" position="replace">
                     <field name="occupation_id"/>
                 </xpath>