Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base_vcard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import vcard_model
from . import res_partner
from . import res_users
37 changes: 29 additions & 8 deletions base_vcard/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,49 @@ def _fill_get_vcard(self, cr, uid, ids, vcard):
vcard.photo.type_param = "PNG"

def _fill_set_vcard(self, cr, uid, ids, vcard, update_values):
partner_obj = self.browse(cr, uid, ids)[0]
update_values = {}
partner_obj = self.browse(cr, uid, ids)[0] if ids else False

# a vcard MUST have an N and FN attribute, so we don't have to
# check whether these are available here

if 'email' in vcard:
for email in vcard['email']:
if email.value != partner_obj.email:
if not partner_obj or email.value != partner_obj.email:
update_values['email'] = email.value

def types(tel):
return (map(lambda x: x.lower(), tel.type_paramlist)
if ('type' in tel.params or 'TYPE' in tel.params)
else [])

# update phone numbers
if 'tel' in vcard:
work_tel = [tel for tel in vcard['tel']
if u'work' in map(lambda x: x.lower(), tel.type_paramlist) and
u'fax' not in map(lambda x: x.lower(), tel.type_paramlist)]
if u'work' in types(tel) and
u'fax' not in types(tel)]
if not work_tel:
if types(tel):
work_tel = [tel for tel in vcard['tel']
if u'main' in types(tel) and
u'cell' not in types(tel)]
else:
work_tel = [tel for tel in vcard['tel']]

for tel in work_tel:
if tel.value != partner_obj.phone:
if not partner_obj or tel.value != partner_obj.phone:
update_values['phone'] = tel.value
break

fax_tel = [tel for tel in vcard['tel']
if u'fax' in types(tel)]
for tel in fax_tel:
if not partner_obj or tel.value != partner_obj.fax:
update_values['fax'] = tel.value
break

cell_tel = [tel for tel in vcard['tel']
if u'cell' in map(lambda x: x.lower(), tel.type_paramlist)]
if u'cell' in types(tel)]
for tel in cell_tel:
if tel.value != partner_obj.mobile:
if not partner_obj or tel.value != partner_obj.mobile:
update_values['mobile'] = tel.value
break
8 changes: 8 additions & 0 deletions base_vcard/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
import uuid
from openerp import models


class User(models.Model):
_inherit = ['res.users', 'vcard.model']
_name = 'res.users'
6 changes: 5 additions & 1 deletion base_vcard/vcard_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_vcard(self, cr, uid, ids):
self._fill_get_vcard(cr, uid, ids, vcard)
return vcard

def set_vcard(self, cr, uid, ids, vcard_string):
def get_values_from_vcard(self, cr, uid, ids, vcard_string):
"Import a model from a vCard"
vcard = vobject.readOne(vcard_string)

Expand All @@ -134,6 +134,10 @@ def set_vcard(self, cr, uid, ids, vcard_string):
pickle.dumps(unmapped_properties)

self._fill_set_vcard(cr, uid, ids, vcard.contents, update_values)
return update_values

def set_vcard(self, cr, uid, ids, vcard_string):
update_values = self.get_values_from_vcard(cr, uid, ids, vcard_string)
self.write(cr, uid, ids, update_values)

def get_uid_by_vcard(self, vcard_string):
Expand Down