From afddb3c58dd2bd8f82ad983c2ce2f6139973a0d9 Mon Sep 17 00:00:00 2001 From: youssef Date: Mon, 8 Oct 2018 14:37:14 +0100 Subject: [PATCH] Add partner_ids to account_invoice --- golem_member_minor/__manifest__.py | 3 +- golem_member_minor/models/__init__.py | 2 +- golem_member_minor/models/account_invoice.py | 27 +++++++++++++ golem_member_minor/models/golem_membership.py | 15 ++++++++ golem_member_minor/views/account_invoice.xml | 38 +++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 golem_member_minor/models/account_invoice.py create mode 100644 golem_member_minor/views/account_invoice.xml diff --git a/golem_member_minor/__manifest__.py b/golem_member_minor/__manifest__.py index d2830d9..62874fb 100644 --- a/golem_member_minor/__manifest__.py +++ b/golem_member_minor/__manifest__.py @@ -27,5 +27,6 @@ 'installable': True, 'depends': ['golem_member'], 'data': ['views/golem_member_views.xml', - 'views/golem_membership_invoice.xml'] + 'views/golem_membership_invoice.xml', + 'views/account_invoice.xml'] } diff --git a/golem_member_minor/models/__init__.py b/golem_member_minor/models/__init__.py index b559e11..22440e6 100644 --- a/golem_member_minor/models/__init__.py +++ b/golem_member_minor/models/__init__.py @@ -16,4 +16,4 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from . import golem_member, golem_membership +from . import golem_member, golem_membership, account_invoice diff --git a/golem_member_minor/models/account_invoice.py b/golem_member_minor/models/account_invoice.py new file mode 100644 index 0000000..69b4417 --- /dev/null +++ b/golem_member_minor/models/account_invoice.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# Copyright 2018 Youssef El Ouahby +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" Account Invoice adaptations """ + +from odoo import models, fields, api + +class AccountInvoice(models.Model): + """ Account Invoice adaptations """ + _inherit = 'account.invoice' + + partner_ids = fields.Many2many('res.partner') diff --git a/golem_member_minor/models/golem_membership.py b/golem_member_minor/models/golem_membership.py index 2b736ae..aa5b808 100644 --- a/golem_member_minor/models/golem_membership.py +++ b/golem_member_minor/models/golem_membership.py @@ -39,3 +39,18 @@ class GolemMembershipInvoice(models.TransientModel): [('id', 'in', record.src_member_id.legal_guardian_ids.ids)] } } + @api.multi + def membership_invoice(self): + """ Create invoice and redirect to partner invoice list """ + self.ensure_one() + res = super(GolemMembershipInvoice, self).membership_invoice() + if self.src_member_id and self.src_member_id.is_minor: + invoice_id = (res['domain'][0][2] if + res['domain'][0][2] else False) + if invoice_id: + self.env['account.invoice'].browse(invoice_id).partner_ids = [ + (6, 0, [self.partner_id.id, + self.src_member_id.partner_id.id])] + self.src_member_id.partner_id.membership_state = self.partner_id.membership_state + self.partner_id.membership_state = 'none' + return res diff --git a/golem_member_minor/views/account_invoice.xml b/golem_member_minor/views/account_invoice.xml new file mode 100644 index 0000000..b441ed1 --- /dev/null +++ b/golem_member_minor/views/account_invoice.xml @@ -0,0 +1,38 @@ + + + + + + + + + account.invoice.form.iherited.member.minor + account.invoice + + + + + + + + + +