[ADD]Note Dates management with calendar views and daily things
This commit is contained in:
parent
92a4430de2
commit
c75a0ed717
18
note_dates/__init__.py
Normal file
18
note_dates/__init__.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2016 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
|
36
note_dates/__openerp__.py
Normal file
36
note_dates/__openerp__.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2016 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': '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']
|
||||||
|
}
|
18
note_dates/models/__init__.py
Normal file
18
note_dates/models/__init__.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2016 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 note_dates
|
78
note_dates/models/note_dates.py
Normal file
78
note_dates/models/note_dates.py
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
62
note_dates/views/note_dates.xml
Normal file
62
note_dates/views/note_dates.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Copyright 2016 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/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
<!-- Form -->
|
||||||
|
<record model="ir.ui.view" id="note_dates_form">
|
||||||
|
<field name="name">Add dates fields for note form</field>
|
||||||
|
<field name="model">note.note</field>
|
||||||
|
<field name="inherit_id" ref="note_base.form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="tag_ids" position="after">
|
||||||
|
<field name="is_daily" />
|
||||||
|
<field name="moment" />
|
||||||
|
<field name="date_start" />
|
||||||
|
<!--attrs="{'invisible': [('is_daily', '=', True)]}" />-->
|
||||||
|
<field name="date_stop" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<!-- Tree -->
|
||||||
|
<record model="ir.ui.view" id="note_dates_tree">
|
||||||
|
<field name="name">Add date_start to tree</field>
|
||||||
|
<field name="model">note.note</field>
|
||||||
|
<field name="inherit_id" ref="note.view_note_note_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="tag_ids" position="after">
|
||||||
|
<field name="is_daily" />
|
||||||
|
<field name="date_start" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<!-- Action -->
|
||||||
|
<!-- Calendar -->
|
||||||
|
<record model="ir.ui.view" id="note_dates_calendar">
|
||||||
|
<field name="name">Add calendar view, based on date</field>
|
||||||
|
<field name="model">note.note</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<calendar date_start="date_start" date_stop="date_stop"
|
||||||
|
color="stage_id" all_day="is_daily" display="[name]" mode="day">
|
||||||
|
<field name="name" />
|
||||||
|
</calendar>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user