@@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 marketing_campaign_mailchimp
|
||||
import wizard
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,44 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
"name" : "",
|
||||
"version" : "1.1",
|
||||
"depends" : ['marketing_campaign'],
|
||||
"author" : "OpenERP SA",
|
||||
"category": 'Generic Modules/Marketing',
|
||||
"description": """
|
||||
This module provides integration of the mailchimp.com marketing campaign and mailing-list service, connecting via Mailchimp's WebServices API.
|
||||
You can define multiple Mailchimp accounts and then use them as you wish through a new type of activity, providing direct connection to your Mailchimp Lists.""",
|
||||
'website': 'http://www.openerp.com',
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
"security/ir.model.access.csv",
|
||||
'marketing_campaign_mailchimp_view.xml',
|
||||
'wizard/create_list_view.xml',
|
||||
],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,211 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 urllib
|
||||
import urllib2
|
||||
import simplejson as json
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
|
||||
mailchimp_url = 'http://%s.api.mailchimp.com/1.2'
|
||||
|
||||
class mailchimp_account(osv.osv):
|
||||
_name = "mailchimp.account"
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Account Name', size=64),
|
||||
'username': fields.char('Username', size=64, required=True),
|
||||
'password': fields.char('Password', size=64, required=True),
|
||||
'apikey': fields.char('API Key', size=128),
|
||||
'data_center': fields.selection([('us1', 'US1'), ('us2', 'US2'),
|
||||
('uk1', 'UK1')], 'Data Center'),
|
||||
'state': fields.selection([('draft', 'Draft'), ('approved', 'Approved'),
|
||||
('cancelled', 'Cancelled')], 'State', readonly=True)
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': lambda *a: 'draft'
|
||||
}
|
||||
|
||||
def get_response(self, cr, uid, mailchimp_id, method, params={}):
|
||||
mailchimp_account = self.browse(cr, uid, mailchimp_id)
|
||||
params['output'] = 'json'
|
||||
if method == 'login':
|
||||
params['username'] = mailchimp_account.username
|
||||
params['password'] = mailchimp_account.password
|
||||
else :
|
||||
params['apikey'] = mailchimp_account.apikey
|
||||
url = mailchimp_url%mailchimp_account.data_center+ '/?method=%s'%method
|
||||
params = urllib.urlencode(params, doseq=True)
|
||||
response = urllib2.urlopen(url, params)
|
||||
return json.loads(response.read())
|
||||
|
||||
def button_approve(self, cr, uid, ids, context):
|
||||
acc_obj = self.browse(cr, uid, ids)[0]
|
||||
vals = {}
|
||||
if not acc_obj.apikey:
|
||||
method = 'login'
|
||||
else:
|
||||
method = 'ping'
|
||||
response = self.get_response(cr, uid, acc_obj.id, method)
|
||||
if 'error' not in response:
|
||||
if method == 'login' :
|
||||
vals['apikey'] = response
|
||||
vals['state'] = 'approved'
|
||||
self.write(cr, uid, ids, vals)
|
||||
else :
|
||||
raise osv.except_osv('Error!!!',
|
||||
"Can't approved accoutnt : %s"%response['error'])
|
||||
return True
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context):
|
||||
self.write(cr, uid, ids, {'state': 'cancelled'})
|
||||
return True
|
||||
|
||||
def add_partner_list(self, cr, uid, account_id, list_id, partner_ids):
|
||||
vals = {} # just dictionary with partner_id and updated in list or not
|
||||
for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids):
|
||||
params = {
|
||||
'id' : list_id,
|
||||
'email_address' : partner.email,
|
||||
'email_type':'text',
|
||||
'merge_vars[FNAME]':partner.name ,
|
||||
'merge_vars[date]' : time.strftime('%Y-%m-%d'),
|
||||
'merge_vars[phone]' : partner.phone,
|
||||
'merge_vars[website]' : partner.website,
|
||||
'merge_vars[address][country]' : partner.country.code,
|
||||
'merge_vars[address][city]' : partner.city,
|
||||
'double_optin':False
|
||||
}
|
||||
vals[partner.id] = self.get_response(cr, uid, account_id,
|
||||
'listSubscribe', params)
|
||||
return vals
|
||||
|
||||
mailchimp_account()
|
||||
|
||||
class mailchimp_list(osv.osv_memory):
|
||||
_name = "mailchimp.list"
|
||||
_description = "Mailchimp list"
|
||||
|
||||
_columns = {
|
||||
'mailchimp_account_id': fields.many2one('mailchimp.account',
|
||||
'Mailchimp Account', required=True),
|
||||
'name': fields.char('Name', size=64)
|
||||
}
|
||||
|
||||
mailchimp_list()
|
||||
|
||||
class marketing_campaign(osv.osv):
|
||||
_inherit = "marketing.campaign"
|
||||
|
||||
_columns = {
|
||||
'mailchimp_account_id': fields.many2one(
|
||||
'mailchimp.account', 'Account'),
|
||||
'mailchimp_campaign': fields.char('campaign', size=64),
|
||||
}
|
||||
marketing_campaign()
|
||||
|
||||
|
||||
class marketing_campaign_activity(osv.osv):
|
||||
_inherit = "marketing.campaign.activity"
|
||||
|
||||
_columns = {
|
||||
'mailchimp_account_id': fields.many2one(
|
||||
'mailchimp.account', 'Account'),
|
||||
'mailchimp_list': fields.char('List', size=64),
|
||||
}
|
||||
|
||||
def onchange_mailchimp(self, cr, uid, ids, mailchimp_account_id):
|
||||
if mailchimp_account_id:
|
||||
return {'value':{'mailchimp_list':''}}
|
||||
return {'value':{}}
|
||||
|
||||
def onchange_mailchimp_list(self, cr, uid, ids, mailchimp_account_id,
|
||||
mailchimp_list):
|
||||
if mailchimp_account_id and mailchimp_list:
|
||||
lists = self.pool.get('mailchimp.account').get_response(cr,
|
||||
uid, mailchimp_account_id, 'lists')
|
||||
list_names = [l['name'] for l in lists]
|
||||
if mailchimp_list not in list_names:
|
||||
raise osv.except_osv('Error!!!',"Lists doesn't exists")
|
||||
else :
|
||||
return {}
|
||||
return {'value':{}}
|
||||
|
||||
def _process_wi_mailchimp(self, cr, uid, activity, workitem, context=None):
|
||||
mailchimp_account_id = activity.mailchimp_account_id.id
|
||||
list_name = activity.mailchimp_list
|
||||
mc_acc_obj = self.pool.get('mailchimp.account')
|
||||
lists = mc_acc_obj.get_response(cr, uid, mailchimp_account_id, 'lists')
|
||||
list_id = ''
|
||||
for l in lists :
|
||||
if l['name'] == list_name:
|
||||
list_id = l['id']
|
||||
break;
|
||||
res_model = workitem.object_id.model
|
||||
res_id = workitem.res_id
|
||||
model_obj = self.pool.get(res_model).browse(cr, uid, res_id)
|
||||
params ={}
|
||||
if res_model == 'res.partner' :
|
||||
params.update({
|
||||
'email_address' : model_obj.email,
|
||||
'merge_vars[FNAME]':model_obj.name and model_obj.name or '',
|
||||
'merge_vars[website]' : model_obj.website,
|
||||
'merge_vars[address][country]' : model_obj.country.code,
|
||||
})
|
||||
elif res_model == 'crm.lead' :
|
||||
params.update({
|
||||
'email_address' : model_obj.email_from,
|
||||
'merge_vars[FNAME]':model_obj.partner_name and \
|
||||
model_obj.partner_name or '',
|
||||
'merge_vars[address][country]' : model_obj.country_id and \
|
||||
model_obj.country_id.code or ''
|
||||
})
|
||||
if params['email_address'] :
|
||||
user = mc_acc_obj.get_response(cr, uid, mailchimp_account_id,
|
||||
'listMemberInfo', {
|
||||
'id' : list_id,
|
||||
'email_address': params['email_address']
|
||||
})
|
||||
# if there s no user with the specify email it will return error code
|
||||
# and thus we add that user otherwise user is alredy subscribe and there
|
||||
# is no need to subscribe user again
|
||||
if 'error' in user:
|
||||
params.update({
|
||||
'id' : list_id,
|
||||
'email_type':'text',
|
||||
'double_optin':False,
|
||||
'merge_vars[date]' : time.strftime('%Y-%m-%d'),
|
||||
'merge_vars[address][city]' : model_obj.city and model_obj.city or '',
|
||||
'merge_vars[phone]' : model_obj.phone and model_obj.phone or '',
|
||||
})
|
||||
mc_acc_obj.get_response(cr, uid, mailchimp_account_id, 'listSubscribe', params)
|
||||
# TODO handle mailchimp error
|
||||
return True
|
||||
else :
|
||||
return {'error_msg' : "Invalid Email Address"}
|
||||
|
||||
def __init__(self, *args):
|
||||
super(marketing_campaign_activity, self).__init__(*args)
|
||||
self._action_types.append(('mailchimp', 'Mailchimp'))
|
||||
|
||||
marketing_campaign_activity()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,84 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!--
|
||||
================================================================
|
||||
Marketing Activity Inherited View - mailchimp
|
||||
================================================================
|
||||
-->
|
||||
|
||||
<record model="ir.ui.view" id="view_marketing_campaign_activity_form_inherit">
|
||||
<field name="name">marketing.campaign.activity.form.inherit</field>
|
||||
<field name="model">marketing.campaign.activity</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="marketing_campaign.view_marketing_campaign_activity_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr='//field[@name="type"]/following-sibling::group' position='inside'>
|
||||
<group colspan="2" attrs="{'invisible':[('type','!=','mailchimp')]}">
|
||||
<field name="mailchimp_account_id" attrs="{'required':[('type','=','mailchimp')]}" domain="[('state','=','approved')]" on_change="onchange_mailchimp(mailchimp_account_id)"/>
|
||||
<field name="mailchimp_list" attrs="{'required':[('type','=','mailchimp')]}" on_change="onchange_mailchimp_list(mailchimp_account_id,mailchimp_list)"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!--
|
||||
================================================================
|
||||
Mailchimp Account
|
||||
================================================================
|
||||
-->
|
||||
|
||||
<menuitem name="Tools" id="base.menu_tools" icon="STOCK_PREFERENCES" sequence="28"/>
|
||||
<menuitem name="Mailchimp" id="menu_action_mailchimp" parent="base.menu_emails" />
|
||||
|
||||
<record model="ir.ui.view" id="view_mailchimp_account_tree">
|
||||
<field name="name">mailchimp.account.tree</field>
|
||||
<field name="model">mailchimp.account</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="blue:state in ('draft');black:state in ('approved');gray:state in ('cancelled')" string="Accounts">
|
||||
<field name="name"/>
|
||||
<field name="username" />
|
||||
<field name="data_center"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mailchimp_account_form">
|
||||
<field name="name">mailchimp.account.form</field>
|
||||
<field name="model">mailchimp.account</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Account">
|
||||
<field name="name" select="1"/>
|
||||
<newline/>
|
||||
<field name="username" select="1"/>
|
||||
<field name="password" select="1" password="True"/>
|
||||
<field name="apikey" />
|
||||
<field name="data_center" required="1"/>
|
||||
<separator string="Status" colspan="4"/>
|
||||
<group col="13" colspan="4">
|
||||
<field name="state" nolabel="1"/>
|
||||
<button name="button_approve" string="Approve" states="draft" type="object"/>
|
||||
<button name="button_cancel" string="Cancel" states="draft,approved" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_mailchimp_account">
|
||||
<field name="name">Mailchimp Accounts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">mailchimp.account</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_mailchimp_account_tree"/>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_action_mailchimp_account" parent="menu_action_mailchimp" action="action_mailchimp_account" sequence="40"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,4 +0,0 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_mailchimp_account_user","mailchimp.account.user","marketing_campaign_mailchimp.model_mailchimp_account","base.res_groups_email_template_admin",1,1,1,1
|
||||
"access_mailchimp_account_system","mailchimp.account.user","marketing_campaign_mailchimp.model_mailchimp_account","base.res_groups_email_template_admin",1,0,0,0
|
||||
"access_mailchimp_account_user","mailchimp_account_user","model_mailchimp_account","base.res_groups_email_template_admin",1,1,1,1
|
||||
|
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="base.res_groups_email_template_admin" model="res.groups">
|
||||
<field name="name">Marketing / User</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 create_list
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,61 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 osv import fields, osv
|
||||
from tools.translate import _
|
||||
import netsvc
|
||||
|
||||
class create_list(osv.osv_memory):
|
||||
_name = "create.list"
|
||||
_description = "Create List of mailchimp"
|
||||
# crm.lead remain
|
||||
_columns = {
|
||||
'mailchimp_account_id': fields.many2one('mailchimp.account',
|
||||
'Mailchimp Account', required=True),
|
||||
'mailchimp_list_id': fields.many2one('mailchimp.list', 'List'),
|
||||
'list_name': fields.char('Name',size = 64),
|
||||
'partner_ids': fields.many2many('res.partner',
|
||||
'create_list_partner_rel',
|
||||
'cust_list_id', 'partner_id',
|
||||
'Partner'),
|
||||
|
||||
}
|
||||
|
||||
def onchange_mailchimp_account_id(self, cr, uid, ids, mailchimp_account_id,
|
||||
action):
|
||||
return {'value':{}}
|
||||
|
||||
def create_list(self, cr, uid, ids, context=None):
|
||||
create_list_obj = self.browse(cr, uid, ids[0])
|
||||
mailchimp_account_obj = self.pool.get('mailchimp.account')
|
||||
account_id = create_list_obj.mailchimp_account_id
|
||||
lists = mailchimp_account_obj.get_response(cr, uid, account_id.id, 'lists')
|
||||
lists = dict([(l['name'],l['id']) for l in lists])
|
||||
if create_list_obj.list_name not in lists.keys():
|
||||
raise osv.except_osv(_('UserError'),
|
||||
_('There is no list define in account %s') % (account_id.name))
|
||||
list_id = lists[create_list_obj.list_name]
|
||||
mailchimp_account_obj.add_partner_list(cr, uid, account_id.id, list_id,
|
||||
create_list_obj.partner_ids)
|
||||
return {}
|
||||
create_list()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,37 +0,0 @@
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_create_list" model="ir.ui.view">
|
||||
<field name="name">create.list.form</field>
|
||||
<field name="model">create.list</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Update List Manually">
|
||||
<separator string="Update List Manually" colspan="4"/>
|
||||
<field name="mailchimp_account_id" on_change = "onchange_mailchimp_account_id(mailchimp_account_id,action)"/>
|
||||
<field name="list_name" />
|
||||
<newline/>
|
||||
<separator string="Partner" colspan="4"/>
|
||||
<field name="partner_ids" nolabel="1" colspan="4"/>
|
||||
<group col="4" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="create_list" string="Update" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_create_list" model="ir.actions.act_window">
|
||||
<field name="name">Manual Mailchimp List Update</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">create.list</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="view_create_list"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_action_mailchimp_create_list"
|
||||
name="Manual Mailchimp List Update"
|
||||
parent="menu_action_mailchimp" action="action_create_list"
|
||||
sequence="40" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user