Skip to content

Commit

Permalink
[MIG] base_dav: migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
huguesdk committed Jul 6, 2023
1 parent 33dcf36 commit 158cd4f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion base_dav/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Caldav and Carddav support",
"version": "11.0.1.0.0",
"version": "12.0.1.0.0",
"author": "initOS GmbH, Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Extra Tools",
Expand Down
10 changes: 5 additions & 5 deletions base_dav/demo/dav_collection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
</record>
<record id="field_mapping_addressbook_n" model="dav.collection.field_mapping">
<field name="name">N</field>
<field name="field_id" ref="base.field_res_partner_name" />
<field name="field_id" ref="base.field_res_partner__name" />
<field name="collection_id" ref="collection_addressbook" />
</record>
<record id="field_mapping_addressbook_fn" model="dav.collection.field_mapping">
<field name="name">FN</field>
<field name="field_id" ref="base.field_res_partner_display_name" />
<field name="field_id" ref="base.field_res_partner__display_name" />
<field name="collection_id" ref="collection_addressbook" />
</record>
<record id="field_mapping_addressbook_photo" model="dav.collection.field_mapping">
<field name="name">photo</field>
<field name="field_id" ref="base.field_res_partner_image" />
<field name="field_id" ref="base.field_res_partner__image" />
<field name="collection_id" ref="collection_addressbook" />
</record>
<record id="field_mapping_addressbook_email" model="dav.collection.field_mapping">
<field name="name">email</field>
<field name="field_id" ref="base.field_res_partner_email" />
<field name="field_id" ref="base.field_res_partner__email" />
<field name="collection_id" ref="collection_addressbook" />
</record>
<record id="field_mapping_addressbook_tel" model="dav.collection.field_mapping">
<field name="name">tel</field>
<field name="field_id" ref="base.field_res_partner_phone" />
<field name="field_id" ref="base.field_res_partner__phone" />
<field name="collection_id" ref="collection_addressbook" />
</record>
</odoo>
9 changes: 2 additions & 7 deletions base_dav/models/dav_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import os
import time
from operator import itemgetter
from urllib.parse import quote_plus

Expand Down Expand Up @@ -156,17 +155,13 @@ def to_vobject(self, record):
vobj.add("uid").value = "%s,%s" % (record._name, record.id)
if "rev" not in vobj.contents and "write_date" in record._fields:
vobj.add("rev").value = (
record.write_date.replace(":", "").replace(" ", "T").replace(".", "")
+ "Z"
record.write_date.isoformat().replace(":", "").replace(".", "") + "Z"
)
return result

@api.model
def _odoo_to_http_datetime(self, value):
return time.strftime(
"%a, %d %b %Y %H:%M:%S GMT",
time.strptime(value, "%Y-%m-%d %H:%M:%S"),
)
return value.strftime("%a, %d %b %Y %H:%M:%S GMT")

@api.model
def _split_path(self, path):
Expand Down
24 changes: 12 additions & 12 deletions base_dav/models/dav_collection_field_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dateutil import tz

from odoo import api, fields, models, tools
from odoo.tools.safe_eval import safe_eval


class DavCollectionFieldMapping(models.Model):
Expand Down Expand Up @@ -69,7 +70,7 @@ def _from_vobject_code(self, child):
"tz": tz,
"vobject": vobject,
}
tools.safe_eval(self.import_code, context, mode="exec", nocopy=True)
safe_eval(self.import_code, context, mode="exec", nocopy=True)
return context.get("result", {})

@api.multi
Expand All @@ -92,19 +93,18 @@ def _from_vobject_simple(self, child):
@api.model
def _from_vobject_datetime(self, item):
if isinstance(item.value, datetime.datetime):
value = item.value.astimezone(dateutil.tz.UTC)
return value.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
elif isinstance(item.value, datetime.date):
return item.value.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
return item.value.astimezone(tz.UTC)
if isinstance(item.value, datetime.date):
return datetime.datetime.combine(item.value, datetime.time())
return None

@api.model
def _from_vobject_date(self, item):
if isinstance(item.value, datetime.datetime):
value = item.value.astimezone(dateutil.tz.UTC)
return value.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
elif isinstance(item.value, datetime.date):
return item.value.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
value = item.value.astimezone(tz.UTC)
return value.date()
if isinstance(item.value, datetime.date):
return item.value
return None

@api.model
Expand Down Expand Up @@ -139,7 +139,7 @@ def _to_vobject_code(self, record):
"tz": tz,
"vobject": vobject,
}
tools.safe_eval(self.export_code, context, mode="exec", nocopy=True)
safe_eval(self.export_code, context, mode="exec", nocopy=True)
return context.get("result", None)

@api.multi
Expand All @@ -157,7 +157,7 @@ def _to_vobject_simple(self, record):

@api.model
def _to_vobject_datetime(self, value):
result = fields.Datetime.from_string(value)
result = fields.Datetime.to_datetime(value)
return result.replace(tzinfo=tz.UTC)

@api.model
Expand All @@ -166,7 +166,7 @@ def _to_vobject_datetime_rev(self, value):

@api.model
def _to_vobject_date(self, value):
return fields.Date.from_string(value)
return fields.Date.to_date(value)

@api.model
def _to_vobject_binary(self, value):
Expand Down
6 changes: 1 addition & 5 deletions base_dav/radicale/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import base64
import os
import time
from contextlib import contextmanager

from odoo.http import request
Expand Down Expand Up @@ -93,10 +92,7 @@ def __init__(self, path):
)

def _odoo_to_http_datetime(self, value):
return time.strftime(
"%a, %d %b %Y %H:%M:%S GMT",
time.strptime(value, "%Y-%m-%d %H:%M:%S"),
)
return value.strftime("%a, %d %b %Y %H:%M:%S GMT")

def get_meta(self, key=None):
if key is None:
Expand Down
2 changes: 2 additions & 0 deletions base_dav/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_dav_collection,access_dav_collection,model_dav_collection,base.group_user,1,0,0,0
write_dav_collection,write_dav_collection,model_dav_collection,base.group_system,1,1,1,1
access_dav_collection_field_mapping,access_dav_collection_field_mapping,model_dav_collection_field_mapping,base.group_user,1,0,0,0
write_dav_collection_field_mapping,write_dav_collection_field_mapping,model_dav_collection_field_mapping,base.group_system,1,1,1,1
25 changes: 15 additions & 10 deletions base_dav/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from datetime import datetime, timedelta
from unittest import mock

from dateutil import tz

from odoo.tests.common import TransactionCase
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

from ..radicale.collection import Collection

Expand All @@ -24,21 +25,21 @@ def setUp(self):

self.create_field_mapping(
"login",
"base.field_res_users_login",
"base.field_res_users__login",
excode="result = record.login",
imcode="result = item.value",
)
self.create_field_mapping(
"name",
"base.field_res_users_name",
"base.field_res_users__name",
)
self.create_field_mapping(
"dtstart",
"base.field_res_users_create_date",
"base.field_res_users__create_date",
)
self.create_field_mapping(
"dtend",
"base.field_res_users_write_date",
"base.field_res_users__write_date",
)

start = datetime.now()
Expand All @@ -47,8 +48,8 @@ def setUp(self):
{
"login": "tester",
"name": "Test User",
"create_date": start.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
"write_date": stop.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
"create_date": start,
"write_date": stop,
}
)

Expand All @@ -69,8 +70,12 @@ def compare_record(self, vobj, rec=None):

self.assertEqual((rec or self.record).login, tmp["login"])
self.assertEqual((rec or self.record).name, tmp["name"])
self.assertEqual((rec or self.record).create_date, tmp["create_date"])
self.assertEqual((rec or self.record).write_date, tmp["write_date"])
self.assertEqual(
(rec or self.record).create_date.astimezone(tz.UTC), tmp["create_date"]
)
self.assertEqual(
(rec or self.record).write_date.astimezone(tz.UTC), tmp["write_date"]
)

def test_import_export(self):
# Exporting and importing should result in the same record
Expand All @@ -82,7 +87,7 @@ def test_get_record(self):
self.assertEqual(rec, self.record)

self.collection.field_uuid = self.env.ref(
"base.field_res_users_login",
"base.field_res_users__login",
).id
rec = self.collection.get_record([self.record.login])
self.assertEqual(rec, self.record)
Expand Down

0 comments on commit 158cd4f

Please sign in to comment.