diff --git a/golem_resource_account/__manifest__.py b/golem_resource_account/__manifest__.py index 7e36e7f..3560e1b 100644 --- a/golem_resource_account/__manifest__.py +++ b/golem_resource_account/__manifest__.py @@ -20,7 +20,7 @@ 'name': 'GOLEM resources invoicing', 'summary': 'GOLEM resources invoicing', 'description': ''' GOLEM resources invoicing ''', - 'version': '10.0.0.1.4', + 'version': '10.0.0.2.0', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_resource_account/models/account_invoice.py b/golem_resource_account/models/account_invoice.py index 35f530c..e0360f0 100644 --- a/golem_resource_account/models/account_invoice.py +++ b/golem_resource_account/models/account_invoice.py @@ -18,7 +18,7 @@ """ GOLEM Resource Reservation Adaptation""" -from odoo import models, fields, api, _ +from odoo import models, api, _ from odoo.exceptions import ValidationError @@ -31,5 +31,12 @@ class AccountInvoice(models.Model): """Add reservation to existing invoice """ for invoice in self: reservation_id = self._context.get('reservation_id') + if not reservation_id: + raise ValidationError(_('There is no reservation passed through ' + 'context. Please contact your administrator.')) reservation = self.env['golem.resource.reservation'].browse(reservation_id) + if not reservation: + raise ValidationError(_('No reservation has been found with {} ' + 'reservation ID. Please contact your ' + 'administrator.'.format(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 1067bf1..308f680 100644 --- a/golem_resource_account/models/golem_resource_reservation.py +++ b/golem_resource_account/models/golem_resource_reservation.py @@ -124,18 +124,17 @@ class GolemResourceReservation(models.Model): partner = reservation.partner_id domain = [('partner_id', '=', partner.id), ('state', '=', 'draft')] - invoice_list = self.env['account.invoice'].search(domain) - #test if none - if invoice_list: - invoice_ids = invoice_list.mapped('id') - return {'name' : ("partner's invoice list"), + invoice_ids = self.env['account.invoice'].search(domain) + if invoice_ids: + 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, + 'context': {'default_invoice_ids': invoice_ids.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')) + 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 aaf5111..8c993ca 100644 --- a/golem_resource_account/wizard/golem_reservation_add_to_invoice.py +++ b/golem_resource_account/wizard/golem_reservation_add_to_invoice.py @@ -17,33 +17,23 @@ # along with this program. If not, see . """ GOLEM Reservation's Adding to invoice wizard""" -import logging from odoo import models, fields, api, _ -_LOGGER = logging.getLogger(__name__) class GolemReservationAddToInvoiceWizard(models.TransientModel): - """GOLEM Resrvation Add to Invoice Wizard """ + """GOLEM Reservation Add to Invoice Wizard """ _name = 'golem.reservation.add.to.invoice.wizard' - #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) + keyword = fields.Char(required=True) member_ids = fields.Many2many('golem.member', string='Members') contact_ids = fields.Many2many('res.partner', string='Contacts') @api.multi def action(self): - + """ Returns action window with current model and instance """ self.ensure_one() - _LOGGER.warning(self[0].contact_ids) - _LOGGER.warning(self[0].member_ids) return {'name' : _('Search results'), 'type' : 'ir.actions.act_window', 'res_model' : self._name, @@ -51,23 +41,14 @@ class GolemReservationAddToInvoiceWizard(models.TransientModel): 'view_mode': 'form', 'target': 'new'} - @api.multi - def new_search(self): - - self[0].write({'member_ids': [(6, False, [])], - 'contact_ids': [(6, False, [])], - 'state': 'init'}) - return self[0].action() - @api.multi def search_partners(self): - + """ Searches partners in name, email """ self.ensure_one() domain = ['|', ('name', 'ilike', self[0].keyword), ('email', 'ilike', self[0].keyword)] partner_ids = self.env['res.partner'].search(domain) self[0].write({'contact_ids': [(6, False, partner_ids.ids)], - 'member_ids': [(6, False, partner_ids.mapped('member_id').ids)], - 'state': 'final'}) - return self[0].action()""" + 'member_ids': [(6, False, partner_ids.mapped('member_id').ids)]}) + return self[0].action() 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 cbf168c..cec5717 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,20 +19,19 @@ along with this program. If not, see . - + GOLEM Reservation Add to invoice Form golem.reservation.add.to.invoice.wizard
- + - -