Merge pull request #12 from akretion/8-calendar
[ADD] calendar usability
This commit is contained in:
1
calendar_default_value/__init__.py
Normal file
1
calendar_default_value/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import resource
|
||||
32
calendar_default_value/__openerp__.py
Normal file
32
calendar_default_value/__openerp__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# coding: utf-8
|
||||
# © 2015 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': 'Calendar Default Values',
|
||||
'summary': 'Makes calendar creation quicker',
|
||||
'description': """
|
||||
Calendar Default Values
|
||||
=======================
|
||||
|
||||
Define opening hours for each day of week at calendar creation.
|
||||
|
||||
Method to override for behavior customization:
|
||||
|
||||
- get_my_calendar_data()
|
||||
- map_day()
|
||||
- string_format()
|
||||
|
||||
""",
|
||||
'version': '8.0.1.0.0',
|
||||
'author': 'Akretion',
|
||||
'category': 'base',
|
||||
'depends': [
|
||||
'resource',
|
||||
],
|
||||
'website': 'http://www.akretion.com/',
|
||||
'data': [
|
||||
'calendar_view.xml',
|
||||
],
|
||||
'license': 'AGPL-3',
|
||||
}
|
||||
29
calendar_default_value/calendar_view.xml
Normal file
29
calendar_default_value/calendar_view.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="resource_calendar_form" model="ir.ui.view">
|
||||
<field name="model">resource.calendar</field>
|
||||
<field name="inherit_id" ref="resource.resource_calendar_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="hour_range"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_resource_calendar_tree" model="ir.ui.view">
|
||||
<field name="model">resource.calendar</field>
|
||||
<field name="inherit_id" ref="resource.view_resource_calendar_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="hour_range"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
37
calendar_default_value/i18n/calendar_default_value.pot
Normal file
37
calendar_default_value/i18n/calendar_default_value.pot
Normal file
@@ -0,0 +1,37 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * calendar_default_value
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 8.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-01-05 17:42+0000\n"
|
||||
"PO-Revision-Date: 2016-01-05 17:42+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: field:resource.calendar,hour_range:0
|
||||
msgid "Hour Range"
|
||||
msgstr ""
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: model:ir.model,name:calendar_default_value.model_resource_calendar
|
||||
msgid "Resource Calendar"
|
||||
msgstr ""
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: help:resource.calendar,hour_range:0
|
||||
msgid "String representation of working hours"
|
||||
msgstr ""
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: model:ir.model,name:calendar_default_value.model_resource_calendar_attendance
|
||||
msgid "Work Detail"
|
||||
msgstr ""
|
||||
|
||||
38
calendar_default_value/i18n/fr_FR.po
Normal file
38
calendar_default_value/i18n/fr_FR.po
Normal file
@@ -0,0 +1,38 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * calendar_default_value
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 8.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-01-05 18:43+0100\n"
|
||||
"PO-Revision-Date: 2016-01-05 18:44+0100\n"
|
||||
"Last-Translator: David BEAL <david.beal@akretion.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: fr_FR\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: \n"
|
||||
"X-Generator: Poedit 1.8.4\n"
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: field:resource.calendar,hour_range:0
|
||||
msgid "Hour Range"
|
||||
msgstr "Plage Horaire"
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: model:ir.model,name:calendar_default_value.model_resource_calendar
|
||||
msgid "Resource Calendar"
|
||||
msgstr "Calendrier de la ressource"
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: help:resource.calendar,hour_range:0
|
||||
msgid "String representation of working hours"
|
||||
msgstr "Représentation en chaîne de caractères des heures de travail"
|
||||
|
||||
#. module: calendar_default_value
|
||||
#: model:ir.model,name:calendar_default_value.model_resource_calendar_attendance
|
||||
msgid "Work Detail"
|
||||
msgstr "Détail du travail"
|
||||
113
calendar_default_value/resource.py
Normal file
113
calendar_default_value/resource.py
Normal file
@@ -0,0 +1,113 @@
|
||||
# coding: utf-8
|
||||
# © 2015 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import collections
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class ResourceCalendarAttendance(models.Model):
|
||||
_inherit = 'resource.calendar.attendance'
|
||||
|
||||
# PR is done for v9
|
||||
# https://github.com/odoo/odoo/pull/10310
|
||||
calendar_id = fields.Many2one(ondelete='cascade')
|
||||
|
||||
|
||||
class ResourceCalendar(models.Model):
|
||||
_inherit = 'resource.calendar'
|
||||
_rec_name = 'display_name'
|
||||
|
||||
hour_range = fields.Char(
|
||||
string='Hour Range', compute='_compute_hour_range',
|
||||
readonly=True, store=True,
|
||||
help="String representation of working hours")
|
||||
display_name = fields.Char(compute='_compute_display_name', store=True)
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'hour_range')
|
||||
def _compute_display_name(self):
|
||||
for rec in self:
|
||||
rec.display_name = "%s: %s" % (rec.name, rec.hour_range)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
"'attendance_ids' field default value"
|
||||
values = super(ResourceCalendar, self).default_get(fields_list)
|
||||
vals = []
|
||||
params = self.get_my_calendar_data()
|
||||
for day in range(0, params.endday):
|
||||
mapping = self._populate_attendance(
|
||||
day, params.hour_from, params.hour_to)
|
||||
vals.append((0, 0, mapping))
|
||||
if params.hour_from2 and params.hour_to2:
|
||||
mapping = self._populate_attendance(
|
||||
day, params.hour_from2, params.hour_to2)
|
||||
vals.append((0, 0, mapping))
|
||||
values['attendance_ids'] = vals
|
||||
return values
|
||||
|
||||
@api.model
|
||||
def _populate_attendance(self, day, hour_from, hour_to):
|
||||
return {
|
||||
'hour_from': hour_from,
|
||||
'hour_to': hour_to,
|
||||
'name': '.',
|
||||
'dayofweek': str(day),
|
||||
}
|
||||
|
||||
@api.model
|
||||
def get_my_calendar_data(self):
|
||||
'Override me according to your opening hours'
|
||||
Params = collections.namedtuple(
|
||||
'Params', 'hour_from hour_to hour_from2 hour_to2 endday')
|
||||
return Params(
|
||||
endday=5,
|
||||
hour_from=8,
|
||||
hour_to=12,
|
||||
# put hour_to/from to False if you don't want use them
|
||||
hour_from2=13,
|
||||
hour_to2=17,
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.depends('attendance_ids')
|
||||
def _compute_hour_range(self):
|
||||
for rec in self:
|
||||
if rec.attendance_ids:
|
||||
info = []
|
||||
dayofweek = ''
|
||||
for hours in rec.attendance_ids:
|
||||
if hours.dayofweek != dayofweek:
|
||||
selection = hours._fields['dayofweek'].selection
|
||||
str_day = self.map_day()[
|
||||
selection[int(hours.dayofweek)][1]]
|
||||
info.append(
|
||||
self.string_format(main_string=True) % (
|
||||
str_day, int(hours.hour_from),
|
||||
int(hours.hour_to)))
|
||||
else:
|
||||
# We are on the same day but with another hour range
|
||||
# we concatenate on the first string of the day
|
||||
position = info.index(info[-1:][0])
|
||||
info[position] = self.string_format() % (
|
||||
info[-1:][0], int(hours.hour_from),
|
||||
int(hours.hour_to))
|
||||
dayofweek = hours.dayofweek
|
||||
rec.hour_range = ', '.join(info)
|
||||
|
||||
@api.model
|
||||
def string_format(self, main_string=None):
|
||||
'Override me to customize calendar hour_range'
|
||||
if main_string:
|
||||
# ie: 'Lu 8-12'
|
||||
return '%s %s-%s'
|
||||
# ie: 'Lu 8-12 / 13-17'
|
||||
return '%s / %s-%s'
|
||||
|
||||
@api.model
|
||||
def map_day(self):
|
||||
'Override me to customize calendar hour_range'
|
||||
return {'Monday': 'Lu', 'Tuesday': 'Ma', 'Wednesday': 'Me',
|
||||
'Thursday': 'Je', 'Friday': 'Ve', 'Saturday': 'Sa',
|
||||
'Sunday': 'Di'}
|
||||
Reference in New Issue
Block a user