diff --git a/golem_resource_account/models/__init__.py b/golem_resource_account/models/__init__.py index 15dcb5c..aaac7ae 100644 --- a/golem_resource_account/models/__init__.py +++ b/golem_resource_account/models/__init__.py @@ -17,4 +17,4 @@ # along with this program. If not, see . -from . import golem_resource_reservation +from . import golem_resource_reservation, account_invoice diff --git a/golem_resource_account/models/account_invoice.py b/golem_resource_account/models/account_invoice.py new file mode 100644 index 0000000..35f530c --- /dev/null +++ b/golem_resource_account/models/account_invoice.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# 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 . + +""" GOLEM Resource Reservation Adaptation""" + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class AccountInvoice(models.Model): + """ Account Invoice """ + _inherit = 'account.invoice' + + @api.multi + def add_to_invoice(self): + """Add reservation to existing invoice """ + for invoice in self: + reservation_id = self._context.get('reservation_id') + reservation = self.env['golem.resource.reservation'].browse(reservation_id) + reservation.create_invoice_line(invoice) diff --git a/golem_resource_account/models/golem_resource_reservation.py b/golem_resource_account/models/golem_resource_reservation.py index 3704cb0..1067bf1 100644 --- a/golem_resource_account/models/golem_resource_reservation.py +++ b/golem_resource_account/models/golem_resource_reservation.py @@ -122,14 +122,20 @@ class GolemResourceReservation(models.Model): """ Add reservation to existing invoice""" for reservation in self: partner = reservation.partner_id - invoice_list = self.env['account.invoice'].search([('partner_id', '=', partner.id), - ('state', '=', 'draft')]) + domain = [('partner_id', '=', partner.id), + ('state', '=', 'draft')] + invoice_list = self.env['account.invoice'].search(domain) #test if none - invoice_ids = invoice_list.mapped('id') - return {'name' : ("partner's invoice list"), - 'type' : 'ir.actions.act_window', - 'res_model' : 'golem.reservation.add.to.invoice.wizard', - 'context': {'default_invoice_ids': invoice_ids}, - 'view_mode': 'form', - 'flags': {'initial_mode': 'view'}, - 'target': 'new'} + if invoice_list: + invoice_ids = invoice_list.mapped('id') + return {'name' : ("partner's invoice list"), + 'type' : 'ir.actions.act_window', + 'res_model' : 'golem.reservation.add.to.invoice.wizard', + 'context': {'default_invoice_ids': invoice_ids, + 'default_reservation_id': reservation.id}, + 'view_mode': 'form', + 'flags': {'initial_mode': 'view'}, + 'target': 'new'} + else: + raise ValidationError(_('There is no existing invoice for the current client, ' + 'please create new one to invoice this reservation')) diff --git a/golem_resource_account/wizard/golem_reservation_add_to_invoice.py b/golem_resource_account/wizard/golem_reservation_add_to_invoice.py index 635d2fc..aaf5111 100644 --- a/golem_resource_account/wizard/golem_reservation_add_to_invoice.py +++ b/golem_resource_account/wizard/golem_reservation_add_to_invoice.py @@ -25,9 +25,14 @@ class GolemReservationAddToInvoiceWizard(models.TransientModel): """GOLEM Resrvation Add to Invoice Wizard """ _name = 'golem.reservation.add.to.invoice.wizard' - state = fields.Selection([('init', 'Init'), ('final', 'Final')], - default='init') + #state = fields.Selection([('init', 'Init'), ('final', 'Final')], + # default='init') invoice_ids = fields.Many2many('account.invoice', string="Partner invoice list") + reservation_id = fields.Many2one('golem.resource.reservation') + + @api.multi + def add(self): + print '__________________hjt______________________' """keyword = fields.Char(required=True) member_ids = fields.Many2many('golem.member', string='Members') diff --git a/golem_resource_account/wizard/golem_reservation_add_to_invoice_views.xml b/golem_resource_account/wizard/golem_reservation_add_to_invoice_views.xml index 4b78b01..cbf168c 100644 --- a/golem_resource_account/wizard/golem_reservation_add_to_invoice_views.xml +++ b/golem_resource_account/wizard/golem_reservation_add_to_invoice_views.xml @@ -19,67 +19,27 @@ along with this program. If not, see . - - GOLEM Member Precreation Search Form + + GOLEM Reservation Add to invoice Form golem.reservation.add.to.invoice.wizard
- - - - -
- - - +