amélioration de vue et raison de rejection

This commit is contained in:
eloyoussef 2018-03-30 19:03:57 +02:00
parent fdf556a8d8
commit 1415b0306f
7 changed files with 133 additions and 78 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 pack',
'summary': 'GOLEM resources pack',
'description': ''' GOLEM resources pack ''',
'version': '10.0.0.0.3',
'version': '10.0.0.0.4',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
@ -28,5 +28,6 @@
'installable': True,
'depends': ['golem_resource'],
'data': ['views/golem_resource_pack_views.xml',
'wizard/golem_pack_rejection_views.xml',
'security/ir.model.access.csv']
}

View File

@ -26,25 +26,39 @@ class GolemResourcePack(models.Model):
""" GOLEM Resource Pack Model """
_name = 'golem.resource.pack'
_description = 'GOLEM Resource Pack Model'
_inherit = 'mail.thread'
name = fields.Char(compute='_compute_name', store=True)
reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id')
reservation_ids = fields.One2many('golem.resource.reservation', 'pack_id',
readonly=True, states={'draft': [('readonly', False)]},
track_visibility='onchange')
note = fields.Text(help='Notes, optional subject for the reservation, reason')
note = fields.Text(help='Notes, optional subject for the reservation, reason',
readonly=True, states={'draft': [('readonly', False)]},
track_visibility='onchange')
user_id = fields.Many2one('res.users', required=True, index=True, readonly=True,
string='User', default=lambda self: self.env.user)
partner_id = fields.Many2one('res.partner', string='On behalf of',
required=True, index=True)
required=True, index=True, readonly=True,
states={'draft': [('readonly', False)]},
track_visibility='onchange')
state = fields.Selection([('canceled', 'Canceled'),
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('validated', 'Validated'),
('rejected', 'Rejected')],
default='draft', compute="_compute_pack_state")
default='draft', compute="_compute_pack_state",
track_visibility='onchange')
reservation_count = fields.Integer(compute="_compute_reservation_count",
string="Reservation count")
rejection_reason = fields.Text(readonly=True, track_visibility='onchange')
@api.multi
@api.constrains('partner_id')
def set_reservation_partner(self):
for pack in self:
pack.reservation_ids.write({'partner_id': pack.partner_id.id})
@api.multi
@api.depends('reservation_ids')
@ -78,11 +92,15 @@ class GolemResourcePack(models.Model):
@api.multi
def state_rejected(self):
""" pack rejected """
for pack in self:
for reservation in pack.reservation_ids:
if reservation.state == "confirmed":
reservation.write({'state' :'rejected'})
""" Wizard call for pack reject """
self.ensure_one()
pack_id = self[0]
return {'name' : _('Please enter the rejection reason'),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.pack.rejection.wizard',
'context': {'default_pack_id': pack_id.id},
'view_mode': 'form',
'target': 'new'}
@api.depends('partner_id')

View File

@ -18,22 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Calendars -->
<!-- <record model="ir.ui.view" id="golem_resource_reservation_view_calendar">
<field name="name">GOLEM Resource Reservation Calendar</field>
<field name="model">golem.resource.reservation</field>
<field name="arch" type="xml">
<calendar date_start="date_start" date_stop="date_stop" color="resource_id"
event_open_popup="%(golem_resource.golem_resource_reservation_view_form)s"
mode="month">
<field name="resource_id" />
<field name="partner_id" />
<field name="note" />
</calendar>
</field>
</record>-->
<!-- Trees -->
<record model="ir.ui.view" id="golem_resource_pack_view_tree">
<field name="name">GOLEM Resource Pack Tree</field>
@ -76,66 +60,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="user_id" />
<field name="partner_id" />
<field name="note" />
<field name="rejection_reason"
attrs="{'invisible': [('state', '!=', 'rejected')]}"/>
</group>
</group>
<field name="reservation_ids" context="{'default_partner_id' : partner_id}" />
</sheet>
<!--<div class="oe_chatter">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>-->
</div>
</form>
</field>
</record>
<!-- Searches -->
<!--<record model="ir.ui.view" id="golem_resource_reservation_view_search">
<field name="name">GOLEM Resource Reservation Search</field>
<field name="model">golem.resource.reservation</field>
<field name="arch" type="xml">
<search>
<field name="date_start" />
<field name="date_stop" />
<field name="day_start"/>
<field name="resource_id" />
<field name="user_id" />
<field name="partner_id" />
<field name="state" />
<filter name="state_draft" string="Draft"
domain="[('state', '=', 'draft')]" />
<filter name="state_confirmed" string="Confirmed, to Validate"
domain="[('state', '=', 'confirmed')]" />
<filter name="state_validated" string="Validated"
domain="[('state', '=', 'validated')]" />
<filter name="state_rejected" string="Rejected"
domain="[('state', '=', 'rejected')]" />
<separator />
<filter name="day_reservation" string="Day Reservation"
domain="[('day_start', '=', context_today().strftime('%%Y-%%m-%%d'))]" />
<filter name="7days_reservation" string="7 Days Reservations"
domain="[('date_start', '&gt;=', (context_today()+datetime.timedelta(days=0)).strftime('%%Y-%%m-%%d')),
('date_start', '&lt;=', (context_today()+datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d'))]" />
<filter name="30days_reservation" string="30 Days Reservations"
domain="[('date_start', '&gt;=', (context_today()+datetime.timedelta(days=0)).strftime('%%Y-%%m-%%d')),
('date_start', '&lt;=', (context_today()+datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d'))]" />
<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>-->
<!-- Actions -->
<act_window id="golem_resource_pack_action" name="Reservation Pack"
res_model="golem.resource.pack" view_mode="tree,form" />

View File

@ -0,0 +1,19 @@
# -*- 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_pack_rejection

View File

@ -0,0 +1,38 @@
# -*- 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 Resources Pack management """
from odoo import models, fields, api
class GolemReservationRejectionWizard(models.TransientModel):
"""GOLEM Resource wizard : refusal reason for a pack """
_name = "golem.pack.rejection.wizard"
pack_id = fields.Many2one('golem.resource.pack', required=True)
reason = fields.Text(required=True)
@api.multi
def reject(self):
""" Sets pack status to rejected and add reason """
self.ensure_one()
rejection = self[0]
for reservation in rejection.pack_id.reservation_ids:
if reservation.state == "confirmed":
reservation.write({'state' :'rejected'})
rejection.pack_id.write({'rejection_reason': rejection.reason})

View File

@ -0,0 +1,41 @@
<?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>
<!-- Forms -->
<record model="ir.ui.view" id="golem_pack_rejection_wizard_view_form">
<field name="name">GOLEM Pack Rejection Wizard Form</field>
<field name="model">golem.pack.rejection.wizard</field>
<field name="arch" type="xml">
<form string="Rejection reason">
<group>
<field name="pack_id" readonly="1" />
<field name="reason" />
</group>
<footer>
<button name="reject" string="Reject" type="object"
class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</odoo>