fonction d'ajout de reservation au facture

This commit is contained in:
eloyoussef 2018-04-04 17:57:01 +02:00 committed by Fabien BOURGEOIS
parent 482e4c0b69
commit b584cf8bef
5 changed files with 73 additions and 67 deletions

View File

@ -17,4 +17,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import golem_resource_reservation
from . import golem_resource_reservation, account_invoice

View File

@ -0,0 +1,35 @@
# -*- 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 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)

View File

@ -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'))

View File

@ -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')

View File

@ -19,67 +19,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<odoo>
<data>
<record model="ir.ui.view" id="golem_member_precreation_search_view_form">
<field name="name">GOLEM Member Precreation Search Form</field>
<record model="ir.ui.view" id="golem_reservation_add_to_invoice_form">
<field name="name">GOLEM Reservation Add to invoice Form</field>
<field name="model">golem.reservation.add.to.invoice.wizard</field>
<field name="arch" type="xml">
<form>
<field name="state" invisible="1"/>
<field name="invoice_ids" readonly="1"/>
</form>
</field>
</record>
<!--<record model="ir.ui.view" id="golem_member_precreation_search_view_form">
<field name="name">GOLEM Member Precreation Search Form</field>
<field name="model">golem.member.precreation.search</field>
<field name="arch" type="xml">
<form>
<field name="state" invisible="1" />
<group>
<p colspan="2" states="init">
Please enter a keyword. It will be searched, as case-insensitive, into firstname, lastname and emails.
</p>
<field name="keyword" attrs="{'readonly': [('state', '=', 'final')]}" />
</group>
<group states="final">
<p colspan="2" attrs="{'invisible': [('member_ids', '!=', [])]}">
No member found for the current search.
</p>
<field name="member_ids" readonly="1"
attrs="{'invisible': [('member_ids', '=', [])]}">
<tree>
<field name="id" invisible="1"/>
<field name="firstname"/>
<field name="lastname"/>
<field name="email"/>
<button name="navigate_to_contact" type="object" icon="fa fa-external-link" />
</tree>
</field>
<p colspan="2" attrs="{'invisible': [('contact_ids', '!=', [])]}">
No contact found for the current search.
</p>
<field name="contact_ids" readonly="1"
attrs="{'invisible': [('contact_ids', '=', [])]}">
<tree>
<field name="id" invisible="1"/>
<field name="firstname"/>
<field name="lastname"/>
<field name="email"/>
<button name="navigate_to_contact" type="object" icon="fa fa-external-link" />
</tree>
</field>
</group>
<field name="reservation_id" invisible="1" />
<field name="invoice_ids" widget="many2many"
context="{'reservation_id': reservation_id}"
readonly="1">
<tree>
<field name="partner_id" />
<field name="amount_total" />
<field name="state"/>
<button name="add_to_invoice" type="object" icon="fas fa-plus-square"/>
</tree>
</field>
<footer>
<button name="search_partners" string="Search Members and Contacts"
type="object" class="oe_highlight" states="init" />
<button name="new_search" string="New search"
type="object" states="final" />
<button string="Close" special="cancel" />
</footer>
</form>
</field>
</record>-->
</record>
</data>
</odoo>