GOLEM/golem_family_membership/wizard/golem_membership_invoice.py

65 lines
2.7 KiB
Python
Raw Normal View History

2018-08-13 17:47:49 +02:00
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 Fabien Bourgeois <fabien@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 Invoice Adaptations"""
2018-08-13 18:09:27 +02:00
from odoo import models, fields, api
2018-08-13 17:47:49 +02:00
class GolemMembershipInvoice(models.TransientModel):
""" GOLEM Membership Invoice adaptations """
_inherit = 'golem.membership.invoice'
family_id = fields.Many2one('golem.family', required=True)
2018-08-13 17:47:49 +02:00
members_ids = fields.Many2many('res.partner')
on_the_name_of = fields.Many2one('res.partner', domain="[('id', '=', members_ids[0][2])]")
@api.onchange('family_id')
def onchange_family(self):
""" Fill members_ids """
2018-08-13 17:47:49 +02:00
for record in self:
record.members_ids = [(6, False, record.family_id.members_ids.ids)]
2018-08-13 17:47:49 +02:00
@api.multi
def membership_family_invoice(self):
""" Create family membership """
self.ensure_one()
record = self[0]
datas = {'membership_product_id': record.product_id.id,
'amount': record.member_price}
2018-08-13 17:47:49 +02:00
invoice_list = record.on_the_name_of.create_membership_invoice(datas=datas)
datas = {'membership_product_id': record.product_id.id,
'amount': 0.0}
2018-08-13 17:47:49 +02:00
gen = (member for member in record.members_ids if member != record.on_the_name_of)
for member in gen:
2018-08-13 18:09:27 +02:00
id_membership = member.create_membership_invoice(datas=datas)
self.env['account.invoice'].browse(id_membership).action_invoice_open()
invoice_list += id_membership
2018-08-13 17:47:49 +02:00
search_view_id = self.env.ref('account.view_account_invoice_filter')
form_view_id = self.env.ref('account.invoice_form')
return {
'domain': [('id', 'in', invoice_list)],
'name': 'Membership Invoices',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'type': 'ir.actions.act_window',
'views': [(False, 'tree'), (form_view_id.id, 'form')],
'search_view_id': search_view_id.id
}