[IMP] Partners Geo Assignation - new module

bzr revid: fp@tinyerp.com-20100611220209-kerfxsckm6us8yh7
This commit is contained in:
Fabien Pinckaers 2010-06-12 00:02:09 +02:00
parent caca420c82
commit 71be09ecc6
7 changed files with 288 additions and 45 deletions

View File

@ -1,22 +1,22 @@
<openerp>
<data>
<record id="account_invoice_confirm_view" model="ir.ui.view">
<record id="account_invoice_confirm_view" model="ir.ui.view">
<field name="name">account.invoice.confirm.form</field>
<field name="model">account.invoice.confirm</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm Draft Invoices">
<separator string="Confirm Draft Invoices" colspan="4"/>
<form string="Confirm Draft Invoices">
<separator string="Confirm Draft Invoices" colspan="4"/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Close"/>
<button icon="gtk-execute" string="Confirm Invoices" name="invoice_confirm" type="object" default_focus="1"/>
<button icon="gtk-cancel" special="cancel" string="Close"/>
<button icon="gtk-execute" string="Confirm Invoices" name="invoice_confirm" type="object" default_focus="1"/>
</group>
</form>
</field>
</record>
</record>
<record id="action_account_invoice_confirm" model="ir.actions.act_window">
<record id="action_account_invoice_confirm" model="ir.actions.act_window">
<field name="name">Confirm Draft Invoices</field>
<field name="res_model">account.invoice.confirm</field>
<field name="view_type">form</field>
@ -25,7 +25,7 @@
<field name="target">new</field>
</record>
<record model="ir.values" id="action_account_invoice_confirm_values">
<record model="ir.values" id="action_account_invoice_confirm_values">
<field name="model_id" ref="account.model_account_invoice" />
<field name="object" eval="1" />
<field name="name">Confirm Draft Invoices</field>
@ -33,24 +33,24 @@
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_account_invoice_confirm'))" />
<field name="key">action</field>
<field name="model">account.invoice</field>
</record>
</record>
<record id="account_invoice_cancel_view" model="ir.ui.view">
<record id="account_invoice_cancel_view" model="ir.ui.view">
<field name="name">account.invoice.cancel.form</field>
<field name="model">account.invoice.cancel</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Cancel Selected Invoices">
<separator string="Cancel Selected Invoices" colspan="4"/>
<form string="Cancel Selected Invoices">
<separator string="Cancel Selected Invoices" colspan="4"/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Close"/>
<button icon="gtk-execute" string="Cancel Invoices" name="invoice_cancel" type="object" default_focus="1"/>
<button icon="gtk-cancel" special="cancel" string="Close"/>
<button icon="gtk-execute" string="Cancel Invoices" name="invoice_cancel" type="object" default_focus="1"/>
</group>
</form>
</field>
</record>
</record>
<record id="action_account_invoice_cancel" model="ir.actions.act_window">
<record id="action_account_invoice_cancel" model="ir.actions.act_window">
<field name="name">Cancel Selected Invoices</field>
<field name="res_model">account.invoice.cancel</field>
<field name="view_type">form</field>
@ -59,7 +59,7 @@
<field name="target">new</field>
</record>
<record model="ir.values" id="action_account_invoice_cancel_values">
<record model="ir.values" id="action_account_invoice_cancel_values">
<field name="model_id" ref="account.model_account_invoice" />
<field name="object" eval="1" />
<field name="name">Cancel Selected Invoices</field>
@ -67,7 +67,7 @@
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_account_invoice_cancel'))" />
<field name="key">action</field>
<field name="model">account.invoice</field>
</record>
</record>
</data>
</openerp>
</data>
</openerp>

View File

@ -83,7 +83,8 @@
<field name="date_action"/>
<field name="title_action"/>
<field name="priority" string="Priority"/>
<field name="type" readonly="1"/>
<newline/>
<field name="type" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Opportunity">
@ -134,6 +135,27 @@
icon="gtk-convert" />
</group>
</page>
<page string="Lead">
<group colspan="2" col="4">
<separator string="Contact" colspan="4" col="4"/>
<field name="partner_name" string="Partner Name" colspan="4"/>
<newline/>
<field domain="[('domain', '=', 'contact')]" name="title"/>
<field name="function" />
<field name="street" colspan="4"/>
<field name="street2" colspan="4"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="state_id"/>
</group>
<group colspan="2" col="3">
<separator string="Communication" colspan="4" col="3"/>
<field name="fax"/>
<newline/>
<field name="mobile"/>
</group>
</page>
<page string="Emails" groups="base.group_extended">
<group colspan="4">

View File

@ -0,0 +1,22 @@
# -*- 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 partner_geo_assign

View File

@ -0,0 +1,38 @@
# -*- 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': 'Partner Geo-Localisation',
'version': '1.0',
'category': 'Generic Modules/Production',
'description': """
This is the module used by OpenERP SA to redirect customers to his partners,
based on geolocalisation.
""",
'author': 'OpenERP SA',
'depends': ['crm'],
'update_xml': ['res_partner_view.xml'],
'demo_xml': [],
'installable': True,
'active': False,
'certificate': False,
}

View File

@ -0,0 +1,113 @@
# -*- 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 osv
from osv import fields
import urllib,re
import random, time
def geo_find(addr):
import urllib,re
regex = '<coordinates>([+-]?[0-9\.]+),([+-]?[0-9\.]+),([+-]?[0-9\.]+)</coordinates>'
url = 'http://maps.google.com/maps/geo?q=' + urllib.quote(addr) + '&output=xml&oe=utf8&sensor=false'
xml = urllib.urlopen(url).read()
if '<error>' in xml:
print 'Error'
return None
result = re.search(regex, xml, re.M|re.I)
if not result:
print 'No Regex', xml
return None
return float(result.group(1)),float(result.group(2))
class res_partner(osv.osv):
_inherit = "res.partner"
_columns = {
'partner_latitude': fields.float('Geo Latitude', digits=(16,2)),
'partner_longitude': fields.float('Geo Longitude', digits=(16,2)),
'partner_weight': fields.integer('Weight',
help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"),
}
_defaults = {
'partner_weight': lambda *args: 0
}
def geo_localize(self, cr, uid, ids, context=None):
regex = '<coordinates>([+-]?[0-9\.]+),([+-]?[0-9\.]+),([+-]?[0-9\.]+)</coordinates>'
for partner in self.browse(cr, uid, ids, context=context):
part = partner.address[0]
addr = ', '.join(filter(None, [part.street, part.street2, (part.zip or '')+' '+(part.city or ''), part.state_id and part.state_id.name, part.country_id and part.country_id.name]))
result = geo_find(addr)
if result:
print 'Write', {
'partner_latitude': result[0],
'partner_longitude': result[1]
}
self.write(cr, uid, [partner.id], {
'partner_latitude': result[0],
'partner_longitude': result[1]
}, context=context)
return True
res_partner()
class crm_lead(osv.osv):
_inherit = "crm.lead"
_columns = {
'partner_latitude': fields.float('Geo Latitude', digits=(16,2)),
'partner_longitude': fields.float('Geo Longitude', digits=(16,2)),
'partner_assigned_id': fields.many2one('res.partner','Assigned Partner')
'date_assign': fields.date('Assignation Date')
}
def assign_partner(self, cr, uid, ids, context=None):
for part in self.browse(cr, uid, ids, context=context):
if not part.country_id:
continue
addr = ', '.join(filter(None, [part.street, part.street2, (part.zip or '')+' '+(part.city or ''), part.state_id and part.state_id.name, part.country_id and part.country_id.name]))
result = geo_find(addr)
if result:
self.write(cr, uid, [part.id], {
'partner_latitude': result[0],
'partner_longitude': result[1]
}, context=context)
part_ids = self.pool.get('res.partner').search(cr, uid, [
('partner_weight','>',0),
('partner_latitude','>',result[0]-2), ('partner_latitude','<',result[0]+2),
('partner_longitude','>',result[1]-1.5), ('partner_longitude','<',result[1]+1.5)
], context=context)
if not part_ids:
part_ids = self.pool.get('res.partner').search(cr, uid, [
('partner_weight','>',0),
('partner_latitude','>',result[0]-4), ('partner_latitude','<',result[0]+4),
('partner_longitude','>',result[1]-3), ('partner_longitude','<',result[1]+3)
], context=context)
total = 0
toassign = []
for part2 in self.pool.get('res.partner').browse(cr, uid, part_ids, context=context):
total += part2.partner_weight
toassign.append( (part2.id, total) )
mypartner = random.randint(0,total)
for t in toassign:
if mypartner<=t[1]:
self.write(cr, uid, [part.id], {'partner_assigned_id': t[0], 'date_assign': time.strftime('%Y-%m-%d')}, context=context)
break
return True
crm_lead()

View File

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_crm_opportunity_geo_assign_form" model="ir.ui.view">
<field name="name">crm.lead.geo_assign.inherit</field>
<field name="model">crm.lead</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//notebook[last()]" position="inside">
<page string="Partner Assignation">
<field name="partner_assigned_id"/>
<label string="" colspan="1"/>
<button string="Geo Assign" name="assign_partner" type="object"/>
<newline/>
<field name="partner_latitude"/>
<field name="partner_longitude"/>
</page>
</xpath>
</field>
</record>
<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="type">form</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook[last()]" position="inside">
<page string="Partner Association">
<field name="partner_weight"/>
<label string="" colspan="1"/>
<button string="Geo Localize" name="geo_localize" icon="gtk-apply" type="object"/>
<newline/>
<field name="partner_latitude"/>
<field name="partner_longitude"/>
<field name="date_assign"/>
</page>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -91,9 +91,9 @@
<field name="product_qty"/>
<field name="product_uom"/>
<field name="price_unit"/>
<field name="price_subtotal" groups="base.group_extended"/>
<field name="price_subtotal" groups="base.group_extended"/>
<field name="invoiced"/>
<field name="state"/>
<field name="state"/>
</tree>
<!-- default form view -->
</field>
@ -233,7 +233,13 @@
<field name="date_planned" widget="date"/>
<field name="price_unit"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="account_analytic_id" colspan="4" groups="base.group_extended"/>
<field name="price_subtotal" readonly="1"/>
<group colspan="4" col="4" groups="base.group_extended">
<separator colspan="4" string="Taxes"/>
<field colspan="4" nolabel="1" name="taxes_id"
domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
</group>
</page>
<page string="Notes">
<field colspan="4" name="notes" nolabel="1"/>
@ -243,17 +249,14 @@
<field colspan="4" name="move_ids" nolabel="1" widget="many2many"/>
</page>
<page string="Invoicing" groups="base.group_extended">
<field name="account_analytic_id" colspan="4"/>
<separator colspan="4" string="Taxes"/>
<field colspan="4" nolabel="1" name="taxes_id" domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
<separator colspan="4" string="Manual Invoices"/>
<field name="invoiced"/>
<newline/>
<field colspan="4" name="invoice_lines" nolabel="1" widget="many2many"/>
<separator colspan="4" string="Manual Invoices"/>
<field name="invoiced"/>
<newline/>
<field colspan="4" name="invoice_lines" nolabel="1" widget="many2many"/>
</page>
</notebook>
<group>
<field name="state" />
<group>
<field name="state" />
</group>
</form>
</field>
@ -313,7 +316,7 @@
src_model="product.product"
groups="base.group_extended"/>
<!--
<record model="ir.values" id="action_merge_purchase_order">
<record model="ir.values" id="action_merge_purchase_order">
<field name="object" eval="1" />
<field name="name">Purchase Order</field>
<field name="key2">client_action_multi</field>
@ -344,22 +347,22 @@
<field name="view_id" ref="purchase_order_line_form"/>
<field name="act_window_id" ref="purchase_line_form_action2"/>
</record>
<menuitem action="purchase_line_form_action2" id="menu_purchase_line_order_draft" parent="menu_procurement_management_invoice"/>
<menuitem action="purchase_line_form_action2" id="menu_purchase_line_order_draft" parent="menu_procurement_management_invoice"/>
<!--
Procurements
<!--
Procurements
-->
<record id="view_procurement_form_inherit" model="ir.ui.view">
<field name="name">procurement.order.form.inherit</field>
<field name="model">procurement.order</field>
<field name="inherit_id" ref="procurement.procurement_form_view"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="/form/notebook/page/field[@name='close_move']" position="before">
<field name="purchase_id"/>
</xpath>
</field>
<field name="name">procurement.order.form.inherit</field>
<field name="model">procurement.order</field>
<field name="inherit_id" ref="procurement.procurement_form_view"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="/form/notebook/page/field[@name='close_move']" position="before">
<field name="purchase_id"/>
</xpath>
</field>
</record>
</data>