Basic model and view for work period

This commit is contained in:
Shalabh Aggarwal 2012-09-26 21:16:01 +05:30
parent 2291ed3242
commit 69e4443f08
2 changed files with 116 additions and 2 deletions

View File

@ -23,6 +23,7 @@ from nereid.signals import registration
from nereid.contrib.pagination import Pagination
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.pyson import Eval
from trytond.config import CONFIG
from trytond.tools import get_smtp_server
@ -188,6 +189,45 @@ class ProjectWorkInvitation(ModelSQL):
ProjectWorkInvitation()
class WorkPeriod(ModelSQL, ModelView):
'Work Period'
_name= 'project.work.period'
_description = __doc__
name = fields.Char('Name', required=True)
start_date = fields.Date('Starting Date', required=True, select=True)
end_date = fields.Date('Ending Date', required=True, select=True)
def __init__(self):
super(WorkPeriod, self).__init__()
self._constraints += [
('check_dates', 'periods_overlaps'),
]
self._order.insert(0, ('start_date', 'ASC'))
self._error_messages.update({
'periods_overlaps': 'You can not have two overlapping periods!',
})
def check_dates(self, ids):
cursor = Transaction().cursor
for period in self.browse(ids):
cursor.execute('SELECT id ' \
'FROM "' + self._table + '" ' \
'WHERE ((start_date <= %s AND end_date >= %s) ' \
'OR (start_date <= %s AND end_date >= %s) ' \
'OR (start_date >= %s AND end_date <= %s)) ' \
'AND id != %s',
(period.start_date, period.start_date,
period.end_date, period.end_date,
period.start_date, period.end_date,
period.id))
if cursor.fetchone():
return False
return True
WorkPeriod()
class Project(ModelSQL, ModelView):
"""
Tryton itself is very flexible in allowing multiple layers of Projects and
@ -239,7 +279,6 @@ class Project(ModelSQL, ModelView):
'invisible': Eval('type') != 'task',
'readonly': Eval('type') != 'task',
}
)
#: Get all the attachments on the object and return them
@ -248,7 +287,24 @@ class Project(ModelSQL, ModelView):
'get_attachments'
)
#TODO: Add a field for computed state
progress_state = fields.Selection([
('Backlog', 'Backlog'),
('Planning', 'Planning'),
('In Progress', 'In Progress'),
], 'Progress State', depends=['state', 'type'], select=True,
states={
'invisible': (Eval('type') != 'task') | (Eval('state') != 'opened'),
'readonly': (Eval('type') != 'task') | (Eval('state') != 'opened'),
}
)
work_period = fields.Many2One(
'project.work.period', 'Work Period',
states={
'invisible': Eval('type') != 'task',
'readonly': Eval('type') != 'task',
}, select=True
)
def __init__(self):
super(Project, self).__init__()

View File

@ -13,6 +13,10 @@ of this repository contains the full copyright notices and license terms. -->
position="before">
<label name="assigned_to"/>
<field name="assigned_to"/>
<label name="progress_state"/>
<field name="progress_state"/>
<label name="work_period"/>
<field name="work_period"/>
</xpath>
<xpath expr="/form/notebook" position="inside">
<page string="Participants" id="project_participants">
@ -31,6 +35,60 @@ of this repository contains the full copyright notices and license terms. -->
]]>
</field>
</record>
<!--Work Period-->
<record model="ir.ui.view" id="work_period_form">
<field name="model">project.work.period</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="Work Period">
<label name="name" />
<field name="name" />
<newline/>
<label name="start_date" />
<field name="start_date" />
<label name="end_date" />
<field name="end_date" />
</form>
]]>
</field>
</record>
<record model="ir.ui.view" id="work_period_view_tree">
<field name="model">project.work.period</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<![CDATA[
<tree string="Work Periods">
<field name="name" />
<field name="start_date" />
<field name="end_date" />
</tree>
]]>
</field>
</record>
<record model="ir.action.act_window" id="act_work_period_form">
<field name="name">Work Periods</field>
<field name="res_model">project.work.period</field>
</record>
<record model="ir.action.act_window.view" id="act_work_period_form_view1">
<field name="sequence" eval="10" />
<field name="view" ref="work_period_view_tree" />
<field name="act_window" ref="act_work_period_form" />
</record>
<record model="ir.action.act_window.view" id="act_work_period_form_view2">
<field name="sequence" eval="20" />
<field name="view" ref="work_period_form" />
<field name="act_window" ref="act_work_period_form" />
</record>
<menuitem parent="project.menu_project" action="act_work_period_form"
id="menu_work_period" sequence="100" />
</data>
</tryton>