[IMP] hr_contract: added override of base_action_rule (+ dependency) to add the possibility to use a user-related working scheduling.
bzr revid: tde@openerp.com-20130902134200-xvy5hb7lqv2wv0um
This commit is contained in:
parent
2cdefa52ef
commit
6e1cb5226b
|
@ -240,6 +240,18 @@ class base_action_rule(osv.osv):
|
|||
data.update({'model': model.model})
|
||||
return {'value': data}
|
||||
|
||||
def _check_delay(self, cr, uid, action, record, record_dt, context=None):
|
||||
if action.trg_date_calendar_id and action.trg_date_range_type == 'day':
|
||||
start_dt = get_datetime(record_dt)
|
||||
action_dt = self.pool['resource.calendar'].schedule_days_get_date(
|
||||
cr, uid, action.trg_date_calendar_id.id, action.trg_date_range,
|
||||
day_date=start_dt, compute_leaves=True, context=context
|
||||
)
|
||||
else:
|
||||
delay = DATE_RANGE_FUNCTION[action.trg_date_range_type](action.trg_date_range)
|
||||
action_dt = get_datetime(record_dt) + delay
|
||||
return action_dt
|
||||
|
||||
def _check(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
|
||||
""" This Function is called by scheduler. """
|
||||
context = context or {}
|
||||
|
@ -266,21 +278,12 @@ class base_action_rule(osv.osv):
|
|||
else:
|
||||
get_record_dt = lambda record: record[date_field]
|
||||
|
||||
delay = DATE_RANGE_FUNCTION[action.trg_date_range_type](action.trg_date_range)
|
||||
|
||||
# process action on the records that should be executed
|
||||
for record in model.browse(cr, uid, record_ids, context=context):
|
||||
record_dt = get_record_dt(record)
|
||||
if not record_dt:
|
||||
continue
|
||||
if action.trg_date_calendar_id and action.trg_date_range_type == 'day':
|
||||
start_dt = get_datetime(record_dt)
|
||||
action_dt = self.pool['resource.calendar'].schedule_days(
|
||||
cr, uid, action.trg_date_calendar_id.id, action.trg_date_range,
|
||||
date=start_dt, compute_leaves=True
|
||||
)
|
||||
else:
|
||||
action_dt = get_datetime(record_dt) + delay
|
||||
action_dt = self._check_delay(cr, uid, action, record, record_dt, context=context)
|
||||
if last_run and (last_run <= action_dt < now) or (action_dt < now):
|
||||
try:
|
||||
self._process(cr, uid, action, [record.id], context=context)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
# Copyright (C) 2004-Today OpenERP SA (<http://www.openerp.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
|
||||
|
@ -20,6 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
import hr_contract
|
||||
import base_action_rule
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -38,11 +38,12 @@ You can assign several contracts per employee.
|
|||
'author': 'OpenERP SA',
|
||||
'website': 'http://www.openerp.com',
|
||||
'images': ['images/hr_contract.jpeg'],
|
||||
'depends': ['hr'],
|
||||
'depends': ['base_action_rule', 'hr'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'hr_contract_view.xml',
|
||||
'hr_contract_data.xml'
|
||||
'hr_contract_data.xml',
|
||||
'base_action_rule_view.xml',
|
||||
],
|
||||
'demo': [],
|
||||
'test': ['test/test_hr_contract.yml'],
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Business Applications
|
||||
# Copyright (c) 2013 OpenERP S.A. <http://www.openerp.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 openerp.addons.base_action_rule.base_action_rule import get_datetime
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
|
||||
class base_action_rule(osv.Model):
|
||||
""" Add resource and calendar for time-based conditions """
|
||||
_name = 'base.action.rule'
|
||||
_inherit = ['base.action.rule']
|
||||
|
||||
_columns = {
|
||||
'trg_date_resource_field_id': fields.many2one(
|
||||
'ir.model.fields', 'User related field',
|
||||
help='Use the user\'s working schedule.',
|
||||
),
|
||||
}
|
||||
|
||||
def _check_delay(self, cr, uid, action, record, record_dt, context=None):
|
||||
""" Override the check of delay to try to use a user-related calendar.
|
||||
If no calendar is found, fallback on the default behavior. """
|
||||
if action.trg_date_calendar_id and action.trg_date_range_type == 'day' and action.trg_date_resource_field_id:
|
||||
user = record[action.trg_date_resource_field_id.name]
|
||||
if user.employee_ids and user.employee_ids[0].contract_id \
|
||||
and user.employee_ids[0].contract_id.working_hours:
|
||||
calendar = user.employee_ids[0].contract_id.working_hours
|
||||
start_dt = get_datetime(record_dt)
|
||||
action_dt = self.pool['resource.calendar'].schedule_days_get_date(
|
||||
cr, uid, calendar.id, action.trg_date_range,
|
||||
day_date=start_dt, compute_leaves=True, context=context
|
||||
)
|
||||
return action_dt
|
||||
return super(base_action_rule, self)._check_delay(cr, uid, action, record, record_dt, context=context)
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="view_base_action_rule_form_resource">
|
||||
<field name="name">base.action.rule.form</field>
|
||||
<field name="model">base.action.rule</field>
|
||||
<field name="inherit_id" ref="base_action_rule.view_base_action_rule_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='trg_date_calendar_id']" position="before">
|
||||
<field name="trg_date_resource_field_id"
|
||||
domain="[('model_id', '=', model_id), ('relation', '=', 'res.users'), ('ttype', 'in', ['many2one'])]"
|
||||
attrs="{'invisible': ['|', ('trg_date_id','=',False), ('trg_date_range_type', '!=', 'day')]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -481,7 +481,7 @@ class resource_calendar(osv.osv):
|
|||
"""Wrapper on _schedule_days: return the beginning/ending datetime of
|
||||
a days scheduling. """
|
||||
res = self._schedule_days(cr, uid, id, days, day_date, compute_leaves, resource_id, context)
|
||||
return res[-1][1].date()
|
||||
return res[-1][1]
|
||||
|
||||
def schedule_days(self, cr, uid, id, days, day_date=None, compute_leaves=False, resource_id=None, context=None):
|
||||
"""Wrapper on _schedule_days: return the working intervals of a days
|
||||
|
|
|
@ -60,12 +60,13 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Working Time" version="7.0">
|
||||
<sheet>
|
||||
<group col="4">
|
||||
<field name="name"/>
|
||||
<field name="manager"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<field name="attendance_ids"/>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="manager"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<field name="attendance_ids"/>
|
||||
<field name="leave_ids"/>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -245,14 +246,17 @@
|
|||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_resource_calendar_leave_tree" model="ir.actions.act_window">
|
||||
<field name="name">Resource Leaves</field>
|
||||
<field name="res_model">resource.calendar.leaves</field>
|
||||
<field name="view_mode">tree,form,calendar</field>
|
||||
<field name="search_view_id" ref="view_resource_calendar_leaves_search"/>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_resource_config" name="Resource" parent="base.next_id_4" sequence="5"/>
|
||||
<menuitem action="resource.action_resource_calendar_leave_tree" id="menu_view_resource_calendar_leaves_search" parent="menu_resource_config" sequence="1"/>
|
||||
<menuitem action="resource.action_resource_calendar_form" id="menu_view_resource_calendar_search" parent="menu_resource_config" sequence="1"/>
|
||||
<menuitem action="resource.action_resource_calendar_form" id="menu_resource_calendar" parent="menu_resource_config" sequence="1"/>
|
||||
<menuitem action="resource.action_resource_calendar_leave_tree" id="menu_resource_calendar_leaves" parent="menu_resource_config" sequence="1"/>
|
||||
<menuitem action="resource.action_resource_resource_tree" id="menu_resource_resource" parent="menu_resource_config" sequence="1"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -367,16 +367,16 @@ class TestResource(TestResourceCommon):
|
|||
self.assertEqual(td.total_seconds() / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
|
||||
|
||||
res = self.resource_calendar._interval_hours_get(cr, uid, self.calendar_id, self.date1.replace(hour=6, minute=0), self.date2.replace(hour=23, minute=0) + relativedelta(days=7), resource_id=self.resource1_id, exclude_leaves=False)
|
||||
print res
|
||||
# print res
|
||||
|
||||
res = self.resource_calendar.get_working_hours(cr, uid, self.calendar_id, self.date1.replace(hour=6, minute=0), self.date2.replace(hour=23, minute=0) + relativedelta(days=7), compute_leaves=False, resource_id=self.resource1_id)
|
||||
print res
|
||||
# print res
|
||||
|
||||
res = self.resource_calendar._interval_hours_get(cr, uid, self.calendar_id, self.date1.replace(hour=6, minute=0), self.date2.replace(hour=23, minute=0) + relativedelta(days=7), resource_id=self.resource1_id, exclude_leaves=True)
|
||||
print res
|
||||
# print res
|
||||
|
||||
res = self.resource_calendar.get_working_hours(cr, uid, self.calendar_id, self.date1.replace(hour=6, minute=0), self.date2.replace(hour=23, minute=0) + relativedelta(days=7), compute_leaves=True, resource_id=self.resource1_id)
|
||||
print res
|
||||
# print res
|
||||
|
||||
def test_50_calendar_schedule_days(self):
|
||||
""" Testing calendar days scheduling """
|
||||
|
@ -384,12 +384,12 @@ class TestResource(TestResourceCommon):
|
|||
_format = '%Y-%m-%d %H:%M:%S'
|
||||
|
||||
res = self.resource_calendar.schedule_days_get_date(cr, uid, self.calendar_id, 5, day_date=self.date1)
|
||||
self.assertEqual(res, datetime.strptime('2013-02-26 00:0:00', _format).date(), 'resource_calendar: wrong days scheduling')
|
||||
self.assertEqual(res.date(), datetime.strptime('2013-02-26 00:0:00', _format).date(), 'resource_calendar: wrong days scheduling')
|
||||
|
||||
res = self.resource_calendar.schedule_days_get_date(
|
||||
cr, uid, self.calendar_id, 5, day_date=self.date1,
|
||||
compute_leaves=True, resource_id=self.resource1_id)
|
||||
self.assertEqual(res, datetime.strptime('2013-03-01 00:0:00', _format).date(), 'resource_calendar: wrong days scheduling')
|
||||
self.assertEqual(res.date(), datetime.strptime('2013-03-01 00:0:00', _format).date(), 'resource_calendar: wrong days scheduling')
|
||||
|
||||
# --------------------------------------------------
|
||||
# Misc
|
||||
|
|
Loading…
Reference in New Issue