From: Ludovic CHEVALIER Date: Mon, 24 Sep 2012 05:40:37 +0000 (+0200) Subject: +member id X-Git-Url: https://git.heureux-cyclage.org/?p=burette%2Fremembership.git;a=commitdiff_plain;h=03e884c839ad12ec33540cffb07217b0d762e2a7 +member id --- 03e884c839ad12ec33540cffb07217b0d762e2a7 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..a7284a9 --- /dev/null +++ b/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# ReMembership module for OpenERP, Other membership module for member management. +# Copyright (C) 2012 L'Heureux Cyclage () 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 . +# +############################################################################## + +import remembership + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/__openerp__.py b/__openerp__.py new file mode 100644 index 0000000..6e9738d --- /dev/null +++ b/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# ReMembership module for OpenERP, Other membership module for member management. +# Copyright (C) 2012 L'Heureux Cyclage () 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 . +# +############################################################################## + +{ + '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 index 0000000..ffc074d --- /dev/null +++ b/data/membership_sequence.xml @@ -0,0 +1,17 @@ + + + + + + Member identifier + member_ident + + + Member identifier + member_ident + 0 + 1 + 1 + + + diff --git a/remembership.py b/remembership.py new file mode 100644 index 0000000..2004770 --- /dev/null +++ b/remembership.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Remembership module for OpenERP, Overload membership module +# Copyright (C) 2012 L'Heureux Cyclage () 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 . +# +############################################################################## + +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 index 0000000..e413865 --- /dev/null +++ b/view/partner.xml @@ -0,0 +1,18 @@ + + + + + res.partner.form - Remembership + res.partner + form + + + + + + + + + + +