+member id
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Mon, 24 Sep 2012 05:40:37 +0000 (07:40 +0200)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Mon, 24 Sep 2012 05:40:37 +0000 (07:40 +0200)
__init__.py [new file with mode: 0644]
__openerp__.py [new file with mode: 0644]
data/membership_sequence.xml [new file with mode: 0644]
remembership.py [new file with mode: 0644]
view/partner.xml [new file with mode: 0644]

diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..a7284a9
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    ReMembership module for OpenERP, Other membership module for member management.
+#    Copyright (C) 2012 L'Heureux Cyclage (<http://www.heureux-cyclage.org>) Ludovic CHEVALIER
+#
+#    This file is a part of ReMembership
+#
+#    ReMembership 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.
+#
+#    ReMembership 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/>.
+#
+##############################################################################
+
+import remembership
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/__openerp__.py b/__openerp__.py
new file mode 100644 (file)
index 0000000..6e9738d
--- /dev/null
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    ReMembership module for OpenERP, Other membership module for member management.
+#    Copyright (C) 2012 L'Heureux Cyclage (<http://www.heureux-cyclage.org>) Ludovic CHEVALIER
+#
+#    This file is a part of ReMembership
+#
+#    ReMembership 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.
+#
+#    ReMembership 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/>.
+#
+##############################################################################
+
+{
+    'name': 'ReMembership',
+    'version': '0.1',
+    'category': 'Generic Modules/Association',
+    'description': """
+    This module overload official OpenERP membership module for adding some functionnalities that could be useful.
+    """,
+    'author': 'L\'Heureux Cyclage - LHC',
+    'depends': ['membership'],
+    'init_xml': [],
+    'data': [
+        'data/membership_sequence.xml',
+        'view/partner.xml',
+    ],
+    'update_xml': [],
+    'demo_xml': [],
+    'test': [],
+    'installable': True,
+    'active': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/data/membership_sequence.xml b/data/membership_sequence.xml
new file mode 100644 (file)
index 0000000..ffc074d
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data noupdate="1">
+        <!--    Member identifier sequence  -->
+        <record id="member_ident_sequence_type" model="ir.sequence.type">
+            <field name="name">Member identifier</field>
+            <field name="code">member_ident</field>
+        </record>
+        <record id="member_ident_sequence" model="ir.sequence">
+            <field name="name">Member identifier</field>
+            <field name="code">member_ident</field>
+            <field name="padding">0</field>
+            <field name="number_next">1</field>
+            <field name="number_increment">1</field>
+        </record>
+    </data>
+</openerp>
diff --git a/remembership.py b/remembership.py
new file mode 100644 (file)
index 0000000..2004770
--- /dev/null
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Remembership module for OpenERP, Overload membership module
+#    Copyright (C) 2012 L'Heureux Cyclage (<http://www.heureux-cyclage.org>) Ludovic CHEVALIER
+#
+#    This file is a part of Remembership
+#
+#    Remembership 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.
+#
+#    Remembership 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 osv import osv
+from osv import fields
+
+class Partner(osv.osv):
+    _inherit = 'res.partner'
+
+    _columns = {
+        'member_ident': fields.char('Member identifier', size=64, readonly=True),
+    }
+
+    def create_membership_invoice(self, cr, uid, ids, product_id=None, datas=None, context=None):
+        """ Create Customer Invoice of Membership for partners.
+        @param datas: datas has dictionary value which consist Id of Membership product and Cost Amount of Membership.
+                      datas = {'membership_product_id': None, 'amount': None}
+        """
+        invoice_obj = self.pool.get('account.invoice')
+        invoice_line_obj = self.pool.get('account.invoice.line')
+        invoice_tax_obj = self.pool.get('account.invoice.tax')
+        product_id = product_id or datas.get('membership_product_id', False)
+        amount = datas.get('amount', 0.0)
+        invoice_list = []
+        if type(ids) in (int, long,):
+            ids = [ids]
+        for partner in self.browse(cr, uid, ids, context=context):
+            account_id = partner.property_account_receivable and partner.property_account_receivable.id or False
+            fpos_id = partner.property_account_position and partner.property_account_position.id or False
+            addr = self.address_get(cr, uid, [partner.id], ['invoice'])
+            if partner.free_member:
+                raise osv.except_osv(_('Error !'),
+                        _("Partner is a free Member."))
+            if not addr.get('invoice', False):
+                raise osv.except_osv(_('Error !'),
+                        _("Partner doesn't have an address to make the invoice."))
+            quantity = 1
+            line_value =  {
+                'product_id': product_id,
+            }
+
+            line_dict = invoice_line_obj.product_id_change(cr, uid, {},
+                            product_id, False, quantity, '', 'out_invoice', partner.id, fpos_id, price_unit=amount, context=context)
+            line_value.update(line_dict['value'])
+            line_value['price_unit'] = amount
+            if line_value.get('invoice_line_tax_id', False):
+                tax_tab = [(6, 0, line_value['invoice_line_tax_id'])]
+                line_value['invoice_line_tax_id'] = tax_tab
+
+            invoice_id = invoice_obj.create(cr, uid, {
+                'partner_id': partner.id,
+                'address_invoice_id': addr.get('invoice', False),
+                'account_id': account_id,
+                'fiscal_position': fpos_id or False
+                }, context=context)
+            line_value['invoice_id'] = invoice_id
+            invoice_line_id = invoice_line_obj.create(cr, uid, line_value, context=context)
+            invoice_obj.write(cr, uid, invoice_id, {'invoice_line': [(6, 0, [invoice_line_id])]}, context=context)
+            invoice_list.append(invoice_id)
+            if line_value['invoice_line_tax_id']:
+                tax_value = invoice_tax_obj.compute(cr, uid, invoice_id).values()
+                for tax in tax_value:
+                       invoice_tax_obj.create(cr, uid, tax, context=context)
+            if partner.member_ident:
+                mbr_id = partner.member_ident
+            else:
+                mbr_id = self.pool.get('ir.sequence').get(cr, uid, 'member_ident')
+        #recompute the membership_state of those partners
+        self.pool.get('res.partner').write(cr, uid, ids, {'member_ident': mbr_id})
+        return invoice_list
+
+Partner()
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/view/partner.xml b/view/partner.xml
new file mode 100644 (file)
index 0000000..e413865
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="view_partner_form" model="ir.ui.view">
+            <field name="name">res.partner.form - Remembership</field>
+            <field name="model">res.partner</field>
+            <field name="type">form</field>
+            <field name="inherit_id" ref="membership.view_partner_form"/>
+            <field name="arch" type="xml">
+                <notebook colspan="4" position="inside">
+                    <page string="Member ID">
+                        <field name="member_ident"/>
+                    </page>
+                </notebook>
+            </field>
+        </record>
+    </data>
+</openerp>