[IMP] base_action_rule - Allow using any object dates as a triggering date

bzr revid: yannick.vaucher@camptocamp.com-20120510135020-x7m08ojkxjzy4fs9
This commit is contained in:
Yannick Vaucher 2012-05-10 15:50:20 +02:00
parent 02200ffe30
commit 16e8bdc6b2
2 changed files with 21 additions and 30 deletions

View File

@ -79,13 +79,10 @@ class base_action_rule(osv.osv):
it will allow you to hide the rule without removing it."), it will allow you to hide the rule without removing it."),
'sequence': fields.integer('Sequence', help="Gives the sequence order \ 'sequence': fields.integer('Sequence', help="Gives the sequence order \
when displaying a list of rules."), when displaying a list of rules."),
'trg_date_type': fields.selection([ 'trg_date_id': fields.many2one('ir.model.fields',
('none', 'None'), 'Trigger Date',
('create', 'Creation Date'), domain="[('model_id', '=', model_id),"
('action_last', 'Last Action Date'), "('ttype','in',('date','datetime'))]"),
('date', 'Date'),
('deadline', 'Deadline'),
], 'Trigger Date', size=16),
'trg_date_range': fields.integer('Delay after trigger date', \ 'trg_date_range': fields.integer('Delay after trigger date', \
help="Delay After Trigger Date,\ help="Delay After Trigger Date,\
specifies you can put a negative number. If you need a delay before the \ specifies you can put a negative number. If you need a delay before the \
@ -132,7 +129,6 @@ the rule to mark CC(mail to any other person defined in actions)."),
_defaults = { _defaults = {
'active': lambda *a: True, 'active': lambda *a: True,
'trg_date_type': lambda *a: 'none',
'trg_date_range_type': lambda *a: 'day', 'trg_date_range_type': lambda *a: 'day',
'act_mail_to_user': lambda *a: 0, 'act_mail_to_user': lambda *a: 0,
'act_remind_partner': lambda *a: 0, 'act_remind_partner': lambda *a: 0,
@ -168,7 +164,7 @@ the rule to mark CC(mail to any other person defined in actions)."),
obj = self.pool.get(obj_name) obj = self.pool.get(obj_name)
# If the rule doesn't involve a time condition, run it immediately # If the rule doesn't involve a time condition, run it immediately
# Otherwise we let the scheduler run the action # Otherwise we let the scheduler run the action
if self.browse(cr, uid, rule_id, context=context).trg_date_type == 'none': if not self.browse(cr, uid, rule_id, context=context).trg_date_id:
self._action(cr, uid, [rule_id], obj.browse(cr, uid, ids, context=context), context=context) self._action(cr, uid, [rule_id], obj.browse(cr, uid, ids, context=context), context=context)
return True return True
@ -230,7 +226,7 @@ the rule to mark CC(mail to any other person defined in actions)."),
def _check(self, cr, uid, automatic=False, use_new_cursor=False, \ def _check(self, cr, uid, automatic=False, use_new_cursor=False, \
context=None): context=None):
""" """
This Function is call by scheduler. This Function is called by scheduler.
""" """
rule_pool = self.pool.get('base.action.rule') rule_pool = self.pool.get('base.action.rule')
rule_ids = rule_pool.search(cr, uid, [], context=context) rule_ids = rule_pool.search(cr, uid, [], context=context)
@ -248,22 +244,17 @@ the rule to mark CC(mail to any other person defined in actions)."),
obj = model_pool.browse(cr, uid, obj_id, context=context) obj = model_pool.browse(cr, uid, obj_id, context=context)
# Calculate when this action should next occur for this object # Calculate when this action should next occur for this object
base = False base = False
if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): if rule.trg_date_id:
base = obj.create_date date_type = rule.trg_date_id.name
elif (rule.trg_date_type=='action_last' if (date_type=='date_action_last'
and hasattr(obj, 'create_date')): and hasattr(obj, 'create_date')):
if hasattr(obj, 'date_action_last') and obj.date_action_last: if hasattr(obj, 'date_action_last') and obj.date_action_last:
base = obj.date_action_last base = obj.date_action_last
else: else:
base = obj.create_date base = obj.create_date
elif (rule.trg_date_type=='deadline' elif (hasattr(obj, date_type)
and hasattr(obj, 'date_deadline') and obj.read([date_type])[0][date_type]):
and obj.date_deadline): base = obj.read([date_type])[0][date_type]
base = obj.date_deadline
elif (rule.trg_date_type=='date'
and hasattr(obj, 'date')
and obj.date):
base = obj.date
if base: if base:
fnct = { fnct = {
'minutes': lambda interval: timedelta(minutes=interval), 'minutes': lambda interval: timedelta(minutes=interval),

View File

@ -39,8 +39,8 @@
</group> </group>
<group col="2" colspan="2"> <group col="2" colspan="2">
<separator colspan="4" string="Conditions on Timing"/> <separator colspan="4" string="Conditions on Timing"/>
<field name="trg_date_type"/> <field name="trg_date_id"/>
<group col="3" colspan="2" attrs="{'invisible': [('trg_date_type', '=', 'none')]}"> <group col="3" colspan="2" attrs="{'invisible': [('trg_date_id', '=', 'none')]}">
<field name="trg_date_range" string="Delay After Trigger Date"/> <field name="trg_date_range" string="Delay After Trigger Date"/>
<field name="trg_date_range_type" nolabel="1"/> <field name="trg_date_range_type" nolabel="1"/>
</group> </group>