From 33cb2c8c9a87e68ab9da02a95372af5ac63ea399 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 13 Sep 2010 02:43:37 +0200 Subject: [PATCH] [IMP] marketing_campaign: another round of reviewing/improvements: - better form/search views - improved labels - added next sync on segments - added domain to prevent cross-campaign transitions on activities - ... bzr revid: odo@openerp.com-20100913004337-0cvl8qd0qaj3fomc --- .../marketing_campaign/marketing_campaign.py | 35 ++--- .../marketing_campaign_data.xml | 8 +- .../marketing_campaign_view.xml | 123 ++++++++++-------- 3 files changed, 89 insertions(+), 77 deletions(-) diff --git a/addons/marketing_campaign/marketing_campaign.py b/addons/marketing_campaign/marketing_campaign.py index c9383b53b15..4fd4fda5253 100644 --- a/addons/marketing_campaign/marketing_campaign.py +++ b/addons/marketing_campaign/marketing_campaign.py @@ -135,12 +135,12 @@ Normal - the campaign runs normally and automatically sends all emails and repor if activity.type != 'email': continue if not activity.email_template_id.from_account: - raise osv.except_osv(_("Error"), _("The campaign cannot be started: an email account is missing in the email activity '%s'")%activity.name) + raise osv.except_osv(_("Error"), _("The campaign cannot be started: the email account is missing in email activity '%s'")%activity.name) if activity.email_template_id.from_account.state != 'approved': - raise osv.except_osv(_("Error"), _("The campaign cannot be started: the email account is not approved in the email activity '%s'")%activity.name) + raise osv.except_osv(_("Error"), _("The campaign cannot be started: the email account is not approved in email activity '%s'")%activity.name) if not has_start and not has_signal_without_from: - raise osv.except_osv(_("Error"), _("The campaign hasn't any starting activity nor any activity with a signal and no previous activity.")) + raise osv.except_osv(_("Error"), _("The campaign cannot be started: it doesn't have any starting activity (or any activity with a signal and no previous activity)")) return self.write(cr, uid, ids, {'state': 'running'}) @@ -213,27 +213,31 @@ class marketing_campaign_segment(osv.osv): _name = "marketing.campaign.segment" _description = "Campaign Segment" + def _get_next_sync(self, cr, uid, ids, fn, args, context=None): + # next auto sync date is same for all segments + sync_job = self.pool.get('ir.model.data').get_object(cr, uid, 'marketing_campaign', 'ir_cron_marketing_campaign_every_day', context=context) + next_sync = sync_job and sync_job.nextcall or False + return dict.fromkeys(ids, next_sync) + _columns = { 'name': fields.char('Name', size=64,required=True), - 'campaign_id': fields.many2one('marketing.campaign', 'Campaign', - required=True, select=1, ondelete="cascade"), - 'object_id': fields.related('campaign_id','object_id', - type='many2one', relation='ir.model', - string='Object'), - 'ir_filter_id': fields.many2one('ir.filters', 'Filter', help="Filter to select the matching resource records that belong to this segment. New filters can be created and saved using the advanced search on the list view of the Resource"), + 'campaign_id': fields.many2one('marketing.campaign', 'Campaign', required=True, select=1, ondelete="cascade"), + 'object_id': fields.related('campaign_id','object_id', type='many2one', relation='ir.model', string='Resource'), + 'ir_filter_id': fields.many2one('ir.filters', 'Filter', help="Filter to select the matching resource records that belong to this segment. New filters can be created and saved using the advanced search on the list view of the Resource. If no filter is set, all records are selected without filtering. The synchronization mode may also add a criterion to the filter."), 'sync_last_date': fields.datetime('Last Synchronization', help="Date on which this segment was synchronized last time (automatically or manually)"), - 'sync_mode': fields.selection([('create_date', 'If record created after last sync'), - ('write_date', 'If record modified after last sync (no duplicates)'), + 'sync_mode': fields.selection([('create_date', 'Only records created after last sync'), + ('write_date', 'Only records modified after last sync (no duplicates)'), ('all', 'All records (no duplicates)')], - 'Workitem creation mode', - help="Determines how new campaign workitems are created for resource records matching this segment. This is used when segments are synchronized manually, or automatically via the scheduled job."), + 'Synchronization mode', + help="Determines an additional criterion to add to the filter when selecting new records to inject in the campaign."), 'state': fields.selection([('draft', 'Draft'), ('running', 'Running'), ('done', 'Done'), ('cancelled', 'Cancelled')], 'State',), - 'date_run': fields.datetime('Launching Date', help="Initial start date of this segment."), + 'date_run': fields.datetime('Launch Date', help="Initial start date of this segment."), 'date_done': fields.datetime('End Date', help="Date this segment was last closed or cancelled."), + 'date_next_sync': fields.function(_get_next_sync, method=True, string='Next Synchronization', type='datetime', help="Next time the synchronization job is scheduled to run automatically"), } _defaults = { @@ -264,7 +268,6 @@ class marketing_campaign_segment(osv.osv): if model_name: mod_name = model_name[0]['model'] res['domain'] = {'ir_filter_id': [('model_id', '=', mod_name)]} - res['context'] = {'default_model_id': model_name[0]['model']} else: res['value'] = {'ir_filter_id': False} return res @@ -594,7 +597,7 @@ class marketing_campaign_workitem(osv.osv): 'campaign_id': fields.related('activity_id', 'campaign_id', type='many2one', relation='marketing.campaign', string='Campaign', readonly=True, store=True), 'object_id': fields.related('activity_id', 'campaign_id', 'object_id', - type='many2one', relation='ir.model', string='Resource', select=1, readonly=True), + type='many2one', relation='ir.model', string='Resource', select=1, readonly=True, store=True), 'res_id': fields.integer('Resource ID', select=1, readonly=True), 'res_name': fields.function(_res_name_get, method=True, string='Resource Name', fnct_search=_resource_search, type="char", size=64), 'date': fields.datetime('Execution Date', help='If date is not set, this workitem has to be run manually', readonly=True), diff --git a/addons/marketing_campaign/marketing_campaign_data.xml b/addons/marketing_campaign/marketing_campaign_data.xml index 42ed4d12118..4f337b1d60e 100644 --- a/addons/marketing_campaign/marketing_campaign_data.xml +++ b/addons/marketing_campaign/marketing_campaign_data.xml @@ -5,7 +5,7 @@ - Check Marketing Campaign Activities + Marketing Campaign: Campaign workitems processing 1 hours -1 @@ -14,9 +14,9 @@ - + - Check Segment + Marketing Campaign: Segment Sync 1 days -1 @@ -25,6 +25,6 @@ - + diff --git a/addons/marketing_campaign/marketing_campaign_view.xml b/addons/marketing_campaign/marketing_campaign_view.xml index cbcb7fe1b76..7d1c8d3d2bf 100644 --- a/addons/marketing_campaign/marketing_campaign_view.xml +++ b/addons/marketing_campaign/marketing_campaign_view.xml @@ -32,14 +32,14 @@ - +