Improvement on timesheet work:
- removed state and type fields - added timesheet_available and company fields - childs is now children
This commit is contained in:
1 parent
5e40757c9d
commit
cb0360316a
3 files changed
+59
-35
No files matched your search
@@ -16,8 +16,7 @@ class Line(ModelSQL, ModelView):
|
||||
hours = fields.Float('Hours', digits=(16, 2), required=True)
|
||||
work = fields.Many2One('timesheet.work', 'Work',
|
||||
required=True, select=1, domain=[
|
||||
('type', '!=', 'view'),
|
||||
('state', '!=', 'closed'),
|
||||
('timesheet_available', '=', 'True'),
|
||||
])
|
||||
description = fields.Char('Description')
|
||||
|
||||
|
||||
@@ -13,43 +13,52 @@ class Work(ModelSQL, ModelView):
|
||||
name = fields.Char('Name', required=True)
|
||||
active = fields.Boolean('Active')
|
||||
parent = fields.Many2One('timesheet.work', 'Parent', select=2)
|
||||
childs = fields.One2Many('timesheet.work', 'parent', 'Children')
|
||||
hours = fields.Function('get_hours', digits=(16, 2), string='Hours')
|
||||
type = fields.Selection([
|
||||
('view', 'View'),
|
||||
('normal', 'Normal'),
|
||||
], 'Type', required=True, select=1)
|
||||
state = fields.Selection([
|
||||
('opened', 'Opened'),
|
||||
('closed', 'Closed'),
|
||||
], 'State', required=True, select=1)
|
||||
children = fields.One2Many('timesheet.work', 'parent', 'Children')
|
||||
hours = fields.Function('get_hours', digits=(16, 2), string='Timesheet Hours')
|
||||
timesheet_available = fields.Boolean('Available on timesheets')
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
|
||||
def __init__(self):
|
||||
super(Work, self).__init__()
|
||||
self._constraints += [
|
||||
('check_recursion', 'recursive_works'),
|
||||
('check_parent_company', 'parent_company'),
|
||||
]
|
||||
self._error_messages.update({
|
||||
'recursive_works': 'You can not create recursive works!',
|
||||
'parent_company': 'Every work must be in the same company '\
|
||||
'as it\'s parent work!',
|
||||
})
|
||||
|
||||
def default_active(self, cursor, user, context=None):
|
||||
return True
|
||||
|
||||
def default_type(self, cursor, user, context=None):
|
||||
return 'normal'
|
||||
def default_timesheet_available(self, cursor, user, context=None):
|
||||
return True
|
||||
|
||||
def default_state(self, cursor, user, context=None):
|
||||
return 'opened'
|
||||
def default_company(self, cursor, user, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context.get('company'):
|
||||
return context['company']
|
||||
return False
|
||||
|
||||
def _tree_qty(self, hours_by_wt, childs, ids, to_compute):
|
||||
def check_parent_company(self, cursor, user, ids):
|
||||
for work in self.browse(cursor, user, ids):
|
||||
if not work.parent:
|
||||
continue
|
||||
if work.parent.company.id != work.company.id:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _tree_qty(self, hours_by_wt, children, ids, to_compute):
|
||||
res = 0
|
||||
for h in ids:
|
||||
if (not childs.get(h)) or (not to_compute[h]):
|
||||
if (not children.get(h)) or (not to_compute[h]):
|
||||
res += hours_by_wt.setdefault(h, 0)
|
||||
else:
|
||||
sub_qty = self._tree_qty(
|
||||
hours_by_wt, childs, childs[h], to_compute)
|
||||
hours_by_wt, children, children[h], to_compute)
|
||||
hours_by_wt.setdefault(h, 0)
|
||||
hours_by_wt[h] += sub_qty
|
||||
res += hours_by_wt[h]
|
||||
@@ -76,11 +85,11 @@ class Work(ModelSQL, ModelView):
|
||||
hours_by_wt = dict([(i[0], i[1]) for i in cursor.fetchall()])
|
||||
to_compute = dict.fromkeys(all_ids, True)
|
||||
works = self.browse(cursor, user, all_ids, context=context)
|
||||
childs = {}
|
||||
children = {}
|
||||
for work in works:
|
||||
if work.parent:
|
||||
childs.setdefault(work.parent.id, []).append(work.id)
|
||||
self._tree_qty(hours_by_wt, childs, ids, to_compute)
|
||||
children.setdefault(work.parent.id, []).append(work.id)
|
||||
self._tree_qty(hours_by_wt, children, ids, to_compute)
|
||||
return hours_by_wt
|
||||
|
||||
def get_rec_name(self, cursor, user, ids, name, arg, context=None):
|
||||
|
||||
@@ -11,16 +11,14 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<form string="Work">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="state"/>
|
||||
<group col="3" colspan="1" id="state_active">
|
||||
<field name="state"/>
|
||||
<label name="active"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
<label name="active"/>
|
||||
<field name="active"/>
|
||||
<label name="parent"/>
|
||||
<field name="parent"/>
|
||||
<label name="type"/>
|
||||
<field name="type"/>
|
||||
<label name="timesheet_available"/>
|
||||
<field name="timesheet_available"/>
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
@@ -33,7 +31,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<![CDATA[
|
||||
<tree string="Works">
|
||||
<field name="rec_name"/>
|
||||
<field name="state" select="1"/>
|
||||
<field name="name" select="1" tree_invisible="1"/>
|
||||
<field name="active" select="1" tree_invisible="1"/>
|
||||
</tree>
|
||||
@@ -63,13 +60,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="model">timesheet.work</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="16"/>
|
||||
<field name="field_childs">childs</field>
|
||||
<field name="field_childs">children</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Works">
|
||||
<field name="name" select="1"/>
|
||||
<field name="type" select="1"/>
|
||||
<field name="state" select="1"/>
|
||||
<field name="timesheet_available" select="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
@@ -93,7 +89,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="model">timesheet.work</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="16"/>
|
||||
<field name="field_childs">childs</field>
|
||||
<field name="field_childs">children</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Works">
|
||||
@@ -208,5 +204,25 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_work">
|
||||
<field name="model" search="[('model', '=', 'timesheet.work')]"/>
|
||||
<field name="global_p" eval="False"/>
|
||||
<field name="default_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_work1">
|
||||
<field name="field" search="[('name', '=', 'company'),
|
||||
('model.model', '=', 'timesheet.work')]"/>
|
||||
<field name="operator">=</field>
|
||||
<field name="operand">User/Main Company</field>
|
||||
<field name="rule_group" ref="rule_group_work"/>
|
||||
</record>
|
||||
<record model="ir.rule.group" id="rule_group_work_admin">
|
||||
<field name="model" search="[('model', '=', 'timesheet.work')]"/>
|
||||
<field name="global_p" eval="False"/>
|
||||
<field name="default_p" eval="False"/>
|
||||
<field name="groups" eval="[('add', ref('group_timesheet_admin'))]"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
Reference in new issue
Block a user