From c75a0ed7174fcd727ac9b8a75fac88ecb136b026 Mon Sep 17 00:00:00 2001 From: Fabien Bourgeois Date: Fri, 29 Jul 2016 11:38:06 +0200 Subject: [PATCH] [ADD]Note Dates management with calendar views and daily things --- note_dates/__init__.py | 18 ++++++++ note_dates/__openerp__.py | 36 +++++++++++++++ note_dates/models/__init__.py | 18 ++++++++ note_dates/models/note_dates.py | 78 +++++++++++++++++++++++++++++++++ note_dates/views/note_dates.xml | 62 ++++++++++++++++++++++++++ 5 files changed, 212 insertions(+) create mode 100644 note_dates/__init__.py create mode 100644 note_dates/__openerp__.py create mode 100644 note_dates/models/__init__.py create mode 100644 note_dates/models/note_dates.py create mode 100644 note_dates/views/note_dates.xml diff --git a/note_dates/__init__.py b/note_dates/__init__.py new file mode 100644 index 0000000..2fca3d2 --- /dev/null +++ b/note_dates/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from . import models diff --git a/note_dates/__openerp__.py b/note_dates/__openerp__.py new file mode 100644 index 0000000..7197652 --- /dev/null +++ b/note_dates/__openerp__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +{ + 'name': 'Note Dates', + 'summary': 'Dates and hours management for notes', + 'description': ''' + Dates and hours management for notes : + + * Use date field to automatically fix the stage of note; + * Optional duration and begin hour; + * Add calendar view to be able to use per day agenda like. + ''', + 'version': '0.1', + 'category': 'Tools', + 'author': 'Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': ['note_base'], + 'data': ['views/note_dates.xml'] +} diff --git a/note_dates/models/__init__.py b/note_dates/models/__init__.py new file mode 100644 index 0000000..bd6560b --- /dev/null +++ b/note_dates/models/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from . import note_dates diff --git a/note_dates/models/note_dates.py b/note_dates/models/note_dates.py new file mode 100644 index 0000000..a0e3a56 --- /dev/null +++ b/note_dates/models/note_dates.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +# Author: Fabien Bourgeois. Copyright Yaltik +# Copyright (C) +# +# 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 . + +from datetime import timedelta, datetime +from openerp import fields, models, api, _ + + +class Note(models.Model): + + _inherit = 'note.note' + is_daily = fields.Boolean('Daily', default=False) + moment = fields.Selection([('now', _('Now')), ('morning', _('Morning')), + ('afternoon', _('Afternoon')), + ('night', _('Night'))], string='Moment') + date_start = fields.Datetime('Start') + date_stop = fields.Datetime('End') + + @api.onchange('is_daily') + def onchange_isdaily(self): + """ If event is daily, sets infinity """ + for n in self: + if n.is_daily: + today = datetime.now().replace(hour=0, minute=0, second=0) + n.date_start = fields.Datetime.to_string(today) + n.date_stop = fields.Datetime.to_string(datetime( + day=1, month=1, year=2099)) + + @api.onchange('moment') + def onchange_moment(self): + """ According to moment, give good old defaults (warn: UTC) """ + for n in self: + if n.moment: + nowstr = fields.Datetime.now() + now = fields.Datetime.from_string(nowstr) + if n.moment == 'now': + n.date_start = nowstr + n.date_stop = fields.Datetime.to_string(now + + timedelta(hours=1)) + elif n.moment == 'morning': + db = now.replace(hour=6, minute=0, second=0) + n.date_start = fields.Datetime.to_string(db) + n.date_stop = fields.Datetime.to_string(db + + timedelta(hours=4)) + elif n.moment == 'afternoon': + db = now.replace(hour=12, minute=30, second=0) + n.date_start = fields.Datetime.to_string(db) + n.date_stop = fields.Datetime.to_string(db + + timedelta(hours=4)) + else: + delta = timedelta(days=1) + db = now + delta + db = db.replace(hour=3, minute=0, second=0) + n.date_start = fields.Datetime.to_string(db) + n.date_stop = fields.Datetime.to_string(db + + timedelta(hours=3)) + + @api.onchange('date_start') + def onchange_datestart(self): + for n in self: + if n.date_start and not n.date_stop: + dt = fields.Datetime.from_string(n.date_start) + dur = timedelta(hours=1) + n.date_stop = fields.Datetime.to_string(dt + dur) diff --git a/note_dates/views/note_dates.xml b/note_dates/views/note_dates.xml new file mode 100644 index 0000000..6e5be1a --- /dev/null +++ b/note_dates/views/note_dates.xml @@ -0,0 +1,62 @@ + + + + + + + + + Add dates fields for note form + note.note + + + + + + + + + + + + + + Add date_start to tree + note.note + + + + + + + + + + + + Add calendar view, based on date + note.note + + + + + + + +