2018-03-16 16:04:33 +01: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 Reservation Invoice Wizard"""
|
|
|
|
|
2018-03-26 17:59:49 +02:00
|
|
|
from odoo import models, fields, api
|
2018-03-16 16:04:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GolemReservationInvoiceWizard(models.TransientModel):
|
|
|
|
""" GOLEM Resource Reservation Invoice Wizard """
|
|
|
|
_name = 'golem.reservation.invoice.wizard'
|
|
|
|
|
2018-03-26 16:22:57 +02:00
|
|
|
reservation_ids = fields.Many2many(
|
|
|
|
'golem.resource.reservation', required=True, string='Reservations to invoice',
|
|
|
|
default=lambda self: self._context.get('active_ids', []))
|
2018-03-16 16:04:33 +01:00
|
|
|
|
|
|
|
@api.multi
|
2018-03-26 17:09:23 +02:00
|
|
|
def create_invoice(self):
|
|
|
|
""" Invoice creation """
|
2018-03-16 16:04:33 +01:00
|
|
|
self.ensure_one()
|
|
|
|
|
2018-03-26 17:09:23 +02:00
|
|
|
self.reservation_ids.check_before_invoicing()
|
|
|
|
self.reservation_ids[0].create_invoice()
|
2018-03-26 17:21:21 +02:00
|
|
|
invoice_id = self.reservation_ids[0].invoice_id
|
2018-03-26 17:09:23 +02:00
|
|
|
if len(self.reservation_ids) > 1:
|
|
|
|
self.reservation_ids[1:].create_invoice_line(invoice_id)
|
2018-03-16 16:04:33 +01:00
|
|
|
|
2018-03-26 17:59:49 +02:00
|
|
|
if self._context.get('open_invoice', False):
|
|
|
|
return self.reservation_ids[0].show_invoice()
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|