[IMP]: convert in osv memory wizard

bzr revid: ksa@tinyerp.co.in-20100825113624-6ah0xc54mjr5e10n
This commit is contained in:
ksa (Open ERP)
2010-08-25 17:06:24 +05:30
parent 9fdae47333
commit be21d83942
11 changed files with 283 additions and 202 deletions
+4 -2
View File
@@ -53,12 +53,14 @@
'res/res_log_view.xml',
'res/partner/partner_report.xml',
'res/partner/partner_view.xml',
'res/partner/partner_wizard.xml',
'res/bank_view.xml',
'res/country_view.xml',
'res/res_currency_view.xml',
'res/res_currency_view.xml',
'res/partner/crm_view.xml',
'res/partner/wizard/partner_sms_send_view.xml',
'res/partner/wizard/partner_wizard_spam_view.xml',
'res/partner/wizard/partner_clear_ids_view.xml',
# 'res/partner/wizard/partner_wizard_ean_check_view.xml',
'res/partner/partner_data.xml',
'res/ir_property_view.xml',
'security/base_security.xml',
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<wizard id="res_partner_mass_mailing_wizard" model="res.partner" name="res.partner.spam_send" string="Mass Mailing"/>
</data>
</openerp>
@@ -19,10 +19,10 @@
#
##############################################################################
import wizard_spam
import wizard_clear_ids
import wizard_ean_check
import partner_sms_send
import partner_wizard_spam
import partner_clear_ids
import partner_wizard_ean_check
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# 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
@@ -15,26 +15,38 @@
# 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
import netsvc
from osv import fields, osv
class wizard_clear_ids(wizard.interface):
def _clear_ids(self, cr, uid, data, context):
service = netsvc.LocalService("object_proxy")
service.execute(cr.dbname, uid, 'res.partner', 'write', data['ids'], {'ref': False})
return {}
states = {
'init': {
'actions': [_clear_ids],
'result': {'type':'state', 'state':'end'}
}
}
wizard_clear_ids('res.partner.clear_ids')
class partner_clear_ids(osv.osv_memory):
""" Clear IDs """
_name = "partner.clear.ids"
_description = "Clear IDs"
def clear_ids(self, cr, uid, ids, context):
"""
Clear Ids
@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
"""
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 active_ids in partner:
res.update({'ref': False})
return res
partner_clear_ids()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_clear_ids" model="ir.ui.view">
<field name="name">Clear IDs</field>
<field name="model">partner.clear.ids</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Clear Ids">
<label string="Want to Clear Ids ? "/>
<separator string="" colspan="6" />
<label string="" colspan="2"/>
<group>
<button special="cancel" string="Cancel" icon="gtk-cancel" />
<button name="clear_ids" string="Clear IDs" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_view_partner_clear_ids" model="ir.actions.act_window">
<field name="name">Clear IDs</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">partner.clear.ids</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -0,0 +1,77 @@
# -*- 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 math
from osv import osv
from tools.misc import UpdateableStr
import pooler
class partner_wizard_ean_check(osv.osv_memory):
""" Ean check """
_name = "partner.wizard.ean.check"
_description = "Ean Check"
def is_pair(x):
return not x%2
def get_ean_key(string):
if not string or string=='':
return '0'
if len(string)!=12:
return '0'
sum = 0
for i in range(12):
if is_pair(i):
sum = sum + int(string[i])
else:
sum = sum + 3*int(string[i])
return str(int(math.ceil(sum/10.0)*10-sum))
def default_get(self, cr, fields, context):
partner_table = self.pool.get('res.partner')
ids = context.get('active_ids')
partners = partner_table.browse(cr, uid, ids)
_check_arch_lst = ['<?xml version="1.0"?>', '<form string="Check EAN13">', '<label string=""/>', '<label string=""/>','<label string="Original" />', '<label string="Computed" />']
for partner in partners:
if partner['ean13'] and len(partner['ean13'])>11 and len(partner['ean13'])<14:
_check_arch_lst.append('<label colspan="2" string="%s" />' % partner['ean13']);
key = get_ean_key(partner['ean13'][:12])
_check_arch_lst.append('<label string=""/>')
if len(partner['ean13'])==12:
_check_arch_lst.append('<label string="" />');
else:
_check_arch_lst.append('<label string="%s" />' % partner['ean13'][12])
_check_arch_lst.append('<label string="%s" />' % key)
_check_arch_lst.append('</form>')
_check_arch.string = '\n'.join(_check_arch_lst)
def update_ean(self, cr, uid, ids, context):
partner_table = self.pool.get('res.partner')
ids = context.get('active_ids')
partners = partner_table.browse(cr, uid, ids)
for partner in partners:
partner_table.write(cr, uid, ids, {
'ean13': "%s%s" % (partner['ean13'][:12], get_ean_key(partner['ean13'][:12]))
})
return {}
partner_wizard_ean_check()
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_wizard_ean_check" model="ir.ui.view">
<field name="name">Ean check</field>
<field name="model">partner.wizard.ean.check</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Ean check">
<separator string="" colspan="4"/>
<label string="Want to check Ean ? "/>
<separator string="" colspan="6" />
<label string="" colspan="2"/>
<group>
<button special="cancel" string="Ignore" icon="gtk-cancel" />
<button name="update_ean" string="Correct EAN13" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_view_partner_wizard_ean_check" model="ir.actions.act_window">
<field name="name">Ean check</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">partner.wizard.ean.check</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -0,0 +1,72 @@
# -*- 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 netsvc
import tools
from osv import fields, osv
class partner_wizard_spam(osv.osv_memory):
""" Mass Mailing """
_name = "partner.wizard.spam"
_description = "Mass Mailing"
_columns = {
'email_from': fields.char("Sender's email", size=256, required=True),
'subject': fields.char('Subject', size=256,required=True),
'text': fields.text('Message',required=True),
}
def mass_mail_send(self, cr, uid, ids, context):
"""
Send Email
@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
"""
nbr = 0
partner_pool = self.pool.get('res.partner')
data = self.browse(cr, uid, ids, context=context)
event_pool = self.pool.get('res.partner.event')
active_ids = context and context.get('active_ids', [])
partners = partner_pool.browse(cr, uid, active_ids, context)
for partner in partners:
for adr in partner.address:
if adr.email:
name = adr.name or partner.name
to = '%s <%s>' % (name, adr.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
tools.email_send(data.email_from, [to], data.subject, data.text,subtype='html')
nbr += 1
event_pool.create(cr, uid,
{'name': 'Email sent through mass mailing',
'partner_id': partner.id,
'description': data.text })
#TODO: log number of message sent
return {'email_sent': nbr}
partner_wizard_spam()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_mass_mail" model="ir.ui.view">
<field name="name">Mass Mailing</field>
<field name="model">partner.wizard.spam</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Mass Mailing" col="4">
<field name="email_from"/>
<newline/>
<field name="subject"/>
<newline/>
<field name="text" widget="text_tag"/>
<newline/>
<separator string="" colspan="6"/>
<group colspan="6" col="4" >
<button special="cancel" string="Cancel" icon="gtk-cancel" />
<button name="mass_mail_send" string="Send Email" type="object" icon="gtk-go-forward"/>
</group>
</form>
</field>
</record>
<act_window name="Mass Mailing"
res_model="partner.wizard.spam"
src_model="res.partner"
view_mode="form"
target="new"
key2="client_action_multi"
id="action_partner_mass_mail"/>
</data>
</openerp>
@@ -1,98 +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 math
from osv import osv
from tools.misc import UpdateableStr
import pooler
def _is_pair(x):
return not x%2
def _get_ean_key(string):
if not string or string=='':
return '0'
if len(string)!=12:
return '0'
sum=0
for i in range(12):
if _is_pair(i):
sum+=int(string[i])
else:
sum+=3*int(string[i])
return str(int(math.ceil(sum/10.0)*10-sum))
#FIXME: this is not concurrency safe !!!!
_check_arch = UpdateableStr()
_check_fields = {}
def _check_key(self, cr, uid, data, context):
partner_table=pooler.get_pool(cr.dbname).get('res.partner')
partners = partner_table.browse(cr, uid, data['ids'])
_check_arch_lst=['<?xml version="1.0"?>', '<form string="Check EAN13">', '<label string=""/>', '<label string=""/>','<label string="Original" />', '<label string="Computed" />']
for partner in partners:
if partner['ean13'] and len(partner['ean13'])>11 and len(partner['ean13'])<14:
_check_arch_lst.append('<label colspan="2" string="%s" />' % partner['ean13']);
key=_get_ean_key(partner['ean13'][:12])
_check_arch_lst.append('<label string=""/>')
if len(partner['ean13'])==12:
_check_arch_lst.append('<label string="" />');
else:
_check_arch_lst.append('<label string="%s" />' % partner['ean13'][12])
_check_arch_lst.append('<label string="%s" />' % key)
_check_arch_lst.append('</form>')
_check_arch.string = '\n'.join(_check_arch_lst)
return {}
def _update_ean(self, cr, uid, data, context):
partner_table = pooler.get_pool(cr.dbname).get('res.partner')
partners = partner_table.browse(cr, uid, data['ids'])
for partner in partners:
partner_table.write(cr, uid, data['ids'], {
'ean13': "%s%s" % (partner['ean13'][:12], _get_ean_key(partner['ean13'][:12]))
})
return {}
class wiz_ean_check(wizard.interface):
states = {
'init': {
'actions': [_check_key],
'result': {
'type': 'form',
'arch': _check_arch,
'fields': _check_fields,
'state': (('end', 'Ignore'), ('correct', 'Correct EAN13'))
}
},
'correct' : {
'actions': [_update_ean],
'result': {
'type': 'state',
'state': 'end'
}
}
}
wiz_ean_check('res.partner.ean13')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,75 +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 pooler
import tools
email_send_form = '''<?xml version="1.0"?>
<form string="Mass Mailing">
<field name="from"/>
<newline/>
<field name="subject"/>
<newline/>
<field name="text"/>
</form>'''
email_send_fields = {
'from': {'string':"Sender's email", 'type':'char', 'size':64, 'required':True},
'subject': {'string':'Subject', 'type':'char', 'size':64, 'required':True},
'text': {'string':'Message', 'type':'text_tag', 'required':True}
}
# this sends an email to ALL the addresses of the selected partners.
def _mass_mail_send(self, cr, uid, data, context):
nbr = 0
partners = pooler.get_pool(cr.dbname).get('res.partner').browse(cr, uid, data['ids'], context)
for partner in partners:
for adr in partner.address:
if adr.email:
name = adr.name or partner.name
to = '%s <%s>' % (name, adr.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'],subtype='html')
nbr += 1
pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
{'name': 'Email sent through mass mailing',
'partner_id': partner.id,
'description': data['form']['text'], })
#TODO: log number of message sent
return {'email_sent': nbr}
class part_email(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel'), ('send','Send Email')]}
},
'send': {
'actions': [_mass_mail_send],
'result': {'type': 'state', 'state':'end'}
}
}
part_email('res.partner.spam_send')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: