initialisation resource option

This commit is contained in:
eloyoussef 2018-03-21 01:36:29 +01:00
parent 1886ab9828
commit 7af41f07c7
11 changed files with 686 additions and 0 deletions

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 models

View File

@ -0,0 +1,31 @@
# -*- 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/>.
{
'name': 'GOLEM resources option',
'summary': 'GOLEM resources option',
'description': ''' GOLEM resources option ''',
'version': '10.0.0.0.0',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
'application': True,
'installable': True,
'depends': ['golem_resource'],
'data': []
}

View File

@ -0,0 +1,22 @@
# -*- 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_resource_type, \
golem_resource_timetable, \
golem_resource, \
golem_resource_reservation

View File

@ -0,0 +1,95 @@
# -*- 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 management """
from odoo import models, fields, api, _
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'
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'))

View File

@ -0,0 +1,32 @@
# -*- 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 """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemResourceOption(models.Model):
""" GOLEM Resource Option Model """
_name = 'golem.resource.option'
_description = 'GOLEM Reservation Model'
name = fields.Char()
resource_id = fields.Many2one('golem.resource')

View File

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

@ -0,0 +1,32 @@
# -*- 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 Type """
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.')]
name = fields.Char(string='Resource Type', required=True, index=True)

View File

@ -0,0 +1,146 @@
<?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>
<!-- 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>
<field name="model">golem.resource.reservation</field>
<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>
</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

@ -0,0 +1,38 @@
<?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_timetable_view_tree">
<field name="name">GOLEM Resource Timetable Tree</field>
<field name="model">golem.resource.timetable</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>
</field>
</record>
</data>
</odoo>

View File

@ -0,0 +1,54 @@
<?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

@ -0,0 +1,140 @@
<?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_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>
<field name="model">golem.resource</field>
<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>
</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>