[REF]GOLEM Resource Account : add to invoice refactoring / small enhancements

This commit is contained in:
Fabien BOURGEOIS 2018-04-16 17:55:02 +02:00
parent c446fccd03
commit 95cc14a4ee
5 changed files with 25 additions and 39 deletions

View File

@ -20,7 +20,7 @@
'name': 'GOLEM resources invoicing', 'name': 'GOLEM resources invoicing',
'summary': 'GOLEM resources invoicing', 'summary': 'GOLEM resources invoicing',
'description': ''' GOLEM resources invoicing ''', 'description': ''' GOLEM resources invoicing ''',
'version': '10.0.0.1.4', 'version': '10.0.0.2.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois', 'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@ -18,7 +18,7 @@
""" GOLEM Resource Reservation Adaptation""" """ GOLEM Resource Reservation Adaptation"""
from odoo import models, fields, api, _ from odoo import models, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
@ -31,5 +31,12 @@ class AccountInvoice(models.Model):
"""Add reservation to existing invoice """ """Add reservation to existing invoice """
for invoice in self: for invoice in self:
reservation_id = self._context.get('reservation_id') 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) 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) reservation.create_invoice_line(invoice)

View File

@ -124,18 +124,17 @@ class GolemResourceReservation(models.Model):
partner = reservation.partner_id partner = reservation.partner_id
domain = [('partner_id', '=', partner.id), domain = [('partner_id', '=', partner.id),
('state', '=', 'draft')] ('state', '=', 'draft')]
invoice_list = self.env['account.invoice'].search(domain) invoice_ids = self.env['account.invoice'].search(domain)
#test if none if invoice_ids:
if invoice_list: return {'name' : (_('Partner\'s invoice list')),
invoice_ids = invoice_list.mapped('id')
return {'name' : ("partner's invoice list"),
'type' : 'ir.actions.act_window', 'type' : 'ir.actions.act_window',
'res_model' : 'golem.reservation.add.to.invoice.wizard', '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}, 'default_reservation_id': reservation.id},
'view_mode': 'form', 'view_mode': 'form',
'flags': {'initial_mode': 'view'}, 'flags': {'initial_mode': 'view'},
'target': 'new'} 'target': 'new'}
else: else:
raise ValidationError(_('There is no existing invoice for the current client, ' raise ValidationError(_('There is no existing invoice for the '
'please create new one to invoice this reservation')) 'current client, please create new one '
'to invoice this reservation'))

View File

@ -17,33 +17,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" GOLEM Reservation's Adding to invoice wizard""" """ GOLEM Reservation's Adding to invoice wizard"""
import logging
from odoo import models, fields, api, _ from odoo import models, fields, api, _
_LOGGER = logging.getLogger(__name__)
class GolemReservationAddToInvoiceWizard(models.TransientModel): class GolemReservationAddToInvoiceWizard(models.TransientModel):
"""GOLEM Resrvation Add to Invoice Wizard """ """GOLEM Reservation Add to Invoice Wizard """
_name = '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") invoice_ids = fields.Many2many('account.invoice', string="Partner invoice list")
reservation_id = fields.Many2one('golem.resource.reservation') reservation_id = fields.Many2one('golem.resource.reservation')
@api.multi keyword = fields.Char(required=True)
def add(self):
print '__________________hjt______________________'
"""keyword = fields.Char(required=True)
member_ids = fields.Many2many('golem.member', string='Members') member_ids = fields.Many2many('golem.member', string='Members')
contact_ids = fields.Many2many('res.partner', string='Contacts') contact_ids = fields.Many2many('res.partner', string='Contacts')
@api.multi @api.multi
def action(self): def action(self):
""" Returns action window with current model and instance """
self.ensure_one() self.ensure_one()
_LOGGER.warning(self[0].contact_ids)
_LOGGER.warning(self[0].member_ids)
return {'name' : _('Search results'), return {'name' : _('Search results'),
'type' : 'ir.actions.act_window', 'type' : 'ir.actions.act_window',
'res_model' : self._name, 'res_model' : self._name,
@ -51,23 +41,14 @@ class GolemReservationAddToInvoiceWizard(models.TransientModel):
'view_mode': 'form', 'view_mode': 'form',
'target': 'new'} '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 @api.multi
def search_partners(self): def search_partners(self):
""" Searches partners in name, email """
self.ensure_one() self.ensure_one()
domain = ['|', domain = ['|',
('name', 'ilike', self[0].keyword), ('name', 'ilike', self[0].keyword),
('email', 'ilike', self[0].keyword)] ('email', 'ilike', self[0].keyword)]
partner_ids = self.env['res.partner'].search(domain) partner_ids = self.env['res.partner'].search(domain)
self[0].write({'contact_ids': [(6, False, partner_ids.ids)], self[0].write({'contact_ids': [(6, False, partner_ids.ids)],
'member_ids': [(6, False, partner_ids.mapped('member_id').ids)], 'member_ids': [(6, False, partner_ids.mapped('member_id').ids)]})
'state': 'final'}) return self[0].action()
return self[0].action()"""

View File

@ -19,20 +19,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<odoo> <odoo>
<data> <data>
<record model="ir.ui.view" id="golem_reservation_add_to_invoice_form"> <record id="golem_reservation_add_to_invoice_form" model="ir.ui.view">
<field name="name">GOLEM Reservation Add to invoice Form</field> <field name="name">GOLEM Reservation Add to invoice Form</field>
<field name="model">golem.reservation.add.to.invoice.wizard</field> <field name="model">golem.reservation.add.to.invoice.wizard</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<field name="reservation_id" invisible="1" /> <field name="reservation_id" readonly="1" />
<field name="invoice_ids" widget="many2many" <field name="invoice_ids" widget="many2many"
context="{'reservation_id': reservation_id}" context="{'reservation_id': reservation_id}"
readonly="1"> readonly="1">
<tree> <tree>
<field name="partner_id" /> <field name="partner_id" />
<field name="amount_total" /> <field name="amount_total" />
<field name="state"/> <button name="add_to_invoice" type="object" icon="fa fa-plus-square" />
<button name="add_to_invoice" type="object" icon="fas fa-plus-square"/>
</tree> </tree>
</field> </field>
<footer> <footer>