From 71cbfb950350a1f0f64b5d86e77e545199e8c44e Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Fri, 30 Oct 2015 13:21:35 +0100 Subject: [PATCH 1/4] [RFR] Allow to get values from a partner vcard without a partner so that we can create a new partner from a vcard [IMP] Allow for phone numbers with type list missing [IMP] Allow for fax numbers --- base_vcard/res_partner.py | 31 +++++++++++++++++++++++-------- base_vcard/vcard_model.py | 6 +++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/base_vcard/res_partner.py b/base_vcard/res_partner.py index 17eded1..4748d86 100644 --- a/base_vcard/res_partner.py +++ b/base_vcard/res_partner.py @@ -92,28 +92,43 @@ 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 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 and not types(tel): + 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 diff --git a/base_vcard/vcard_model.py b/base_vcard/vcard_model.py index 74cfca4..80777ab 100644 --- a/base_vcard/vcard_model.py +++ b/base_vcard/vcard_model.py @@ -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) @@ -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): From 7fe8d74d19fff418e257f37396a7cae8cbc443c7 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Mon, 2 Nov 2015 15:09:17 +0100 Subject: [PATCH 2/4] [FIX] Case in vcard params list --- base_vcard/res_partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_vcard/res_partner.py b/base_vcard/res_partner.py index 4748d86..8026891 100644 --- a/base_vcard/res_partner.py +++ b/base_vcard/res_partner.py @@ -104,7 +104,8 @@ def _fill_set_vcard(self, cr, uid, ids, vcard, update_values): def types(tel): return (map(lambda x: x.lower(), tel.type_paramlist) - if 'type' in tel.params else []) + if ('type' in tel.params or 'TYPE' in tel.params) + else []) # update phone numbers if 'tel' in vcard: From 39ad9500deb9b19fb6bd41f1fe47c01794229892 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Mon, 2 Nov 2015 15:17:39 +0100 Subject: [PATCH 3/4] [FIX] Take MAIN phone number into account --- base_vcard/res_partner.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/base_vcard/res_partner.py b/base_vcard/res_partner.py index 8026891..080577b 100644 --- a/base_vcard/res_partner.py +++ b/base_vcard/res_partner.py @@ -110,10 +110,15 @@ def types(tel): # update phone numbers if 'tel' in vcard: work_tel = [tel for tel in vcard['tel'] - if u'work' in types(tel) and - u'fax' not in types(tel)] - if not work_tel and not types(tel): - work_tel = [tel for tel in vcard['tel']] + 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 not partner_obj or tel.value != partner_obj.phone: @@ -128,7 +133,7 @@ def types(tel): break cell_tel = [tel for tel in vcard['tel'] - if u'cell' in types(tel)] + if u'cell' in types(tel)] for tel in cell_tel: if not partner_obj or tel.value != partner_obj.mobile: update_values['mobile'] = tel.value From 8434c6ffb4aec5ca53de24cf5c32b0c2796a406f Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 10 Nov 2015 10:35:20 +0100 Subject: [PATCH 4/4] [FIX] Trigger uid uniqueness constraint when duplicating users, because of incomplete inheritance structure --- base_vcard/__init__.py | 1 + base_vcard/res_users.py | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 base_vcard/res_users.py diff --git a/base_vcard/__init__.py b/base_vcard/__init__.py index 2078a2d..17a2ae3 100644 --- a/base_vcard/__init__.py +++ b/base_vcard/__init__.py @@ -1,2 +1,3 @@ from . import vcard_model from . import res_partner +from . import res_users diff --git a/base_vcard/res_users.py b/base_vcard/res_users.py new file mode 100644 index 0000000..bd05e88 --- /dev/null +++ b/base_vcard/res_users.py @@ -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'