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 import models, fields, api, _
from odoo.exceptions import ValidationError, UserError from odoo.exceptions import UserError
class GolemResourceReservation(models.Model): class GolemResourceReservation(models.Model):
@ -35,7 +35,8 @@ class GolemResourceReservation(models.Model):
def _search_invoicing_state(self, operator, value): def _search_invoicing_state(self, operator, value):
if value == "None": 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'))] return [('id', 'in', reservation.mapped('id'))]
else: else:
return [('invoice_id.state', operator, value)] return [('invoice_id.state', operator, value)]
@ -51,7 +52,8 @@ class GolemResourceReservation(models.Model):
reservation.invoicing_state = "None" reservation.invoicing_state = "None"
@api.multi @api.multi
def voir_invoice(self): def open_invoice(self):
""" open invoice """
for reservation in self: for reservation in self:
if reservation.invoice_id: if reservation.invoice_id:
return {'name' : _('Reservation Invoice'), return {'name' : _('Reservation Invoice'),
@ -59,11 +61,13 @@ class GolemResourceReservation(models.Model):
'res_model' : 'account.invoice', 'res_model' : 'account.invoice',
'res_id' : reservation.invoice_id.id, 'res_id' : reservation.invoice_id.id,
'view_mode': 'form', 'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'target': 'current'} 'target': 'current'}
@api.multi @api.multi
def create_invoice(self): def create_invoice(self):
""" Create invoice """
for reservation in self: for reservation in self:
inv_obj = self.env['account.invoice'] inv_obj = self.env['account.invoice']
partner_id = reservation.partner_id partner_id = reservation.partner_id
@ -81,9 +85,9 @@ class GolemResourceReservation(models.Model):
_('There is no income account defined for this product: "%s". \ _('There is no income account defined for this product: "%s". \
You may have to install a chart of account from Accounting \ You may have to install a chart of account from Accounting \
app, settings menu.') % (product.name,)) app, settings menu.') % (product.name,))
reservation.invoice_id = inv_obj.create({ invoice = inv_obj.create({
'name': reservation.name, 'name': reservation.name,
#'origin': self.application_number, 'origin': reservation.name,
'type': 'out_invoice', 'type': 'out_invoice',
'reference': False, 'reference': False,
'account_id': partner_id.property_account_receivable_id.id, 'account_id': partner_id.property_account_receivable_id.id,
@ -99,3 +103,4 @@ class GolemResourceReservation(models.Model):
'product_id': product.id, '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> <odoo>
<data> <data>
<!-- Trees --> <!-- Trees -->
<record model="ir.ui.view" id="golem_resource_reservation_tree_inherit_golem_resource_account"> <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> <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" <button name="create_invoice" type="object" string="Create New Invoice" class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'not in', 'validated'), attrs="{'invisible': ['|', ('state', 'not in', 'validated'),
'|',('id', '=', False), ('invoicing_state', '=', 'paid')]}" /> '|',('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')]}" /> attrs="{'invisible': [('invoicing_state', '==', 'None')]}" />
</button> </button>
<field name="partner_id" position="after"> <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')]" /> domain="[('invoicing_state', '=', 'open')]" />
<filter name="invoice_paid" string="Invoice Paid" <filter name="invoice_paid" string="Invoice Paid"
domain="[('invoicing_state', '=', '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> </search>
</field> </field>
</record>--> </record>-->
@ -95,23 +78,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
multi="True" multi="True"
target="new" 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> </data>
</odoo> </odoo>

View File

@ -30,11 +30,9 @@ class GolemReservationInvoiceWizard(models.TransientModel):
default=lambda self: self._context.get('active_ids', []), default=lambda self: self._context.get('active_ids', []),
string='Reservations to invoice') string='Reservations to invoice')
@api.multi @api.multi
def create_invoices(self): def create_invoices(self):
""" Create invoices for reservation """
self.ensure_one() self.ensure_one()
if self.reservation_ids: if self.reservation_ids:
@ -55,6 +53,11 @@ class GolemReservationInvoiceWizard(models.TransientModel):
lines = [] lines = []
for reservation in self.reservation_ids: 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 product = reservation.resource_id.product_tmpl_id
amount = product.standard_price amount = product.standard_price
quantity = reservation.hour_stop - reservation.hour_start quantity = reservation.hour_stop - reservation.hour_start
@ -69,8 +72,8 @@ class GolemReservationInvoiceWizard(models.TransientModel):
'product_id': product.id, 'product_id': product.id,
})) }))
invoice = inv_obj.create({ invoice = inv_obj.create({
'name': reservation.name, #'name': reservation.name,
#'origin': self.application_number, #'origin': ,
'type': 'out_invoice', 'type': 'out_invoice',
'reference': False, 'reference': False,
'account_id': partner_id.property_account_receivable_id.id, 'account_id': partner_id.property_account_receivable_id.id,
@ -84,5 +87,6 @@ class GolemReservationInvoiceWizard(models.TransientModel):
'res_model' : 'account.invoice', 'res_model' : 'account.invoice',
'res_id' : invoice.id, 'res_id' : invoice.id,
'view_mode': 'form', 'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'target': 'current'} 'target': 'current'}
return {'type': 'ir.actions.act_window_close'} 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> <odoo>
<data> <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 --> <!-- 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" <record model="ir.ui.view"
id="golem_reservation_invoice_wizard_form"> id="golem_reservation_invoice_wizard_form">
<field name="name"> GOLEM Reservation Invoice Wizard Form</field> <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"> <field name="arch" type="xml">
<form string="Reservation to invoice"> <form string="Reservation to invoice">
<label string="Invoices will be created in draft so that you can review them before validation" /> <label string="Invoices will be created in draft so that you can review them before validation" />
<field name="reservation_ids" />
<footer> <footer>
<button name="create_invoices" string="Create and View Invoices" type="object" <button name="create_invoices" string="Create and View Invoices" type="object"
context="{'open_invoices': True}" class="oe_highlight" /> context="{'open_invoices': True}" class="oe_highlight" />
@ -75,9 +37,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</form> </form>
</field> </field>
</record> </record>
</data> </data>
</odoo> </odoo>