Interdiction de facturer plusieurs clients par facture, forçage du partner en client au niveau du view

This commit is contained in:
eloyoussef 2018-03-19 15:07:48 +01:00
parent d620fb18b8
commit 7168052703
4 changed files with 21 additions and 89 deletions

View File

@ -20,7 +20,7 @@
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, UserError
from odoo.exceptions import UserError
class GolemResourceReservation(models.Model):
@ -35,7 +35,8 @@ class GolemResourceReservation(models.Model):
def _search_invoicing_state(self, operator, value):
if value == "None":
reservation = self.env['golem.resource.reservation'].search([('invoice_id', '=', False)])
reservation = self.env['golem.resource.reservation'].search(
[('invoice_id', '=', False)])
return [('id', 'in', reservation.mapped('id'))]
else:
return [('invoice_id.state', operator, value)]
@ -51,7 +52,8 @@ class GolemResourceReservation(models.Model):
reservation.invoicing_state = "None"
@api.multi
def voir_invoice(self):
def open_invoice(self):
""" open invoice """
for reservation in self:
if reservation.invoice_id:
return {'name' : _('Reservation Invoice'),
@ -59,11 +61,13 @@ class GolemResourceReservation(models.Model):
'res_model' : 'account.invoice',
'res_id' : reservation.invoice_id.id,
'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'target': 'current'}
@api.multi
def create_invoice(self):
""" Create invoice """
for reservation in self:
inv_obj = self.env['account.invoice']
partner_id = reservation.partner_id
@ -81,9 +85,9 @@ class GolemResourceReservation(models.Model):
_('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,))
reservation.invoice_id = inv_obj.create({
invoice = inv_obj.create({
'name': reservation.name,
#'origin': self.application_number,
'origin': reservation.name,
'type': 'out_invoice',
'reference': False,
'account_id': partner_id.property_account_receivable_id.id,
@ -99,3 +103,4 @@ class GolemResourceReservation(models.Model):
'product_id': product.id,
})],
})
reservation.invoice_id = invoice.id

View File

@ -18,9 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Trees -->
<record model="ir.ui.view" id="golem_resource_reservation_tree_inherit_golem_resource_account">
<field name="name">GOLEM Resource Reservation Tree Adaptation to invoicing</field>
@ -44,7 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<button name="create_invoice" type="object" string="Create New Invoice" class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'not in', 'validated'),
'|',('id', '=', False), ('invoicing_state', '=', 'paid')]}" />
<button name="voir_invoice" type="object" string="Voir Invoice" class="oe_highlight"
<button name="open_invoice" type="object" string="Open Invoice" class="oe_highlight"
attrs="{'invisible': [('invoicing_state', '==', 'None')]}" />
</button>
<field name="partner_id" position="after">
@ -69,20 +66,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
domain="[('invoicing_state', '=', 'open')]" />
<filter name="invoice_paid" string="Invoice Paid"
domain="[('invoicing_state', '=', 'paid')]" />
<!--<filter name="group_state" string="State"
context="{'group_by': 'state'}" />
<filter name="group_resource" string="Resource"
context="{'group_by': 'resource_id'}" />
<filter name="group_partner_id" string="Partner"
context="{'group_by': 'partner_id'}" />
<filter name="group_user" string="User"
context="{'group_by': 'user_id'}" />
<filter name="group_date_month" string="Month"
context="{'group_by': 'date:month'}" />
<filter name="group_date_week" string="Week"
context="{'group_by': 'date:week'}" />
<filter name="group_date_day" string="Day"
context="{'group_by': 'date:day'}" />-->
</search>
</field>
</record>-->
@ -95,23 +78,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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"
multi="True"
target="new"
/>
<!-- Actions -->
<!--<act_window id="golem_resource_reservation_action" name="Reservations"
res_model="golem.resource.reservation" view_mode="tree,form,calendar" />-->
<!-- Menus -->
<!--<menuitem id="golem_resource_reservation_menu" name="Reservations"
parent="golem_resource_menu" action="golem_resource_reservation_action"
sequence="20" />-->
</data>
</odoo>

View File

@ -30,11 +30,9 @@ class GolemReservationInvoiceWizard(models.TransientModel):
default=lambda self: self._context.get('active_ids', []),
string='Reservations to invoice')
@api.multi
def create_invoices(self):
""" Create invoices for reservation """
self.ensure_one()
if self.reservation_ids:
@ -55,6 +53,11 @@ class GolemReservationInvoiceWizard(models.TransientModel):
lines = []
for reservation in self.reservation_ids:
if partner_id != reservation.partner_id:
raise ValidationError(
_("You can't group reservations of multiple clients in the same \
invoice, please remove inadequate reservations"))
product = reservation.resource_id.product_tmpl_id
amount = product.standard_price
quantity = reservation.hour_stop - reservation.hour_start
@ -69,8 +72,8 @@ class GolemReservationInvoiceWizard(models.TransientModel):
'product_id': product.id,
}))
invoice = inv_obj.create({
'name': reservation.name,
#'origin': self.application_number,
#'name': reservation.name,
#'origin': ,
'type': 'out_invoice',
'reference': False,
'account_id': partner_id.property_account_receivable_id.id,
@ -84,5 +87,6 @@ class GolemReservationInvoiceWizard(models.TransientModel):
'res_model' : 'account.invoice',
'res_id' : invoice.id,
'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'target': 'current'}
return {'type': 'ir.actions.act_window_close'}

View File

@ -18,46 +18,7 @@ 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 and View Invoices" type="object"
context="{'open_invoices': True}" class="oe_highlight" />
<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>
@ -65,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<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" />
<field name="reservation_ids" />
<footer>
<button name="create_invoices" string="Create and View Invoices" type="object"
context="{'open_invoices': True}" class="oe_highlight" />
@ -75,9 +37,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</form>
</field>
</record>
</data>
</odoo>