deplacement des fonctionnalités sur un nouveau module

This commit is contained in:
eloyoussef 2018-03-27 15:20:01 +02:00
parent 1f295ec9c7
commit 73e92ca551
12 changed files with 138 additions and 464 deletions

View File

@ -27,5 +27,9 @@
'application': True,
'installable': True,
'depends': ['golem_resource'],
'data': []
'data': [
'views/golem_resource_views.xml',
'views/golem_resource_reservation_views.xml',
'views/golem_resource_option_views.xml',
'views/golem_resource_option_selection_views.xml']
}

View File

@ -16,7 +16,7 @@
# 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_resource_type, \
golem_resource_timetable, \
from . import golem_resource_option, \
golem_resource_option_selection, \
golem_resource, \
golem_resource_reservation

View File

@ -16,7 +16,7 @@
# 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 management """
""" GOLEM Resources Option Management """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
@ -24,72 +24,7 @@ from odoo.exceptions import ValidationError
class GolemResource(models.Model):
""" GOLEM Resource Model """
_name = 'golem.resource'
_description = 'GOLEM Resource Model'
_inherit = 'mail.thread'
_order = 'name asc'
_inherit = 'golem.resource'
name = fields.Char(required=True, index=True)
active = fields.Boolean(default=True)
validation_required = fields.Boolean(default=False,
string='Is validation required ?')
type_id = fields.Many2one('golem.resource.type',
index=True, string='Resource Type')
supervisor_id = fields.Many2one('res.partner', index=True, string='Supervisor')
product_tmpl_id = fields.Many2one('product.template', index=True,
string='Linked product',
help='A generic product can be linked, in '
'order to sell reservations (work in '
'progress)')
avaibility_start = fields.Date(required=True, string='Availibility start date')
avaibility_stop = fields.Date(required=True, string='Availibility stop date')
availibility_24_7 = fields.Boolean(string='24/7 availibility')
timetable_ids = fields.One2many('golem.resource.timetable', 'resource_id',
string='Availibility timetable')
reservation_ids = fields.One2many('golem.resource.reservation', 'resource_id',
string='Reservations')
reservation_count = fields.Integer(compute='_compute_reservation_count')
@api.depends('reservation_ids')
def _compute_reservation_count(self):
for resource in self:
resource.reservation_count = len(resource.reservation_ids)
@api.multi
def reservation_calendar(self):
""" current resource reservation calendar """
self.ensure_one()
return {
'name': _('Resource Reservation'),
'view_mode': 'calendar,tree,form',
'res_model': 'golem.resource.reservation',
'context': {'search_default_resource_id': self[0].id},
'type': 'ir.actions.act_window'
}
@api.multi
def reserveration_list(self):
""" current resource reservation list """
self.ensure_one()
return {
'name': _('Resource Reservation list'),
'view_mode': 'tree,form,calendar',
'res_model': 'golem.resource.reservation',
'context': {'search_default_resource_id': self[0].id},
'type': 'ir.actions.act_window'
}
@api.multi
def active_toggle(self):
""" Toggles active boolean """
for resource in self:
resource.active = not resource.active
@api.constrains('avaibility_start', 'avaibility_stop')
def _check_date_consistency(self):
""" Checks date consistency """
for resource in self:
if resource.avaibility_stop <= resource.avaibility_start:
raise ValidationError(_('End availibility should be after than '
'start availibility'))
option_ids = fields.One2many('golem.resource.option', 'resource_id',
string='Option list')

View File

@ -19,14 +19,13 @@
""" GOLEM Resource Option """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo import models, fields
class GolemResourceOption(models.Model):
""" GOLEM Resource Option Model """
_name = 'golem.resource.option'
_description = 'GOLEM Reservation Model'
_description = 'GOLEM Reservation Option Model'
name = fields.Char()
resource_id = fields.Many2one('golem.resource')
name = fields.Char("Option")
resource_id = fields.Many2one('golem.resource', "Resource")

View File

@ -0,0 +1,43 @@
# -*- 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 Option Selection"""
from odoo import models, fields, api, _
class GolemResourceOptionSelection(models.Model):
""" GOLEM Resource Option SelectionModel """
_name = 'golem.resource.option.selection'
_description = 'GOLEM Resource option selection Model'
name = fields.Char(compute="_compute_name")
option_id = fields.Many2one('golem.resource.option', 'Option',
domain="[('resource_id', '=', resource_id)]")
resource_id = fields.Many2one(related="reservation_id.resource_id")
reservation_id = fields.Many2one('golem.resource.reservation', 'Reservation')
@api.multi
def _compute_name(self):
for selection in self:
selection.name = "{}/{}".format(selection.resource_id.name, selection.option_id.name)
_sql_constraints = [
('unique_selection', "UNIQUE(resource_id, option_id, reservation_id)",
_("Not allowed, a reservation with same option and resource already exists"))]

View File

@ -16,17 +16,18 @@
# 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 Type """
""" GOLEM Resource Reservation """
from odoo import models, fields
class GolemResourceType(models.Model):
""" GOLEM Resource Type """
_name = 'golem.resource.type'
_description = 'GOLEM Resource Type'
_order = 'name asc'
_sql_constraints = [('golem_resource_type_name_uniq',
'UNIQUE (name)',
'Resource type must be unique.')]
from datetime import timedelta
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
name = fields.Char(string='Resource Type', required=True, index=True)
class GolemResourceReservation(models.Model):
""" GOLEM Resource Reservation Option Model """
_inherit = 'golem.resource.reservation'
resource_option_ids = fields.One2many(related="resource_id.option_ids")
selected_option_ids = fields.One2many('golem.resource.option.selection', 'reservation_id',
string="Selected option")

View File

@ -1,77 +0,0 @@
# -*- 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 Timetable """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemTimetable(models.Model):
""" Golem Timetable """
_name = "golem.resource.timetable"
_description = "Golem Timetable"
_rec_name = 'weekday'
_order = 'weekday asc,time_start asc'
resource_id = fields.Many2one('golem.resource', required=True,
string='Linked resource')
weekday = fields.Selection([('0', _('Monday')),
('1', _('Tuesday')),
('2', _('Wednesday')),
('3', _('Thursday')),
('4', _('Friday')),
('5', _('Saturday')),
('6', _('Sunday'))], required=True)
time_start = fields.Float(string='Start')
time_stop = fields.Float(string='Stop')
availibility_24 = fields.Boolean(string="All day")
@api.onchange('availibility_24')
def onchange_availibility_24(self):
""" fill time_start et time_stop if availibility_24 is True """
for line in self:
if line.availibility_24:
line.update({'time_start': 0.0, 'time_stop': 23.98})
@api.onchange('time_start')
def onchange_time_start(self):
""" Propose automatically stop hour after start hour had been filled """
for line in self:
if line.time_start and not line.time_stop:
line.time_stop = line.time_start + 1
@api.constrains('availibility_24')
def check_avaibility24(self):
""" Checks hour consistency against avaibility 24 """
for line in self:
if line.availibility_24:
line.write({'time_start': 0.0, 'time_stop': 23.98})
@api.constrains('time_start', 'time_stop')
def _check_time_consistency(self):
""" Checks time consistency """
for line in self:
if line.time_stop <= line.time_start:
raise ValidationError(_('End time should be after than start time'))
@api.constrains('time_start', 'time_stop')
def _check_time_all_day(self):
""" Checks time all day availibility """
for timetable in self:
if timetable.time_stop > 23.98 and timetable.time_start == 0:
timetable.write({'availibility_24': True})

View File

@ -18,20 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Trees -->
<record model="ir.ui.view" id="golem_resource_timetable_view_tree">
<field name="name">GOLEM Resource Timetable Tree</field>
<field name="model">golem.resource.timetable</field>
<!-- Form -->
<record model="ir.ui.view" id="golem_resource_option_selection_form">
<field name="name">GOLEM Resource Option Selection Form</field>
<field name="model">golem.resource.option.selection</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="resource_id" invisible="1" />
<field name="weekday" />
<field name="availibility_24"/>
<field name="time_start" string="Start hour" widget="float_time"
required="1" />
<field name="time_stop" string="Stop hour" widget="float_time"
required="1" />
</tree>
<form >
<group>
<field name="name" invisible="1"/>
<field name="resource_id" invisible="1" />
<field name="reservation_id" invisible="1"/>
<field name="option_id"/>
</group>
</form>
</field>
</record>
</data>

View File

@ -0,0 +1,36 @@
<?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>
<!-- Form -->
<record model="ir.ui.view" id="golem_resource_option_form">
<field name="name">GOLEM Resource Option Form</field>
<field name="model">golem.resource.option</field>
<field name="arch" type="xml">
<form >
<group>
<field name="name" />
<field name="resource_id" invisible="1" />
</group>
</form>
</field>
</record>
</data>
</odoo>

View File

@ -18,129 +18,22 @@ 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">
<field name="resource_id" />
<field name="user_id" />
<field name="partner_id" />
</calendar>
</field>
</record>
<!-- 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_start" />
<field name="date_stop" />
<field name="partner_id" />
<field name="state" />
</tree>
</field>
</record>
<!-- Forms -->
<record model="ir.ui.view" id="golem_resource_reservation_view_form">
<field name="name">GOLEM Resource Reservation Form</field>
<record model="ir.ui.view" id="golem_resource_reservation_inherit_option_form">
<field name="name">GOLEM Resource Reservation Option Extension Form</field>
<field name="model">golem.resource.reservation</field>
<field name="inherit_id" ref="golem_resource.golem_resource_reservation_view_form"/>
<field name="arch" type="xml">
<form>
<header>
<button name="state_confirm" type="object" string="Confirm" class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'not in', 'draft'), ('id', '=', False)]}" />
<button name="state_canceled" type="object"
string="Cancel" states="confirmed,validated" />
<button name="state_draft" type="object" string="Set to draft"
states="canceled,confirmed,validated,rejected" />
<button name="state_validated" type="object" string="Validate"
states="confirmed" class="oe_highlight"
groups="golem_base.group_golem_manager" />
<button name="state_rejected" type="object" string="Reject"
states="confirmed" class="oe_highlight"
groups="golem_base.group_golem_manager" />
<field name="state" widget="statusbar" />
</header>
<sheet>
<group>
<group string="Resource">
<field name="id" invisible="1" />
<field name="resource_id" options="{'no_create': True}" />
<field name="resource_avaibility_24_7" readonly="1" />
<field name="resource_avaibility_start" readonly="1" />
<field name="resource_avaibility_stop" readonly="1" />
<field name="resource_timetable_ids" readonly="1"
attrs="{'invisible': [('resource_avaibility_24_7', '=', True)]}" />
</group>
<group string="Reservation">
<group>
<field name="date_start" />
<field name="date_stop" />
<field name="user_id" options="{'no_create': True}" />
<field name="partner_id" />
<field name="note"
placeholder="Notes, optional subject for the reservation, reason" />
<field name="rejection_reason"
attrs="{'invisible': [('state', '!=', 'rejected')]}"/>
</group>
</group>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
<field name="partner_id" position="after" >
<field name="selected_option_ids"
context="{'default_reservation_id': active_id}"
widget="many2many_tags">
<tree>
<field name="option_id"/>
</tree>
</field>
</field>
</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="resource_id" />
<field name="user_id" />
<field name="partner_id" />
<field name="state" />
<filter name="to_validate" string="Reservation to Validate"
domain="[('state', '=', 'confirmed')]" />
<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_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

@ -1,54 +0,0 @@
<?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_type_view_tree">
<field name="name">GOLEM Resource Type Tree</field>
<field name="model">golem.resource.type</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="name" />
</tree>
</field>
</record>
<!-- Searches -->
<record model="ir.ui.view" id="golem_resource_type_view_search">
<field name="name">GOLEM Resource Type Search</field>
<field name="model">golem.resource.type</field>
<field name="arch" type="xml">
<search>
<field name="name" />
</search>
</field>
</record>
<!-- Actions -->
<act_window id="golem_resource_type_action" name="Resource Types"
res_model="golem.resource.type" view_mode="tree" />
<!-- Menus -->
<menuitem id="resource_cofiguration_type_menu" name="Resource Types"
parent="resource_configuration_menu"
action="golem_resource_type_action" sequence="10" />
</data>
</odoo>

View File

@ -18,123 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Trees -->
<record model="ir.ui.view" id="golem_resource_view_tree">
<field name="name">GOLEM Resource Tree</field>
<field name="model">golem.resource</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="type_id" />
<field name="supervisor_id" />
<field name="product_tmpl_id" />
<field name="avaibility_start" />
<field name="avaibility_stop" />
<field name="validation_required" />
</tree>
</field>
</record>
<!-- Forms -->
<record model="ir.ui.view" id="golem_resource_view_form">
<field name="name">GOLEM Resource Form</field>
<record model="ir.ui.view" id="golem_resource_inherit_option_form">
<field name="name">GOLEM Resource Option Extention Form</field>
<field name="model">golem.resource</field>
<field name="inherit_id" ref="golem_resource.golem_resource_view_form"/>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" icon="fa-archive"
name="active_toggle" type="object">
<field name="active" widget="boolean_button"
options="{'terminology': 'archive'}" />
</button>
<button class="oe_stat_button" icon="fa-list"
name="reserveration_list" type="object">
<field string="Reservations" name="reservation_count"
widget="statinfo"/>
</button>
<button class="oe_stat_button" icon="fa-calendar"
name="reservation_calendar" type="object" string="Calendar" />
</div>
<group>
<group>
<field name="name" />
<field name="type_id" />
<field name="product_tmpl_id" options="{'no_create': True}" />
</group>
<group>
<field name="validation_required" />
<field name="supervisor_id" />
</group>
</group>
<group string="Availibility configuration">
<group colspan="2">
<field name="id" invisible="1"/>
<field name="availibility_24_7"/>
<field name="avaibility_start" />
<field name="avaibility_stop" />
</group>
<p attrs="{'invisible': ['|',
('id', '!=', False),
('availibility_24_7', '=', True)]}">
Please save the resource before fixing the timetable availibility"
</p>
<group colspan="2" attrs="{'invisible': [('availibility_24_7', '=', True)]}">
<field name="timetable_ids"
context="{'default_resource_id': active_id}"
attrs="{'readonly': [('id', '=', False)]}" />
</group>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
<field name="supervisor_id" position="after">
<field name="option_ids" widget="many2many_tags"
context="{'default_resource_id': active_id}" />
</field>
</field>
</record>
<!-- Searches -->
<record model="ir.ui.view" id="golem_resource_view_search">
<field name="name">GOLEM Resource search</field>
<field name="model">golem.resource</field>
<field name="arch" type="xml">
<search>
<field name="name" />
<field name="type_id" />
<field name="supervisor_id" />
<field name="product_tmpl_id" />
<filter name="with_validation" string="With validation"
domain="[('validation_required', '=', True)]" />
<filter name="without_validation" string="Without validation"
domain="[('validation_required', '=', False)]" />
<separator />
<filter name="archived" string="Archived"
domain="[('active', '=', False)]" />
<filter name="group_type" string="Type"
context="{'group_by': 'type_id'}"/>
<filter name="group_supervisor" string="Supervisor"
context="{'group_by': 'supervisor_id'}"/>
<filter name="group_product" string="Linked product"
context="{'group_by': 'product_tmpl_id'}"/>
</search>
</field>
</record>
<!-- Actions -->
<act_window id="golem_resource_action" name="Resources"
res_model="golem.resource" view_mode="tree,form" />
<!-- Menus -->
<menuitem id="golem_resource_menu" name="Resources"
sequence="55" groups="golem_base.group_golem_user"
web_icon="golem_resource,static/description/icon.png" />
<menuitem id="resource_list_menu" name="Resources" parent="golem_resource_menu"
action="golem_resource_action" sequence="10" />
<menuitem id="resource_configuration_menu" name="Configuration"
parent="golem_resource_menu" groups="golem_base.group_golem_manager"
sequence="90" />
</data>
</odoo>