Ajout du Facturation multi ligne depuis action

This commit is contained in:
eloyoussef 2018-03-16 16:04:33 +01:00
parent 72739a2df6
commit c3f7ee1bb4
7 changed files with 204 additions and 4 deletions

View File

@ -16,4 +16,4 @@
# 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/>.
from . import models
from . import models, wizard

View File

@ -20,7 +20,7 @@
'name': 'GOLEM resources invoicing',
'summary': 'GOLEM resources invoicing',
'description': ''' GOLEM resources invoicing ''',
'version': '10.0.0.0.0',
'version': '10.0.0.0.2',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
@ -28,5 +28,6 @@
'installable': True,
'depends': ['golem_resource',
'account'],
'data': ['views/golem_resource_reservation_views.xml']
'data': ['views/golem_resource_reservation_views.xml',
'wizard/golem_reservation_invoice.xml']
}

View File

@ -27,7 +27,7 @@ class GolemResourceReservation(models.Model):
""" GOLEM Resource Reservation Adaptation """
_inherit = 'golem.resource.reservation'
@api.multi
def create_invoice(self):
for reservation in self:
@ -38,13 +38,16 @@ class GolemResourceReservation(models.Model):
if product.id:
account_id = product.property_account_income_id.id
if not account_id:
account_id = product.categ_id.property_account_income_categ_id.id
if not account_id:
raise UserError(
_('There is no income account defined for this product: "%s". \
You may have to install a chart of account from Accounting \
app, settings menu.') % (product.name,))
invoice = inv_obj.create({
'name': reservation.name,

View File

@ -82,6 +82,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</search>
</field>
</record>-->
<!-- Add option to the "More" button -->
<act_window id="action_golem_reservation_invoice_wizard"
name="Reservations to invoice"
res_model="golem.reservation.invoice.wizard"
src_model="golem.resource.reservation"
view_mode="form"
view_id="golem_reservation_invoice_wizard_form"
multi="True"
target="new"
/>
<act_window id="action_golem_reservation_invoice_editable_wizard"
name="Reservations to invoice-edition"
res_model="golem.reservation.invoice.wizard"
src_model="golem.resource.reservation"
view_mode="form"
view_id="golem_reservation_invoice_wizard_form_editable"
multi="True"
target="new"
/>
<!-- Actions -->
<!--<act_window id="golem_resource_reservation_action" name="Reservations"

View File

@ -0,0 +1,20 @@
# -*- 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/>.
from . import golem_reservation_invoice

View File

@ -0,0 +1,78 @@
# -*- 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 Reservation Invoice Wizard"""
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, UserError
class GolemReservationInvoiceWizard(models.TransientModel):
""" GOLEM Resource Reservation Invoice Wizard """
_name = 'golem.reservation.invoice.wizard'
reservation_ids = fields.Many2many('golem.resource.reservation',
default=lambda self: self._context.get('active_ids', []),
string='Reservations to invoice')
@api.multi
def create_invoices(self):
self.ensure_one()
if self.reservation_ids:
inv_obj = self.env['account.invoice']
partner_id = self.reservation_ids[0].partner_id
product = self.reservation_ids[0].resource_id.product_tmpl_id
if product.id:
account_id = product.property_account_income_id.id
if not account_id:
account_id = product.categ_id.property_account_income_categ_id.id
if not account_id:
raise UserError(
_('There is no income account defined for this product: "%s". \
You may have to install a chart of account from Accounting \
app, settings menu.') % (product.name,))
lines = []
for reservation in self.reservation_ids:
product = reservation.resource_id.product_tmpl_id
amount = product.standard_price
lines.append((0, 0, {
'name': reservation.resource_id.name,
#'origin': ,
'account_id': account_id,
'price_unit': amount,
'quantity': 1.0,
'discount': 0.0,
'uom_id': product.uom_id.id,
'product_id': product.id,
}))
invoice = inv_obj.create({
'name': reservation.name,
#'origin': self.application_number,
'type': 'out_invoice',
'reference': False,
'account_id': partner_id.property_account_receivable_id.id,
'partner_id': partner_id.id,
'invoice_line_ids': lines,
})

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="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/>.
-->
<odoo>
<data>
<!-- Trees -->
<!--<record model="ir.ui.view" id="golem_resource_reservation_view_tree">
<field name="name">GOLEM Resource Reservation Tree</field>
<field name="model">golem.resource.reservation</field>
<field name="arch" type="xml">
<tree>
<field name="resource_id" />
<field name="date" />
<field name="hour_start" widget="float_time" />
<field name="hour_stop" widget="float_time" />
<field name="partner_id" />
<field name="state" />
</tree>
</field>
</record>-->
<!-- Forms -->
<record model="ir.ui.view"
id="golem_reservation_invoice_wizard_form_editable">
<field name="name"> GOLEM Reservation Invoice Wizard Form Editable</field>
<field name="model">golem.reservation.invoice.wizard</field>
<field name="arch" type="xml">
<form string="Reservation to invoice">
<group>
<field name="reservation_ids" context="{'default_reservation_ids': active_ids}" />
</group>
<footer>
<button name="create_invoices" string="Create Invoices" type="object"
class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.ui.view"
id="golem_reservation_invoice_wizard_form">
<field name="name"> GOLEM Reservation Invoice Wizard Form</field>
<field name="model">golem.reservation.invoice.wizard</field>
<field name="arch" type="xml">
<form string="Reservation to invoice">
<label string="Invoices will be created in draft so that you can review them before validation" />
<footer>
<button name="create_invoices" string="Create Invoices" type="object"
class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</odoo>