[REF]Radicale Odoo Storage : refactor vCard code
This commit is contained in:
parent
f3033e8282
commit
b61be41911
@ -193,6 +193,43 @@ class Collection(BaseCollection):
|
||||
for oid in self.__class__.get_contacts_from_odoo(self.owner):
|
||||
yield oid + self.content_suffix
|
||||
|
||||
@classmethod
|
||||
def _generate_vcard_from_odoo(cls, partner):
|
||||
""" Generate and return vCard object from Odoo res.partner record """
|
||||
# last_modified = strftime("%a, %d %b %Y %H:%M:%S GMT",
|
||||
# strptime(data.get('write_date'), '%Y-%m-%d %H:%M:%S'))
|
||||
last_modified = str(partner.write_date)
|
||||
vobject_item = vobject.vCard()
|
||||
vobject_item.add('n')
|
||||
vobject_item.add('fn')
|
||||
vobject_item.fn.value = partner.name
|
||||
vobject_item.add('adr')
|
||||
state_name = partner.state_id.name if partner.state_id else ''
|
||||
country_name = partner.country_id.name if partner.country_id else ''
|
||||
vobject_item.adr.value = vobject.vcard.Address(
|
||||
street=' '.join([partner.street or '', partner.street2 or '']),
|
||||
code=partner.zip or '', city=partner.city or '',
|
||||
region=state_name, country=country_name)
|
||||
if partner.image:
|
||||
vobject_item.add('photo;encoding=b;type=jpeg').value = partner.image.replace('\n', '')
|
||||
if partner.phone:
|
||||
vobject_item.add('tel').value = partner.phone
|
||||
if partner.email:
|
||||
vobject_item.add('email').value = partner.email
|
||||
if partner.website:
|
||||
vobject_item.add('url').value = partner.website
|
||||
if partner.function:
|
||||
vobject_item.add('role').value = partner.function
|
||||
if partner.comment:
|
||||
vobject_item.add('note').value = partner.comment
|
||||
if partner.category_id:
|
||||
categs = [categ.name for categ in partner.category_id]
|
||||
vobject_item.add('categories').value = categs
|
||||
if partner.parent_id:
|
||||
vobject_item.add('org').value = [partner.parent_id.name]
|
||||
vobject_item.add('rev').value = last_modified
|
||||
return vobject_item
|
||||
|
||||
def _get_with_metadata(self, href):
|
||||
"""Fetch a single item from Odoo database"""
|
||||
model, database_id = href.split(':')
|
||||
@ -200,47 +237,16 @@ class Collection(BaseCollection):
|
||||
# fields = ['name', 'write_date', 'comment', 'street', 'street2', 'zip',
|
||||
# 'city', 'state_id' 'country_id']
|
||||
# data = self.odoo.execute(model, 'read', [database_id], fields)[0]
|
||||
data = self.odoo.env[model].browse([database_id])
|
||||
record = self.odoo.env[model].browse([database_id])
|
||||
if model == 'res.partner':
|
||||
# last_modified = strftime("%a, %d %b %Y %H:%M:%S GMT",
|
||||
# strptime(data.get('write_date'), '%Y-%m-%d %H:%M:%S'))
|
||||
last_modified = str(data.write_date)
|
||||
vobject_item = vobject.vCard()
|
||||
vobject_item.add('n')
|
||||
vobject_item.add('fn')
|
||||
vobject_item.fn.value = data.name
|
||||
vobject_item.add('adr')
|
||||
state_name = data.state_id.name if data.state_id else ''
|
||||
country_name = data.country_id.name if data.country_id else ''
|
||||
vobject_item.adr.value = vobject.vcard.Address(
|
||||
street=' '.join([data.street or '', data.street2 or '']),
|
||||
code=data.zip or '', city=data.city or '',
|
||||
region=state_name, country=country_name)
|
||||
if data.image:
|
||||
vobject_item.add('photo;encoding=b;type=jpeg').value = data.image.replace('\n', '')
|
||||
if data.phone:
|
||||
vobject_item.add('tel').value = data.phone
|
||||
if data.email:
|
||||
vobject_item.add('email').value = data.email
|
||||
if data.website:
|
||||
vobject_item.add('url').value = data.website
|
||||
if data.function:
|
||||
vobject_item.add('role').value = data.function
|
||||
if data.comment:
|
||||
vobject_item.add('note').value = data.comment
|
||||
if data.category_id:
|
||||
categs = [categ.name for categ in data.category_id]
|
||||
vobject_item.add('categories').value = categs
|
||||
if data.parent_id:
|
||||
vobject_item.add('org').value = [data.parent_id.name]
|
||||
vobject_item = self._generate_vcard_from_odoo(record)
|
||||
vobject_item.add('uid').value = href
|
||||
vobject_item.add('rev').value = last_modified
|
||||
tag, start, end = xmlutils.find_tag_and_time_range(vobject_item)
|
||||
text = vobject_item.serialize()
|
||||
etag = get_etag(text)
|
||||
uid = get_uid_from_object(vobject_item)
|
||||
# uid = get_uid_from_object(vobject_item)
|
||||
return Item(
|
||||
self, href=href, last_modified=last_modified, etag=etag,
|
||||
self, href=href, last_modified=vobject_item.rev.value, etag=etag,
|
||||
text=text, item=vobject_item, uid=href,
|
||||
name=vobject_item.name, component_name=tag), (tag, start, end)
|
||||
elif model == 'calendar.event':
|
||||
|
Loading…
x
Reference in New Issue
Block a user