diff --git a/__init__.py b/__init__.py index 09f99957bf8b47495be9a3419aed420a29d25799_X19pbml0X18ucHk=..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_X19pbml0X18ucHk= 100644 --- a/__init__.py +++ b/__init__.py @@ -22,5 +22,7 @@ import trackitem import marketing_campaign_tracker +import wizard +import report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/__openerp__.py b/__openerp__.py index 09f99957bf8b47495be9a3419aed420a29d25799_X19vcGVuZXJwX18ucHk=..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_X19vcGVuZXJwX18ucHk= 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -29,6 +29,7 @@ "email_template", "decimal_precision", "marketing_campaign", + "base", ], "author": "XCG SAS", "category": 'Sales', @@ -40,4 +41,6 @@ 'init_xml': [], 'update_xml': [ 'marketing_campaign_tracker_view.xml', + 'wizard/wizard.xml', + 'report/analytic.xml', ], @@ -43,4 +46,5 @@ ], + 'js': ['static/src/js/report_analytic.js'], 'demo_xml': [ ], 'installable': True, diff --git a/marketing_campaign_tracker.py b/marketing_campaign_tracker.py index 09f99957bf8b47495be9a3419aed420a29d25799_bWFya2V0aW5nX2NhbXBhaWduX3RyYWNrZXIucHk=..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_bWFya2V0aW5nX2NhbXBhaWduX3RyYWNrZXIucHk= 100644 --- a/marketing_campaign_tracker.py +++ b/marketing_campaign_tracker.py @@ -59,4 +59,7 @@ trackitem_osv = self.pool.get( 'marketing_campaign_tracker.trackitem') + print "---------------------------" + print values.get('body') + print "---------------------------" new_body_text, tracks = insert_tracker_in_text( @@ -62,5 +65,9 @@ new_body_text, tracks = insert_tracker_in_text( - values.get('body'), tracker_base, context['activity_id']) + values.get('body'), tracker_base, context['activity_id'], + context['campaign_id']) + print "---------------------------" + print new_body_text + print "---------------------------" for trackvalues in tracks: # create a trackitem for each URL that is replaced @@ -68,4 +75,7 @@ values["body"] = new_body_text + print "---------------------------" + print values.get('body_html') + print "---------------------------" new_body_html, tracks = insert_tracker_in_html( @@ -71,5 +81,9 @@ new_body_html, tracks = insert_tracker_in_html( - values.get('body_html'), tracker_base, context['activity_id']) + values.get('body_html'), tracker_base, context['activity_id'], + context['campaign_id']) + print "---------------------------" + print new_body_html + print "---------------------------" for trackvalues in tracks: # create a trackitem for each URL that is replaced @@ -140,6 +154,7 @@ # and inject the necessary keys into our context context['tracker_base'] = activity.tracker_base.rstrip('/') context['activity_id'] = activity.id + context['campaign_id'] = activity.campaign_id.id return super(marketing_campaign_activity, self)._process_wi_email( cr, uid, activity, workitem, context=context diff --git a/marketing_campaign_tracker_view.xml b/marketing_campaign_tracker_view.xml index 09f99957bf8b47495be9a3419aed420a29d25799_bWFya2V0aW5nX2NhbXBhaWduX3RyYWNrZXJfdmlldy54bWw=..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_bWFya2V0aW5nX2NhbXBhaWduX3RyYWNrZXJfdmlldy54bWw= 100644 --- a/marketing_campaign_tracker_view.xml +++ b/marketing_campaign_tracker_view.xml @@ -1,3 +1,3 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="utf-8"?> <openerp> <data> @@ -2,6 +2,5 @@ <openerp> <data> - <record id="view_marketing_campaign_activity_form" model="ir.ui.view"> <field name="name">marketing.campaign.activity.form.inherit1</field> <field name="model">marketing.campaign.activity</field> @@ -18,7 +17,6 @@ </xpath> </field> </record> - </data> </openerp> diff --git a/replace.py b/replace.py index 09f99957bf8b47495be9a3419aed420a29d25799_cmVwbGFjZS5weQ==..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_cmVwbGFjZS5weQ== 100644 --- a/replace.py +++ b/replace.py @@ -28,8 +28,7 @@ html_href_re = re.compile(r'href="([-a-zA-Z0-9_/.?&=:]+)"') html_imgsrc_re = re.compile(r'img src="([-a-zA-Z0-9_/.?&=:]+)"') - -def insert_tracker_in_text(text, tracker_base, activity_id): +def insert_tracker_in_text(text, tracker_base, activity_id, campaign_id): tracks = [] def repl(match_obj): @@ -37,9 +36,10 @@ uid = str(uuid4()) values = dict(trackitem_uuid=uid, real_url=real_url, - campaign_activity_id=activity_id,) + campaign_activity_id=activity_id, + campaign_id=campaign_id,) tracks.append(values) return "%s/%s" % (tracker_base, uid) return simple_text_url_re.sub(repl, text), tracks @@ -41,9 +41,9 @@ tracks.append(values) return "%s/%s" % (tracker_base, uid) return simple_text_url_re.sub(repl, text), tracks -def insert_tracker_in_html(html, tracker_base, activity_id): +def insert_tracker_in_html(html, tracker_base, activity_id, campaign_id): tracks = [] def repl(match_obj): @@ -51,7 +51,8 @@ uid = str(uuid4()) values = dict(trackitem_uuid=uid, real_url=real_url, - campaign_activity_id=activity_id,) + campaign_activity_id=activity_id, + campaign_id=campaign_id,) tracks.append(values) return 'href="%s/%s"' % (tracker_base, uid) @@ -60,7 +61,8 @@ uid = str(uuid4()) values = dict(trackitem_uuid=uid, real_url=real_url, - campaign_activity_id=activity_id,) + campaign_activity_id=activity_id, + campaign_id=campaign_id,) tracks.append(values) return 'img src="%s/%s"' % (tracker_base, uid) diff --git a/report/__init__.py b/report/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_cmVwb3J0L19faW5pdF9fLnB5 --- /dev/null +++ b/report/__init__.py @@ -0,0 +1,25 @@ +#-*- coding: utf-8 -*- +############################################################################## +# +# Reporting and analytic for marketing campaign +# Copyright (C) 2011 Florent Aide, <florent.aide@gmail.com> +# Copyright (C) 2011 XCG Consulting (http://www.xcg-consulting.fr/) +# +# 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/>. +# +############################################################################## + +import analytic +import board_analytic + diff --git a/report/analytic.py b/report/analytic.py new file mode 100644 index 0000000000000000000000000000000000000000..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_cmVwb3J0L2FuYWx5dGljLnB5 --- /dev/null +++ b/report/analytic.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Marketing campaign analytic. +# Copyright (C) 2011 Florent Aide, <florent.aide@gmail.com> +# Copyright (C) 2011 XCG Consulting (http://www.xcg-consulting.fr/) +# +# 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.osv import osv, fields +import time + +class analytic(osv.Model): + """ + Store and calculate information to display analytic + graphs of all running marketing campaign + """ + + _name = 'marketing_campaign_tracker.analytic' + + def update_graphs(self, cr, uid, ids, context=None): + campaigns = self.pool.get('marketing.campaign') + print campaigns + test = campaigns.browse(cr, uid, ids) + return 0 + + def _get_real_urls(self, cr, uid, ids, name, args, context): + print "*************************" + print "GET REAL URL" + print "*************************" + return dict([("Toto", 1), ("Tata", 2)]) + + def _get_clicks(self, cr, uid, ids, name, args, context): + print "*************************" + print "GET CLICK" + print "*************************" + return dict() + + _columns = { + 'campaign_ids': fields.many2one( + 'marketing.campaign', + 'Marketing Campaign' + ), + 'urls': fields.function( + _get_real_urls, + type='char', + method=True, + store=True + ), + 'clicks': fields.function( + _get_clicks, + type='integer', + method=True, + store=True + ), + } + diff --git a/report/analytic.xml b/report/analytic.xml new file mode 100644 index 0000000000000000000000000000000000000000..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_cmVwb3J0L2FuYWx5dGljLnhtbA== --- /dev/null +++ b/report/analytic.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + <record id="view_marketing_campaign_tracker_analytic_graph" model="ir.ui.view"> + <field name="name">URL Most Clicked - Graph</field> + <field name="model">marketing_campaign_tracker.analytic</field> + <field name="arch" type="xml"> + <graph string="URL Most Clicked" orientation="horizontal" type="line"> + <field name="urls"/> + <field name="campaign_ids"/> + </graph> + </field> + </record> + + <record id="action_marketing_campaign_tracker_analytic" model="ir.actions.act_window"> + <field name="name">Campaign Tracker Analytic</field> + <field name="res_model">marketing_campaign_tracker.analytic</field> + <field name="view_type">form</field> + <field name="view_mode">graph,tree,form</field> + <field name="view_id" ref="view_marketing_campaign_tracker_analytic_graph"/> + </record> + + <record id="board_marketing_campaign_tracker_analytic_form" model="ir.ui.view"> + <field name="name">Campaign Tracker Analytic</field> + <field name="model">board.board</field> + <field name="arch" type="xml"> + <form string="Campaign Tracker Analytic" version="7.0"> + <header> + <button name="update_graph" type="object" string="Update"/> + </header> + <board style= "1-1"> + <column> + <action string="URL Most Clicked" name="%(action_marketing_campaign_tracker_analytic)d"/> + </column> + </board> + </form> + </field> + </record> + + <record id="open_board_marketing_campaign_tracker_analytic" model="ir.actions.act_window"> + <field name="name">Campaign</field> + <field name="res_model">board.board</field> + <field name="view_type">form</field> + <field name="view_mode">form</field> + <field name="context">{'live_update':1}</field> + <!--field name="usage">menu</field--> + <field name="view_id" ref="board_marketing_campaign_tracker_analytic_form"/> + </record> + + <menuitem action="open_board_marketing_campaign_tracker_analytic" + id="menu_report_action_marketing_campaign_tracker_analytic" + parent="base.menu_report_marketing" + sequence="3"/> + </data> +</openerp> diff --git a/report/board_analytic.py b/report/board_analytic.py new file mode 100644 index 0000000000000000000000000000000000000000..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_cmVwb3J0L2JvYXJkX2FuYWx5dGljLnB5 --- /dev/null +++ b/report/board_analytic.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Marketing campaign analytic. +# Copyright (C) 2011 Florent Aide, <florent.aide@gmail.com> +# Copyright (C) 2011 XCG Consulting (http://www.xcg-consulting.fr/) +# +# 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.osv import osv, fields + +class board_analytic(osv.Model): + """ + This class Inherits from board.board to override Create function + to update graphs content when clicking the Update button + """ + + _name = 'board.board' + _inherit = 'board.board' + + def update_graph(self, cr, uid, ids, context=None): + self.pool.get('marketing_campaign_tracker.analytic').update_graphs(cr, uid, ids, context=context) + def board_update(self, cr, uid, ids, context=None): + print "**********************" + print cr + print uid + print ids + print context + print "**********************" + return 0 + diff --git a/static/src/js/report_analytic.js b/static/src/js/report_analytic.js new file mode 100644 index 0000000000000000000000000000000000000000..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_c3RhdGljL3NyYy9qcy9yZXBvcnRfYW5hbHl0aWMuanM= --- /dev/null +++ b/static/src/js/report_analytic.js @@ -0,0 +1,24 @@ +openerp.marketing_campaign_tracker = function(instance) +{ + var QWeb = instance.web.QWeb + var _t = instance.web._t; + + instance.web.form.DashBoard = instance.web.form.DashBoard.extend( + { + init: function(view, node) + { + this._super(view, node); + this.ds_model = new instance.web.DataSetSearch(this, this.view.model); + }, + start: function() + { + var context = new instance.web.CompoundContext(this.build_context(), {}); + this._super.apply(this, arguments); + if (this.view.dataset.context['live_update'] == 1) + { + this.ds_model.call('board_update', [this.session.uid, context]); + } + } + }); +}; + diff --git a/trackitem.py b/trackitem.py index 09f99957bf8b47495be9a3419aed420a29d25799_dHJhY2tpdGVtLnB5..b417f317c2dc44d303fbebeb2bca4d98f7293b7f_dHJhY2tpdGVtLnB5 100644 --- a/trackitem.py +++ b/trackitem.py @@ -46,6 +46,15 @@ 'marketing.campaign.activity', 'Marketing Campaign Activity', ), + 'campaign_id': fields.many2one( + 'marketing.campaign', + 'Marketing Campaign', + ), + 'track_visit_ids': fields.one2many( + 'marketing_campaign_tracker.trackvisit', + 'trackitem_id', + 'Track Visit Id', + ) }