[IMP] crm : crm_partner_assign cleanup address dependancy
bzr revid: jam@tinyerp.com-20120306134846-yp4llvi8kbg14n0w
This commit is contained in:
parent
9b54f8dcce
commit
ca5a69de4f
|
@ -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'],
|
||||
'depends': ['crm', 'account'],
|
||||
'demo_xml': [
|
||||
'res_partner_demo.xml',
|
||||
],
|
||||
|
|
|
@ -89,14 +89,11 @@ class res_partner(osv.osv):
|
|||
}
|
||||
def geo_localize(self, cr, uid, ids, context=None):
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
if not partner.address:
|
||||
continue
|
||||
contact = partner.address[0] #TOFIX: should be get latitude and longitude for default contact?
|
||||
addr = ', '.join(filter(None, [
|
||||
contact.street,
|
||||
"%s %s" % (contact.zip , contact.city),
|
||||
contact.state_id and contact.state_id.name,
|
||||
contact.country_id and contact.country_id.name]))
|
||||
partner.street,
|
||||
"%s %s" % (partner.zip , partner.city),
|
||||
partner.state_id and partner.state_id.name,
|
||||
partner.country_id and partner.country_id.name]))
|
||||
result = geo_find(tools.ustr(addr))
|
||||
if result:
|
||||
self.write(cr, uid, [partner.id], {
|
||||
|
@ -192,7 +189,7 @@ class crm_lead(osv.osv):
|
|||
('partner_weight', '>', 0),
|
||||
('partner_latitude', '>', latitude - 2), ('partner_latitude', '<', latitude + 2),
|
||||
('partner_longitude', '>', longitude - 1.5), ('partner_longitude', '<', longitude + 1.5),
|
||||
('country', '=', lead.country_id.id),
|
||||
('country_id', '=', lead.country_id.id),
|
||||
], context=context)
|
||||
|
||||
# 2. second way: in the same country, big area
|
||||
|
@ -201,7 +198,7 @@ class crm_lead(osv.osv):
|
|||
('partner_weight', '>', 0),
|
||||
('partner_latitude', '>', latitude - 4), ('partner_latitude', '<', latitude + 4),
|
||||
('partner_longitude', '>', longitude - 3), ('partner_longitude', '<' , longitude + 3),
|
||||
('country', '=', lead.country_id.id),
|
||||
('country_id', '=', lead.country_id.id),
|
||||
], context=context)
|
||||
|
||||
|
||||
|
@ -210,7 +207,7 @@ class crm_lead(osv.osv):
|
|||
# still haven't found any, let's take all partners in the country!
|
||||
partner_ids = res_partner.search(cr, uid, [
|
||||
('partner_weight', '>', 0),
|
||||
('country', '=', lead.country_id.id),
|
||||
('country_id', '=', lead.country_id.id),
|
||||
], context=context)
|
||||
|
||||
# 6. sixth way: closest partner whatsoever, just to have at least one result
|
||||
|
|
|
@ -51,7 +51,7 @@ class crm_partner_report_assign(osv.osv):
|
|||
SELECT
|
||||
coalesce(i.id, p.id - 1000000000) as id,
|
||||
p.id as partner_id,
|
||||
(SELECT country_id FROM res_partner_address a WHERE a.partner_id=p.id AND country_id is not null limit 1) as country_id,
|
||||
(SELECT country_id FROM res_partner a WHERE a.partner_id=p.id AND country_id is not null limit 1) as country_id,
|
||||
p.grade_id,
|
||||
p.activation,
|
||||
p.date_review,
|
||||
|
|
|
@ -37,7 +37,6 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
|||
'user_id': fields.many2one('res.users', "User"),
|
||||
'attachment_ids': fields.many2many('ir.attachment','lead_forward_to_partner_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner'),
|
||||
'address_id' : fields.many2one('res.partner.address', 'Address'),
|
||||
'history': fields.selection([('info', 'Case Information'), ('latest', 'Latest email'), ('whole', 'Whole Story')], 'Send history', required=True),
|
||||
}
|
||||
|
||||
|
@ -75,27 +74,15 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
|||
"""This function fills address information based on partner/user selected
|
||||
"""
|
||||
if not partner_id:
|
||||
return {'value' : {'email_to' : False, 'address_id': False}}
|
||||
|
||||
return {'value' : {'email_to' : False}}
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
addr = partner_obj.address_get(cr, uid, [partner_id], ['contact'])
|
||||
data = {'address_id': addr['contact']}
|
||||
data.update(self.on_change_address(cr, uid, ids, addr['contact'])['value'])
|
||||
|
||||
data = {}
|
||||
partner = partner_obj.browse(cr, uid, [partner_id])
|
||||
user_id = partner and partner[0].user_id or False
|
||||
email = user_id and user_id.user_email or ''
|
||||
data.update({'email_cc' : email, 'user_id': user_id and user_id.id or False})
|
||||
return {
|
||||
'value' : data,
|
||||
'domain' : {'address_id' : partner_id and "[('partner_id', '=', partner_id)]" or "[]"}
|
||||
}
|
||||
|
||||
def on_change_address(self, cr, uid, ids, address_id):
|
||||
email = ''
|
||||
if address_id:
|
||||
email = self.pool.get('res.partner.address').browse(cr, uid, address_id).email
|
||||
return {'value': {'email_to' : email}}
|
||||
data.update({'email_from': partner and partner[0].email or "",
|
||||
'email_cc' : user_id and user_id.user_email or '',
|
||||
'user_id': user_id and user_id.id or False})
|
||||
return {'value' : data}
|
||||
|
||||
def action_forward(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
</group>
|
||||
<group col="4" colspan="4" attrs="{'invisible' : [('send_to','!=','partner')]}">
|
||||
<field name="partner_id" attrs="{'required' : [('send_to','=','partner')]}" on_change="on_change_partner(partner_id)" colspan="2" />
|
||||
<field name="address_id" string="Contact" on_change="on_change_address(address_id)" colspan="2" />
|
||||
</group>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
|
|
Loading…
Reference in New Issue