fonction d'ajout de reservation au facture

This commit is contained in:
eloyoussef 2018-04-04 17:57:01 +02:00
parent 08eb3ecb4b
commit 4712b3e689
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/>. # 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""" """ Add reservation to existing invoice"""
for reservation in self: for reservation in self:
partner = reservation.partner_id partner = reservation.partner_id
invoice_list = self.env['account.invoice'].search([('partner_id', '=', partner.id), domain = [('partner_id', '=', partner.id),
('state', '=', 'draft')]) ('state', '=', 'draft')]
invoice_list = self.env['account.invoice'].search(domain)
#test if none #test if none
invoice_ids = invoice_list.mapped('id') if invoice_list:
return {'name' : ("partner's invoice list"), invoice_ids = invoice_list.mapped('id')
'type' : 'ir.actions.act_window', return {'name' : ("partner's invoice list"),
'res_model' : 'golem.reservation.add.to.invoice.wizard', 'type' : 'ir.actions.act_window',
'context': {'default_invoice_ids': invoice_ids}, 'res_model' : 'golem.reservation.add.to.invoice.wizard',
'view_mode': 'form', 'context': {'default_invoice_ids': invoice_ids,
'flags': {'initial_mode': 'view'}, 'default_reservation_id': reservation.id},
'target': 'new'} '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 """ """GOLEM Resrvation 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')], #state = fields.Selection([('init', 'Init'), ('final', 'Final')],
default='init') # 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')
@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') 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> <odoo>
<data> <data>
<record model="ir.ui.view" id="golem_member_precreation_search_view_form"> <record model="ir.ui.view" id="golem_reservation_add_to_invoice_form">
<field name="name">GOLEM Member Precreation Search 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="state" invisible="1"/> <field name="reservation_id" invisible="1" />
<field name="invoice_ids" readonly="1"/> <field name="invoice_ids" widget="many2many"
</form> context="{'reservation_id': reservation_id}"
</field> readonly="1">
</record> <tree>
<field name="partner_id" />
<!--<record model="ir.ui.view" id="golem_member_precreation_search_view_form"> <field name="amount_total" />
<field name="name">GOLEM Member Precreation Search Form</field> <field name="state"/>
<field name="model">golem.member.precreation.search</field> <button name="add_to_invoice" type="object" icon="fas fa-plus-square"/>
<field name="arch" type="xml"> </tree>
<form> </field>
<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>
<footer> <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" /> <button string="Close" special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>
</record>--> </record>
</data> </data>
</odoo> </odoo>