[IMP] partner: convert send_sms wizard into osv_memory
bzr revid: hmo@hmo-20100525071448-26g5z75asbsqxffp
This commit is contained in:
parent
2dc32aeba5
commit
acbde9d5cd
|
@ -58,6 +58,7 @@
|
|||
'res/country_view.xml',
|
||||
'res/res_currency_view.xml',
|
||||
'res/partner/crm_view.xml',
|
||||
'res/partner/wizard/partner_sms_send_view.xml',
|
||||
'res/partner/partner_data.xml',
|
||||
'res/ir_property_view.xml',
|
||||
'security/base_security.xml',
|
||||
|
|
|
@ -136,6 +136,7 @@ class res_partner(osv.osv):
|
|||
'supplier': fields.boolean('Supplier', help="Check this box if the partner is a supplier. If it's not checked, purchase people will not see it when encoding a purchase order."),
|
||||
'city': fields.related('address', 'city', type='char', string='City'),
|
||||
'phone': fields.related('address', 'phone', type='char', string='Phone'),
|
||||
'mobile': fields.related('address', 'mobile', type='char', string='Mobile'),
|
||||
'country': fields.related('address', 'country_id', type='many2one', relation='res.country', string='Country'),
|
||||
'employee': fields.boolean('Employee', help="Check this box if the partner is an Employee."),
|
||||
'email': fields.related('address', 'email', type='char', size=240, string='E-mail'),
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<wizard id="res_partner_send_sms_wizard" model="res.partner" name="res.partner.sms_send" string="Send SMS"/>
|
||||
<data>
|
||||
<wizard id="res_partner_mass_mailing_wizard" model="res.partner" name="res.partner.spam_send" string="Mass Mailing"/>
|
||||
<!--
|
||||
<wizard string="Check EAN13" model="res.partner" name="res.partner.ean13"/>
|
||||
<wizard string="Clear IDs" model="res.partner" name="res.partner.clear_ids"/>
|
||||
-->
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -15,14 +15,14 @@
|
|||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard_sms
|
||||
import wizard_spam
|
||||
import wizard_clear_ids
|
||||
import wizard_ean_check
|
||||
import partner_sms_send
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 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 wizard
|
||||
import netsvc
|
||||
import tools
|
||||
from osv import fields, osv
|
||||
|
||||
class partner_sms_send(osv.osv_memory):
|
||||
""" Create Menu """
|
||||
|
||||
_name = "partner.sms.send"
|
||||
_description = "Send SMS"
|
||||
|
||||
_columns = {
|
||||
'mobile_to': fields.char('To', size=256, required=True),
|
||||
'app_id': fields.char('API ID', size=256,required=True),
|
||||
'user': fields.char('Login', size=256,required=True),
|
||||
'password': fields.char('Password', size=256,required=True),
|
||||
'text': fields.text('SMS Message',required=True),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param fields: List of fields for default value
|
||||
@param context: A standard dictionary for contextual values
|
||||
|
||||
@return : default values of fields.
|
||||
"""
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
active_ids = context and context.get('active_ids', [])
|
||||
res = {}
|
||||
for partner in partner_pool.browse(cr, uid, active_ids, context=context):
|
||||
if 'mobile_to' in fields:
|
||||
res.update({'mobile_to': partner.mobile})
|
||||
return res
|
||||
|
||||
def sms_send(self, cr, uid, ids, context):
|
||||
"""
|
||||
to send sms
|
||||
|
||||
@param cr: the current row, from the database cursor.
|
||||
@param uid: the current user’s ID for security checks.
|
||||
@param ids: the ID or list of IDs
|
||||
@param context: A standard dictionary
|
||||
@return: number indicating the acknowledgement
|
||||
"""
|
||||
nbr = 0
|
||||
|
||||
for data in self.browse(cr, uid, ids, context) :
|
||||
tools.sms_send(
|
||||
data.user,
|
||||
data.password,
|
||||
data.app_id,
|
||||
tools.ustr(data.text),
|
||||
data.mobile_to)
|
||||
nbr += 1
|
||||
return {}
|
||||
partner_sms_send()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Create Menu From view -->
|
||||
|
||||
<record id="view_partner_sms_send" model="ir.ui.view">
|
||||
<field name="name">Send SMS</field>
|
||||
<field name="model">partner.sms.send</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="SMS - Gateway: clickatell">
|
||||
<separator string="Bulk SMS send" colspan="4"/>
|
||||
<field name="mobile_to"/>
|
||||
<field name="app_id"/>
|
||||
<field name="user"/>
|
||||
<field name="password"/>
|
||||
<separator string="Message" colspan="4" />
|
||||
<field name="text" colspan="4" nolabel="1"/>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="6">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="sms_send" string="Send SMS" type="object" icon="gtk-go-back"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window name="SMS Send"
|
||||
res_model="partner.sms.send"
|
||||
src_model="res.partner"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
id="action_partner_sms_send"
|
||||
groups="base.group_extended"/>
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,74 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 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 wizard
|
||||
import netsvc
|
||||
import tools
|
||||
|
||||
sms_send_form = '''<?xml version="1.0"?>
|
||||
<form string="%s">
|
||||
<separator string="%s" colspan="4"/>
|
||||
<field name="app_id"/>
|
||||
<newline/>
|
||||
<field name="user"/>
|
||||
<field name="password"/>
|
||||
<newline/>
|
||||
<field name="text" colspan="4"/>
|
||||
</form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
|
||||
|
||||
sms_send_fields = {
|
||||
'app_id': {'string':'API ID', 'type':'char', 'required':True},
|
||||
'user': {'string':'Login', 'type':'char', 'required':True},
|
||||
'password': {'string':'Password', 'type':'char', 'required':True},
|
||||
'text': {'string':'SMS Message', 'type':'text', 'required':True}
|
||||
}
|
||||
|
||||
def _sms_send(self, cr, uid, data, context):
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
|
||||
res_ids = service.execute(cr.dbname, uid, 'res.partner.address', 'search', [('partner_id','in',data['ids']),('type','=','default')])
|
||||
res = service.execute(cr.dbname, uid, 'res.partner.address', 'read', res_ids, ['mobile'])
|
||||
|
||||
nbr = 0
|
||||
for r in res:
|
||||
to = r['mobile']
|
||||
if to:
|
||||
tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
|
||||
nbr += 1
|
||||
return {'sms_sent': nbr}
|
||||
|
||||
class part_sms(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
|
||||
},
|
||||
'send': {
|
||||
'actions': [_sms_send],
|
||||
'result': {'type': 'state', 'state':'end'}
|
||||
}
|
||||
}
|
||||
part_sms('res.partner.sms_send')
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue