2018-10-08 03:48:49 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
|
|
|
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
""" GOLEM Membership """
|
|
|
|
|
|
|
|
from odoo import models, fields, api
|
|
|
|
|
|
|
|
|
|
|
|
class GolemMembershipInvoice(models.TransientModel):
|
|
|
|
""" Membership invoicing """
|
|
|
|
_inherit = 'golem.membership.invoice'
|
|
|
|
|
|
|
|
|
2018-10-25 17:55:49 +02:00
|
|
|
src_member_id = fields.Many2one('golem.member', ondelete='cascade')
|
|
|
|
src_member_minor = fields.Boolean(related='src_member_id.is_minor')
|
2018-10-08 03:48:49 +02:00
|
|
|
|
|
|
|
@api.onchange('src_member_id')
|
|
|
|
def onchange_member(self):
|
|
|
|
""" Set partner domain if src_member_id is filled """
|
2018-10-25 17:55:49 +02:00
|
|
|
self.ensure_one()
|
2018-10-29 23:53:09 +01:00
|
|
|
record = self[0]
|
2018-11-01 19:12:13 +01:00
|
|
|
domain = ([('id', 'in',
|
|
|
|
record.src_member_id.mapped('legal_guardian_ids.legal_guardian_id').ids)]
|
|
|
|
if record.src_member_id.is_minor else [])
|
|
|
|
return {'domain': {'partner_id': domain}}
|
2018-10-25 17:55:49 +02:00
|
|
|
|
2018-10-08 15:37:14 +02:00
|
|
|
@api.multi
|
|
|
|
def membership_invoice(self):
|
2018-10-25 17:55:49 +02:00
|
|
|
""" Add partners concerned to invoice and move membership from legal
|
|
|
|
guardian to minor """
|
2018-10-08 15:37:14 +02:00
|
|
|
self.ensure_one()
|
2018-10-09 15:36:24 +02:00
|
|
|
record = self[0]
|
2018-10-08 15:37:14 +02:00
|
|
|
res = super(GolemMembershipInvoice, self).membership_invoice()
|
2018-10-25 17:55:49 +02:00
|
|
|
if record.src_member_id.is_minor:
|
|
|
|
# Getting invoice IDS from action's domain already declared
|
|
|
|
invoice_ids = (res['domain'][0][2] or False)
|
|
|
|
if invoice_ids: # As invoice_ids is a Python list, empty or not
|
|
|
|
invoice = self.env['account.invoice'].browse(invoice_ids)[-1]
|
2018-10-09 15:36:24 +02:00
|
|
|
invoice.is_minor_invoice = True
|
|
|
|
invoice.partner_ids = [(6, 0, [record.partner_id.id,
|
|
|
|
record.src_member_id.partner_id.id])]
|
|
|
|
# move the created membership from legal guardian to the minor
|
|
|
|
membership_line = record.partner_id.member_lines[0]
|
|
|
|
membership_line.copy({'partner': record.src_member_id.partner_id.id})
|
|
|
|
membership_line.unlink()
|
2018-10-08 15:37:14 +02:00
|
|
|
return res
|