summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-10-07 16:41:35 +0200
committerThibault Delavallée <tde@openerp.com>2013-10-07 16:41:35 +0200
commitcc59f2d77a8b14c8536dc7a1b1bd59e0c9c044fc (patch)
treec1bcdf3f51783050df3741c524b3b7596bf2d50d /addons
parentdd2dd19b234cb5f3de05465215b745d3e93046c7 (diff)
[REF] crm_partner_assign: moved geolocalization stuff of res.partner inside a dedicated module.
[ADD] base_geolocalize, holding partner latitude, longitude and stuff necessary for geo-localisation. This module will be used for the website, to be able to use geo localization without having to rely on crm_partner_assign. crm_partner_assign now contains the logic related to partner assignment and opportunities geo localization. bzr revid: tde@openerp.com-20131007144135-mwnpdznojr0ece7u
Diffstat (limited to 'addons')
-rw-r--r--addons/base_geolocalize/__init__.py22
-rw-r--r--addons/base_geolocalize/__openerp__.py45
-rw-r--r--addons/base_geolocalize/models/__init__.py1
-rw-r--r--addons/base_geolocalize/models/res_partner.py88
-rw-r--r--addons/base_geolocalize/views/res_partner_view.xml30
-rw-r--r--addons/crm_partner_assign/__openerp__.py4
-rw-r--r--addons/crm_partner_assign/crm_partner_assign.py57
-rw-r--r--addons/crm_partner_assign/res_partner_view.xml2
8 files changed, 191 insertions, 58 deletions
diff --git a/addons/base_geolocalize/__init__.py b/addons/base_geolocalize/__init__.py
new file mode 100644
index 00000000000..9afb820ae15
--- /dev/null
+++ b/addons/base_geolocalize/__init__.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2013_Today OpenERP SA (<http://www.openerp.com>).
+#
+# 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 models
diff --git a/addons/base_geolocalize/__openerp__.py b/addons/base_geolocalize/__openerp__.py
new file mode 100644
index 00000000000..c5e08c08e98
--- /dev/null
+++ b/addons/base_geolocalize/__openerp__.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2013_Today OpenERP SA (<http://www.openerp.com>).
+#
+# 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': 'Partners Geo-Localization',
+ 'version': '1.0',
+ 'category': 'Customer Relationship Management',
+ 'description': """
+Partners geolocalization
+========================
+ """,
+ 'author': 'OpenERP SA',
+ 'depends': ['crm'],
+ 'demo': [
+ # 'res_partner_demo.xml',
+ ],
+ 'data': [
+ 'views/res_partner_view.xml',
+ ],
+ 'test': [],
+ 'installable': True,
+ 'auto_install': False,
+ 'images': [],
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/base_geolocalize/models/__init__.py b/addons/base_geolocalize/models/__init__.py
new file mode 100644
index 00000000000..4e5bc1614d1
--- /dev/null
+++ b/addons/base_geolocalize/models/__init__.py
@@ -0,0 +1 @@
+import res_partner
diff --git a/addons/base_geolocalize/models/res_partner.py b/addons/base_geolocalize/models/res_partner.py
new file mode 100644
index 00000000000..af43b990526
--- /dev/null
+++ b/addons/base_geolocalize/models/res_partner.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2013_Today OpenERP SA (<http://www.openerp.com>).
+#
+# 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/>.
+#
+##############################################################################
+
+try:
+ import simplejson as json
+except ImportError:
+ import json # noqa
+import urllib
+
+from openerp.osv import osv, fields
+from openerp import tools
+from openerp.tools.translate import _
+
+
+def geo_find(addr):
+ url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
+ url += urllib.quote(addr.encode('utf8'))
+
+ try:
+ result = json.load(urllib.urlopen(url))
+ except Exception, e:
+ raise osv.except_osv(_('Network error'),
+ _('Cannot contact geolocation servers. Please make sure that your internet connection is up and running (%s).') % e)
+ if result['status'] != 'OK':
+ return None
+
+ try:
+ geo = result['results'][0]['geometry']['location']
+ return float(geo['lat']), float(geo['lng'])
+ except (KeyError, ValueError):
+ return None
+
+
+def geo_query_address(street=None, zip=None, city=None, state=None, country=None):
+ if country and ',' in country and (country.endswith(' of') or country.endswith(' of the')):
+ # put country qualifier in front, otherwise GMap gives wrong results,
+ # e.g. 'Congo, Democratic Republic of the' => 'Democratic Republic of the Congo'
+ country = '{1} {0}'.format(*country.split(',', 1))
+ return tools.ustr(', '.join(filter(None, [street,
+ ("%s %s" % (zip or '', city or '')).strip(),
+ state,
+ country])))
+
+
+class res_partner(osv.osv):
+ _inherit = "res.partner"
+
+ _columns = {
+ 'partner_latitude': fields.float('Geo Latitude'),
+ 'partner_longitude': fields.float('Geo Longitude'),
+ 'date_localization': fields.date('Geo Localization Date'),
+ }
+
+ def geo_localize(self, cr, uid, ids, context=None):
+ # Don't pass context to browse()! We need country names in english below
+ for partner in self.browse(cr, uid, ids):
+ if not partner:
+ continue
+ result = geo_find(geo_query_address(street=partner.street,
+ zip=partner.zip,
+ city=partner.city,
+ state=partner.state_id.name,
+ country=partner.country_id.name))
+ if result:
+ self.write(cr, uid, [partner.id], {
+ 'partner_latitude': result[0],
+ 'partner_longitude': result[1],
+ 'date_localization': fields.date.context_today(self, cr, uid, context=context)
+ }, context=context)
+ return True
diff --git a/addons/base_geolocalize/views/res_partner_view.xml b/addons/base_geolocalize/views/res_partner_view.xml
new file mode 100644
index 00000000000..4747b2e3bff
--- /dev/null
+++ b/addons/base_geolocalize/views/res_partner_view.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<openerp>
+ <data>
+
+ <record id="view_crm_partner_geo_form" model="ir.ui.view">
+ <field name="name">res.partner.geo.inherit</field>
+ <field name="model">res.partner</field>
+ <field name="inherit_id" ref="base.view_partner_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="//notebook[last()]" position="inside">
+ <page string="Geo Localization" name="geo_localization" groups="base.group_no_one">
+ <group colspan="2" col="2">
+ <separator string="Geo Localization" colspan="2"/>
+ <button
+ string="Geo Localize"
+ name="geo_localize"
+ colspan="2"
+ icon="gtk-apply"
+ type="object"/>
+ <field name="partner_latitude"/>
+ <field name="partner_longitude"/>
+ <field name="date_localization"/>
+ </group>
+ </page>
+ </xpath>
+ </field>
+ </record>
+
+ </data>
+</openerp> \ No newline at end of file
diff --git a/addons/crm_partner_assign/__openerp__.py b/addons/crm_partner_assign/__openerp__.py
index e0f1d78558a..f203d6e9dbc 100644
--- a/addons/crm_partner_assign/__openerp__.py
+++ b/addons/crm_partner_assign/__openerp__.py
@@ -21,7 +21,7 @@
{
- 'name': 'Partners Geo-Localization',
+ 'name': 'Partner Assignation',
'version': '1.0',
'category': 'Customer Relationship Management',
'description': """
@@ -37,7 +37,7 @@ The most appropriate partner can be assigned.
You can also use the geolocalization without using the GPS coordinates.
""",
'author': 'OpenERP SA',
- 'depends': ['crm', 'account', 'portal'],
+ 'depends': ['base_geolocalize', 'crm', 'account', 'portal'],
'demo': ['res_partner_demo.xml', 'crm_lead_demo.xml'],
'data': [
'security/ir.model.access.csv',
diff --git a/addons/crm_partner_assign/crm_partner_assign.py b/addons/crm_partner_assign/crm_partner_assign.py
index daf3d844fe6..171b862fdfe 100644
--- a/addons/crm_partner_assign/crm_partner_assign.py
+++ b/addons/crm_partner_assign/crm_partner_assign.py
@@ -19,46 +19,12 @@
#
##############################################################################
-import urllib
import random
-try:
- import simplejson as json
-except ImportError:
- import json # noqa
-
+from openerp.addons.base_geolocalize.models.res_partner import geo_find, geo_query_address
from openerp.osv import osv
from openerp.osv import fields
-from openerp.tools.translate import _
-from openerp import tools
-
-def geo_find(addr):
- url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
- url += urllib.quote(addr.encode('utf8'))
-
- try:
- result = json.load(urllib.urlopen(url))
- except Exception, e:
- raise osv.except_osv(_('Network error'),
- _('Cannot contact geolocation servers. Please make sure that your internet connection is up and running (%s).') % e)
- if result['status'] != 'OK':
- return None
- try:
- geo = result['results'][0]['geometry']['location']
- return float(geo['lat']), float(geo['lng'])
- except (KeyError, ValueError):
- return None
-
-def geo_query_address(street=None, zip=None, city=None, state=None, country=None):
- if country and ',' in country and (country.endswith(' of') or country.endswith(' of the')):
- # put country qualifier in front, otherwise GMap gives wrong results,
- # e.g. 'Congo, Democratic Republic of the' => 'Democratic Republic of the Congo'
- country = '{1} {0}'.format(*country.split(',',1))
- return tools.ustr(', '.join(filter(None, [street,
- ("%s %s" % (zip or '', city or '')).strip(),
- state,
- country])))
class res_partner_grade(osv.osv):
_order = 'sequence'
@@ -88,9 +54,6 @@ class res_partner_activation(osv.osv):
class res_partner(osv.osv):
_inherit = "res.partner"
_columns = {
- 'partner_latitude': fields.float('Geo Latitude'),
- 'partner_longitude': fields.float('Geo Longitude'),
- 'date_localization': fields.date('Geo Localization Date'),
'partner_weight': fields.integer('Grade Weight',
help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"),
'opportunity_assigned_ids': fields.one2many('crm.lead', 'partner_assigned_id',\
@@ -111,23 +74,7 @@ class res_partner(osv.osv):
partner_grade = self.pool.get('res.partner.grade').browse(cr, uid, grade_id)
res['value']['partner_weight'] = partner_grade.partner_weight
return res
- def geo_localize(self, cr, uid, ids, context=None):
- # Don't pass context to browse()! We need country names in english below
- for partner in self.browse(cr, uid, ids):
- if not partner:
- continue
- result = geo_find(geo_query_address(street=partner.street,
- zip=partner.zip,
- city=partner.city,
- state=partner.state_id.name,
- country=partner.country_id.name))
- if result:
- self.write(cr, uid, [partner.id], {
- 'partner_latitude': result[0],
- 'partner_longitude': result[1],
- 'date_localization': fields.date.context_today(self,cr,uid,context=context)
- }, context=context)
- return True
+
class crm_lead(osv.osv):
_inherit = "crm.lead"
diff --git a/addons/crm_partner_assign/res_partner_view.xml b/addons/crm_partner_assign/res_partner_view.xml
index 6823c262f02..891556e0ad5 100644
--- a/addons/crm_partner_assign/res_partner_view.xml
+++ b/addons/crm_partner_assign/res_partner_view.xml
@@ -103,7 +103,7 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
- <xpath expr="//notebook[last()]" position="inside">
+ <xpath expr="//page[@name='geo_localization']" position="replace">
<page string="Geo Localization">
<group>
<group>