-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from gisce/integrate-powersms
Integrate powersms
- Loading branch information
Showing
26 changed files
with
2,158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# PowerSMS | ||
OpenERP addon to send SMS | ||
|
||
[![CircleCI](https://circleci.com/gh/Som-Energia/powersms.svg?style=svg)](https://circleci.com/gh/Som-Energia/powersms) | ||
[![Coverage Status](https://coveralls.io/repos/github/Som-Energia/powersms/badge.svg)](https://coveralls.io/github/Som-Energia/powersms) | ||
|
||
* We had inspired from the OpenERP module [Poweremail](https://github.com/openlabs/poweremail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from . import powersms_provider | ||
from . import powersms_provider_lleidanet | ||
from . import powersms_core | ||
from . import powersms_templates | ||
from . import powersms_smsbox | ||
from . import wizard | ||
import logging | ||
|
||
logger = logging.getLogger("openerp.powersms") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "Powerful SMS capabilities for Open ERP", | ||
"version": "0.1", | ||
"author": "Som Energia SCCL", | ||
"website": "https://github.com/Som-Energia/powersms", | ||
"category": "Added functionality", | ||
"depends": ["base_extended"], | ||
"description": """Power SMS""", | ||
"demo_xml": [ | ||
"tests/powersms_demo.xml", | ||
], | ||
"init_xml": [], | ||
"update_xml": [ | ||
"security/powersms_security.xml", | ||
"powersms_provider_data.xml", | ||
"powersms_core_view.xml", | ||
"powersms_template_view.xml", | ||
"powersms_smsbox_view.xml", | ||
"powersms_workflow.xml", | ||
"wizard/wizard_send_sms_view.xml", | ||
"powersms_data.xml", | ||
"powersms_scheduler_data.xml", | ||
"security/ir.model.access.csv", | ||
], | ||
"installable": True, | ||
"active": False, | ||
} | ||
|
||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
53 changes: 53 additions & 0 deletions
53
powersms/migrations/5.0.23.1.0/post-0001-set_lleidanet_provider_for_existing_acc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# coding=utf-8 | ||
import logging | ||
from oopgrade.oopgrade import load_data_records, load_data, add_columns_fk | ||
|
||
|
||
def up(cursor, installed_version): | ||
if not installed_version: | ||
return | ||
|
||
import pooler | ||
|
||
logger = logging.getLogger("openerp.migration") | ||
pool = pooler.get_pool(cursor.dbname) | ||
|
||
logger.info("Setting up powersms provider DB...") | ||
pool.get("powersms.provider")._auto_init(cursor, context={"module": "powersms"}) | ||
logger.info("TABLE powersms_provider CREATED success!") | ||
|
||
logger.info("Adding FK provider_id on powersms_core_accounts...") | ||
add_columns_fk( | ||
cursor, | ||
{"powersms_core_accounts": [("provider_id", "int", "powersms_provider", "id", "SET NULL")]}, | ||
) | ||
logger.info("FK provider_id created!") | ||
|
||
logger.info("Loading Providers from data...") | ||
load_data_records( | ||
cursor, "powersms", "powersms_provider_data.xml", ["powersms_provider_lleidanet"] | ||
) | ||
load_data_records(cursor, "powersms", "powersms_core_view.xml", ["powersms_core_accounts_form"]) | ||
load_data_records(cursor, "powersms", "powersms_core_view.xml", ["powersms_core_accounts_tree"]) | ||
|
||
logger.info("Provider data loaded!") | ||
|
||
logger.info("Setting lleida as default for all existing accounts") | ||
set_lleidanet_for_existing_accounts = """ | ||
UPDATE powersms_core_accounts set provider_id = ( | ||
SELECT id FROM powersms_provider WHERE function_pattern_code = 'lleida' | ||
) | ||
""" | ||
cursor.execute(set_lleidanet_for_existing_accounts) | ||
|
||
logger.info("Loading Acces Rules...") | ||
load_data(cursor, "powersms", "security/ir.model.access.csv", mode="update") | ||
logger.info("Access rules create success!") | ||
|
||
|
||
def down(cursor, installed_version): | ||
if not installed_version: | ||
return | ||
|
||
|
||
migrate = up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
from osv import osv, fields | ||
from tools.translate import _ | ||
import netsvc | ||
|
||
|
||
class PowersmsCoreAccounts(osv.osv): | ||
""" | ||
Object to store sms account settings | ||
""" | ||
|
||
_name = "powersms.core_accounts" | ||
|
||
def check_numbers(self, cr, uid, ids, numbers): | ||
box_obj = self.pool.get("powersms.smsbox") | ||
if box_obj.check_mobile(numbers): | ||
return True | ||
return False | ||
|
||
def send_sms(self, cr, uid, ids, from_name, numbers_to, body="", payload=None, context=None): | ||
if context is None: | ||
context = {} | ||
if payload is None: | ||
payload = {} | ||
|
||
def payload_parser(_payload): | ||
from base64 import b64decode | ||
import tempfile | ||
import os | ||
|
||
file_paths = [] | ||
for file_name in _payload.keys(): | ||
# Decode b64 from raw base64 attachment and write it to a buffer | ||
extension = ".{}".format(file_name.split(".")[-1]) | ||
f_name = file_name.replace(extension, "") | ||
fd, path = tempfile.mkstemp(prefix=f_name, suffix=extension) | ||
os.write(fd, b64decode(_payload[file_name])) | ||
os.close(fd) | ||
file_paths.append(path) | ||
return file_paths | ||
|
||
logger = netsvc.Logger() | ||
|
||
# TODO | ||
# - Check if numbers_to is a list, | ||
# for the current code calls numbers_to will be one but better | ||
# if we allow multiple numbers | ||
if not self.check_numbers(cr, uid, ids, numbers_to): | ||
raise Exception("Incorrect cell number: " + numbers_to) | ||
|
||
# Try to send the e-mail from each allowed account | ||
# Only one mail is sent | ||
# TODO | ||
# - Fix this logic, | ||
# if for example we provide 3 accounts and first raise exception the other 2 | ||
# will not be tried | ||
for account_id in ids: | ||
account = self.browse(cr, uid, account_id, context) | ||
|
||
try: | ||
return bool( | ||
account.provider_id.send_sms( | ||
account_id, | ||
from_name, | ||
numbers_to, | ||
body=body, | ||
files=payload_parser(payload), | ||
context=context, | ||
) | ||
) | ||
except Exception as error: | ||
logger.notifyChannel( | ||
_("Power SMS"), | ||
netsvc.LOG_ERROR, | ||
_( | ||
"Could not create SMS " | ||
'from Account "{account.name}".\n' | ||
"Description: {error}" | ||
).format(**locals()), | ||
) | ||
return error | ||
|
||
def do_approval(self, cr, uid, ids, context={}): | ||
self.write(cr, uid, ids, {"state": "approved"}, context=context) | ||
|
||
def filter_send_sms(self, cr, uid, sms_str): | ||
if not sms_str: | ||
sms_str = "" | ||
response = "" | ||
for e in sms_str.split(","): | ||
if self.pool.get("powersms.smsbox").check_mobile(e.strip()): | ||
if response: | ||
response += "," | ||
response += e | ||
return response | ||
|
||
_columns = { | ||
"name": fields.char( | ||
"SMS Account name", | ||
size=64, | ||
required=True, | ||
readonly=True, | ||
select=True, | ||
states={"draft": [("readonly", False)]}, | ||
), | ||
"user": fields.many2one( | ||
"res.users", | ||
"Related User", | ||
required=True, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
), | ||
"tel_id": fields.char( | ||
"Telephone ID", | ||
size=120, | ||
required=True, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
help="eg: +34666666666", | ||
), | ||
"api_server": fields.char( | ||
"SMS API server", | ||
size=120, | ||
required=True, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
help="Enter name of outgoing server, eg: api.lleida.net", | ||
), | ||
"api_uname": fields.char( | ||
"SMS API user Name", | ||
size=120, | ||
required=False, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
), | ||
"api_pass": fields.char( | ||
"SMS API password", | ||
size=120, | ||
invisible=True, | ||
required=False, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
), | ||
"state": fields.selection( | ||
[("draft", "Initiated"), ("suspended", "Suspended"), ("approved", "Approved")], | ||
"Account Status", | ||
required=True, | ||
readonly=True, | ||
), | ||
"allowed_groups": fields.many2many( | ||
"res.groups", | ||
"account_group_rel", | ||
"templ_id", | ||
"group_id", | ||
string="Allowed User Groups", | ||
help="Only users from these groups will be " "allowed to send SMS from this ID.", | ||
), | ||
"provider_id": fields.many2one("powersms.provider", "SMS Provider"), | ||
} | ||
|
||
_defaults = { | ||
"name": lambda self, cursor, user, context: self.pool.get("res.users").read( | ||
cursor, user, user, ["name"], context | ||
)["name"], | ||
"state": lambda *a: "draft", | ||
"user": lambda self, cursor, user, context: user, | ||
} | ||
_sql_constraints = [ | ||
("name_uniq", "unique (name)", "Another account already exists with this Name!") | ||
] | ||
|
||
|
||
PowersmsCoreAccounts() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<!--SMS client Form view --> | ||
<record model="ir.ui.view" id="powersms_core_accounts_form"> | ||
<field name="name">powersms.core_accounts.form</field> | ||
<field name="model">powersms.core_accounts</field> | ||
<field name="type">form</field> | ||
<field name="arch" type="xml"> | ||
<form string="Power SMS Configuration"> | ||
<group colspan="2"> | ||
<field name="name" select="1" /> | ||
</group> | ||
<notebook colspan="4"> | ||
<page string="Outgoing"> | ||
<separator string="Server Information" colspan="4" /> | ||
<group col="2" colspan="2"> | ||
<field name="user" select="2" colspan="2" /> | ||
<field name="api_server" select="1" colspan="2" /> | ||
<field name="tel_id" select="1" colspan="2" /> | ||
<field name="provider_id" select="1" colspan="2" /> | ||
</group> | ||
<group col="2" colspan="2"> | ||
<field name="api_uname" select="1" colspan="2" /> | ||
<field name="api_pass" password="True" colspan="2" /> | ||
<button name="check_outgoing_connection" type="object" string="Check Outgoing Connection" /> | ||
</group> | ||
</page> | ||
<page string="Security" attrs="{'invisible':[('company','!=','yes')]}"> | ||
<field name="allowed_groups" attrs="{'required':[('company','=','yes')]}" /> | ||
</page> | ||
</notebook> | ||
<field name="state" select="1" colspan="2" /> | ||
<group col="2"> | ||
<button string="Approve Account" name="button_approval" states="draft" type="workflow" colspan="2" /> | ||
<button string="Suspend Account" name="button_suspended" states="approved" type="workflow" colspan="2" /> | ||
<button string="Request Re-activation" name="get_reapprove" states="suspended" type="workflow" colspan="2" /> | ||
</group> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="powersms_core_accounts_tree"> | ||
<field name="name">powersms.core_accounts.tree</field> | ||
<field name="model">powersms.core_accounts</field> | ||
<field name="type">tree</field> | ||
<field name="arch" type="xml"> | ||
<tree string="SMS Server"> | ||
<field name="name" select="1" /> | ||
<field name="provider_id" select="1"/> | ||
<field name="tel_id" select="1" /> | ||
<field name="api_uname" select="1" /> | ||
<field name="user" select="1" /> | ||
<field name="api_server" select="1" /> | ||
<field name="state" select="1" /> | ||
</tree> | ||
</field> | ||
</record> | ||
<record model="ir.actions.act_window" id="action_powersms_core_accounts_tree_all"> | ||
<field name="name">All Accounts</field> | ||
<field name="res_model">powersms.core_accounts</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">form,tree</field> | ||
<field name="view_id" ref="powersms_core_accounts_tree" /> | ||
</record> | ||
|
||
<menuitem name="Power SMS" id="menu_powersms_administration_server" /> | ||
<menuitem name="Configuration" id="menu_powersms_configuration_server" parent="menu_powersms_administration_server" /> | ||
<menuitem name="All Accounts" id="menu_powersms_core_accounts_all" parent="menu_powersms_configuration_server" action="action_powersms_core_accounts_tree_all" groups="res_groups_psmsmanager" /> | ||
|
||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<openerp> | ||
<data noupdate="1"> | ||
<record id="sms_account_som" model="powersms.core_accounts"> | ||
<field name="name">Som Energia</field> | ||
<field name="tel_id">600000000</field> | ||
<field name="api_server">api.lleida.net</field> | ||
<field name="state">approved</field> | ||
</record> | ||
<record model="powersms.templates" id="sms_template_factura_impagada"> | ||
<field name="name">Recordatori factura impagada</field> | ||
<field name="object_name" model="ir.model" search="[('model', '=', 'res.partner.address')]"/> | ||
<field name="def_from">Som Energia</field> | ||
<field name="model_int_name">res.partner.address</field> | ||
<field name="def_to">${object.phone}</field> | ||
<field eval="0" name="auto_sms"/> | ||
<field eval="0" name="certificate"/> | ||
<field eval="0" name="send_on_create"/> | ||
<field name="lang">${object.partner_id.lang}</field> | ||
<field eval="0" name="send_on_write"/> | ||
<field name="enforce_from_account" model="powersms.core_accounts" search="[('name','=', 'Som Energia')]"/> | ||
<field name="def_body_text"><![CDATA[El teu banc ens ha retornat una factura. T'hem enviat un correu amb instruccions de com pagar-la. Salutacions.]]></field> | ||
</record> | ||
</data> | ||
</openerp> |
Oops, something went wrong.