[MERGE] lp:~c2c/openobject-addons/trunk-trg_dates-base_action-rule-20120510
replace the field 'trg_date_type' by a many2one field to ir.model.fields bzr revid: rco@openerp.com-20121221113957-gd1c80h4vszg1h4g
This commit is contained in:
commit
375a5820ae
|
@ -29,14 +29,6 @@ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
DATE_TYPE_TO_FIELD = {
|
|
||||||
'create': 'create_date',
|
|
||||||
'write': 'write_date',
|
|
||||||
'action_last': 'date_action_last',
|
|
||||||
'date': 'date',
|
|
||||||
'deadline': 'date_deadline',
|
|
||||||
}
|
|
||||||
|
|
||||||
DATE_RANGE_FUNCTION = {
|
DATE_RANGE_FUNCTION = {
|
||||||
'minutes': lambda interval: timedelta(minutes=interval),
|
'minutes': lambda interval: timedelta(minutes=interval),
|
||||||
'hour': lambda interval: timedelta(hours=interval),
|
'hour': lambda interval: timedelta(hours=interval),
|
||||||
|
@ -69,14 +61,8 @@ class base_action_rule(osv.osv):
|
||||||
help="When unchecked, the rule is hidden and will not be executed."),
|
help="When unchecked, the rule is hidden and will not be executed."),
|
||||||
'sequence': fields.integer('Sequence',
|
'sequence': fields.integer('Sequence',
|
||||||
help="Gives the sequence order when displaying a list of rules."),
|
help="Gives the sequence order when displaying a list of rules."),
|
||||||
'trg_date_type': fields.selection([
|
'trg_date_id': fields.many2one('ir.model.fields', string='Trigger Date',
|
||||||
('none', 'None'),
|
domain="[('model_id', '=', model_id), ('ttype', 'in', ('date', 'datetime'))]"),
|
||||||
('create', 'Creation Date'),
|
|
||||||
('write', 'Last Modified Date'),
|
|
||||||
('action_last', 'Last Action Date'),
|
|
||||||
('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 the trigger date." \
|
help="Delay after the trigger date." \
|
||||||
"You can put a negative number if you need a delay before the" \
|
"You can put a negative number if you need a delay before the" \
|
||||||
|
@ -101,7 +87,6 @@ class base_action_rule(osv.osv):
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'active': True,
|
'active': True,
|
||||||
'trg_date_type': 'none',
|
|
||||||
'trg_date_range_type': 'day',
|
'trg_date_range_type': 'day',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +142,7 @@ class base_action_rule(osv.osv):
|
||||||
|
|
||||||
new_id = old_create(cr, uid, vals, context=context)
|
new_id = old_create(cr, uid, vals, context=context)
|
||||||
# as it is a new record, we do not consider the actions that have a prefilter
|
# as it is a new record, we do not consider the actions that have a prefilter
|
||||||
action_dom = [('model', '=', model), ('trg_date_type', 'in', ('none', False)), ('filter_pre_id', '=', False)]
|
action_dom = [('model', '=', model), ('trg_date_id', '=', False), ('filter_pre_id', '=', False)]
|
||||||
action_ids = self.search(cr, uid, action_dom, context=context)
|
action_ids = self.search(cr, uid, action_dom, context=context)
|
||||||
# check postconditions, and execute actions on the records that satisfy them
|
# check postconditions, and execute actions on the records that satisfy them
|
||||||
for action in self.browse(cr, uid, action_ids, context=context):
|
for action in self.browse(cr, uid, action_ids, context=context):
|
||||||
|
@ -177,7 +162,7 @@ class base_action_rule(osv.osv):
|
||||||
|
|
||||||
ids = [ids] if isinstance(ids, (int, long, str)) else ids
|
ids = [ids] if isinstance(ids, (int, long, str)) else ids
|
||||||
# retrieve the action rules to possibly execute
|
# retrieve the action rules to possibly execute
|
||||||
action_dom = [('model', '=', model), ('trg_date_type', 'in', ('none', False))]
|
action_dom = [('model', '=', model), ('trg_date_id', '=', False)]
|
||||||
action_ids = self.search(cr, uid, action_dom, context=context)
|
action_ids = self.search(cr, uid, action_dom, context=context)
|
||||||
actions = self.browse(cr, uid, action_ids, context=context)
|
actions = self.browse(cr, uid, action_ids, context=context)
|
||||||
# check preconditions
|
# check preconditions
|
||||||
|
@ -225,8 +210,8 @@ class base_action_rule(osv.osv):
|
||||||
def _check(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
|
def _check(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
|
||||||
""" This Function is called by scheduler. """
|
""" This Function is called by scheduler. """
|
||||||
context = context or {}
|
context = context or {}
|
||||||
# retrieve all the action rules that have a trg_date_type and no precondition
|
# retrieve all the action rules that have a trg_date_id and no precondition
|
||||||
action_dom = [('trg_date_type', 'not in', ('none', False)), ('filter_pre_id', '=', False)]
|
action_dom = [('trg_date_id', '!=', False), ('filter_pre_id', '=', False)]
|
||||||
action_ids = self.search(cr, uid, action_dom, context=context)
|
action_ids = self.search(cr, uid, action_dom, context=context)
|
||||||
for action in self.browse(cr, uid, action_ids, context=context):
|
for action in self.browse(cr, uid, action_ids, context=context):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
@ -242,14 +227,20 @@ class base_action_rule(osv.osv):
|
||||||
record_ids = model.search(cr, uid, domain, context=ctx)
|
record_ids = model.search(cr, uid, domain, context=ctx)
|
||||||
|
|
||||||
# determine when action should occur for the records
|
# determine when action should occur for the records
|
||||||
date_field = DATE_TYPE_TO_FIELD.get(action.trg_date_type)
|
date_field = action.trg_date_id.name
|
||||||
if date_field not in model._all_columns:
|
if date_field == 'date_action_last' and 'create_date' in model._all_columns:
|
||||||
continue
|
get_record_dt = lambda record: record[date_field] or record.create_date
|
||||||
|
else:
|
||||||
|
get_record_dt = lambda record: record[date_field]
|
||||||
|
|
||||||
delay = DATE_RANGE_FUNCTION[action.trg_date_range_type](action.trg_date_range)
|
delay = DATE_RANGE_FUNCTION[action.trg_date_range_type](action.trg_date_range)
|
||||||
|
|
||||||
# process action on the records that should be executed
|
# process action on the records that should be executed
|
||||||
for record in model.browse(cr, uid, record_ids, context=context):
|
for record in model.browse(cr, uid, record_ids, context=context):
|
||||||
action_dt = get_datetime(record[date_field]) + delay
|
record_dt = get_record_dt(record)
|
||||||
|
if not record_dt:
|
||||||
|
continue
|
||||||
|
action_dt = get_datetime(record_dt) + delay
|
||||||
if last_run and (last_run <= action_dt < now) or (action_dt < now):
|
if last_run and (last_run <= action_dt < now) or (action_dt < now):
|
||||||
try:
|
try:
|
||||||
self._process(cr, uid, action, [record.id], context=context)
|
self._process(cr, uid, action, [record.id], context=context)
|
||||||
|
|
|
@ -35,9 +35,12 @@
|
||||||
<field name="filter_id" domain="[('model_id','=',model), ('user_id', '=', False)]" context="{'default_model_id': model}"/>
|
<field name="filter_id" domain="[('model_id','=',model), ('user_id', '=', False)]" context="{'default_model_id': model}"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="timing" string="Timer">
|
<group name="timing" string="Timer">
|
||||||
<field name="trg_date_type"/>
|
<field name="trg_date_id"/>
|
||||||
<field name="trg_date_range" string="Delay After Trigger Date" attrs="{'invisible': [('trg_date_type', '=', 'none')]}"/>
|
<label string="Delay After Trigger Date" attrs="{'invisible': [('trg_date_id','=',False)]}"/>
|
||||||
<field name="trg_date_range_type" attrs="{'invisible': [('trg_date_type', '=', 'none')]}"/>
|
<div attrs="{'invisible': [('trg_date_id','=',False)]}">
|
||||||
|
<field name="trg_date_range"/>
|
||||||
|
<field name="trg_date_range_type" attrs="{'required': [('trg_date_id','!=',False)]}"/>
|
||||||
|
</div>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
|
|
@ -48,7 +48,6 @@ class base_action_rule_test(common.TransactionCase):
|
||||||
'name' : "Rule 1",
|
'name' : "Rule 1",
|
||||||
'model_id': self.registry('ir.model').search(cr, uid, [('model','=','base.action.rule.lead.test')], context=context)[0],
|
'model_id': self.registry('ir.model').search(cr, uid, [('model','=','base.action.rule.lead.test')], context=context)[0],
|
||||||
'active' : 1,
|
'active' : 1,
|
||||||
'trg_date_type' : 'none',
|
|
||||||
'filter_pre_id' : filter_pre_id,
|
'filter_pre_id' : filter_pre_id,
|
||||||
'filter_id' : filter_id,
|
'filter_id' : filter_id,
|
||||||
'act_user_id': self.demo,
|
'act_user_id': self.demo,
|
||||||
|
|
|
@ -27,7 +27,7 @@ Description: [[object.description]]
|
||||||
<field name="model_id" ref="model_crm_lead"/>
|
<field name="model_id" ref="model_crm_lead"/>
|
||||||
<field name="sequence">1</field>
|
<field name="sequence">1</field>
|
||||||
<field name="filter_id" ref="filter_draft_lead"/>
|
<field name="filter_id" ref="filter_draft_lead"/>
|
||||||
<field name="trg_date_type">create</field>
|
<field name="trg_date_id" ref="field_crm_lead_create_date"/>
|
||||||
<field name="trg_date_range">5</field>
|
<field name="trg_date_range">5</field>
|
||||||
<field name="trg_date_range_type">day</field>
|
<field name="trg_date_range_type">day</field>
|
||||||
<field name="server_action_ids" eval="[(6,0,[ref('action_email_reminder_lead')])]"/>
|
<field name="server_action_ids" eval="[(6,0,[ref('action_email_reminder_lead')])]"/>
|
||||||
|
@ -57,7 +57,7 @@ object.write({'section_id': sales_team.id})
|
||||||
<field name="filter_id" ref="filter_usa_lead"/>
|
<field name="filter_id" ref="filter_usa_lead"/>
|
||||||
<field name="act_followers" eval="[(6,0,[ref('base.res_partner_4'), ref('base.res_partner_5'), ref('base.res_partner_6')])]"/>
|
<field name="act_followers" eval="[(6,0,[ref('base.res_partner_4'), ref('base.res_partner_5'), ref('base.res_partner_6')])]"/>
|
||||||
<field name="act_user_id" ref="base.user_root"/>
|
<field name="act_user_id" ref="base.user_root"/>
|
||||||
<field name="trg_date_type">create</field>
|
<field name="trg_date_id" ref="field_crm_lead_create_date"/>
|
||||||
<field name="trg_date_range">0</field>
|
<field name="trg_date_range">0</field>
|
||||||
<field name="trg_date_range_type">minutes</field>
|
<field name="trg_date_range_type">minutes</field>
|
||||||
<field name="server_action_ids" eval="[(6,0,[ref('action_set_team_sales_department')])]"/>
|
<field name="server_action_ids" eval="[(6,0,[ref('action_set_team_sales_department')])]"/>
|
||||||
|
|
Loading…
Reference in New Issue