diff --git a/g2p_encryption_keymanager/__manifest__.py b/g2p_encryption_keymanager/__manifest__.py index 54008a94..7f2baa91 100644 --- a/g2p_encryption_keymanager/__manifest__.py +++ b/g2p_encryption_keymanager/__manifest__.py @@ -9,7 +9,7 @@ "depends": [ "g2p_encryption", ], - "external_dependencies": {"python": ["cryptography<37", "jwcrypto", "python-jose"]}, + "external_dependencies": {"python": ["cryptography>36,<37", "jwcrypto", "python-jose"]}, "data": [ "views/encryption_provider.xml", "data/default_provider.xml", diff --git a/g2p_odk_importer/i18n/g2p_odk_importer.pot b/g2p_odk_importer/i18n/g2p_odk_importer.pot index 55c84c96..febc87ee 100644 --- a/g2p_odk_importer/i18n/g2p_odk_importer.pot +++ b/g2p_odk_importer/i18n/g2p_odk_importer.pot @@ -127,6 +127,13 @@ msgstr "" msgid "Form ID" msgstr "" +#. module: g2p_odk_importer +#. odoo-python +#: code:addons/g2p_odk_importer/models/odk_client.py:0 +#, python-format +msgid "Future records cannot be fetched before the regular import occurs." +msgstr "" + #. module: g2p_odk_importer #: model:ir.model.fields.selection,name:g2p_odk_importer.selection__odk_import__target_registry__group msgid "Group" diff --git a/g2p_odk_importer/models/odk_client.py b/g2p_odk_importer/models/odk_client.py index ded2353c..d3f4a185 100644 --- a/g2p_odk_importer/models/odk_client.py +++ b/g2p_odk_importer/models/odk_client.py @@ -5,11 +5,12 @@ from datetime import datetime import jq +import pytz import requests from dateutil import parser from odoo import _ -from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError _logger = logging.getLogger(__name__) @@ -304,7 +305,7 @@ def download_attachment(self, base_url, project_id, form_id, instance_id, filena return response.content # Fetch Record using Instance ID - def import_record_by_instance_id(self, instance_id): + def import_record_by_instance_id(self, instance_id, last_sync_timestamp=None): url = ( f"{self.base_url}/v1/projects/{self.project_id}/forms/{self.form_id}.svc/" f"Submissions('{instance_id}')" @@ -325,8 +326,23 @@ def import_record_by_instance_id(self, instance_id): raise ValidationError(f"Failed to parse response by using instance ID: {e}") from e _logger.info(f"ODK RAW DATA by instance ID %s {instance_id} {data}") + + if last_sync_timestamp: + last_sync_time = pytz.UTC.localize(last_sync_timestamp) + else: + last_sync_time = None + try: for member in data["value"]: + submission_date_str = member.get("__system", {}).get("submissionDate") + if submission_date_str: + # Parse submissionDate to a timezone-aware datetime object + submission_date = parser.isoparse(submission_date_str) + if last_sync_time and last_sync_time < submission_date: + raise UserError( + _("Future records cannot be fetched before the regular import occurs.") + ) + mapped_json = jq.first(self.json_formatter, member) if self.target_registry == "individual": mapped_json.update({"is_registrant": True, "is_group": False}) diff --git a/g2p_odk_importer/models/odk_import.py b/g2p_odk_importer/models/odk_import.py index f29444a6..0a487e99 100644 --- a/g2p_odk_importer/models/odk_import.py +++ b/g2p_odk_importer/models/odk_import.py @@ -72,8 +72,9 @@ def fetch_record_by_instance_id(self): config.json_formatter, ) client.login() - - imported = client.import_record_by_instance_id(instance_id=config.instance_id) + imported = client.import_record_by_instance_id( + instance_id=config.instance_id, last_sync_timestamp=config.last_sync_time + ) if "form_updated" in imported: message = "ODK form records is imported successfully." types = "success" @@ -171,25 +172,6 @@ def import_records(self): }, } - def import_records_by_cron(self, _id): - config = self.env["odk.config"].browse(_id) - if not config.base_url: - raise UserError(_("Please configure the ODK.")) - client = ODKClient( - self.env, - config.id, - config.base_url, - config.username, - config.password, - config.project, - config.form_id, - self.target_registry, - self.json_formatter, - ) - client.login() - client.import_delta_records(last_sync_timestamp=config.last_sync_time) - config.update({"last_sync_time": fields.Datetime.now()}) - def odk_import_action_trigger(self): for rec in self: if rec.job_status == "draft" or rec.job_status == "completed": @@ -204,7 +186,7 @@ def odk_import_action_trigger(self): "interval_type": "minutes", "model_id": self.env["ir.model"].search([("model", "=", "odk.import")]).id, "state": "code", - "code": "model.import_records_by_cron(" + str(rec.id) + ")", + "code": "model.browse(" + str(rec.id) + ").import_records()", "doall": False, "numbercall": -1, } diff --git a/g2p_openid_vci/__manifest__.py b/g2p_openid_vci/__manifest__.py index 3a19fa69..a67618c1 100644 --- a/g2p_openid_vci/__manifest__.py +++ b/g2p_openid_vci/__manifest__.py @@ -11,7 +11,7 @@ "g2p_registry_base", "g2p_encryption", ], - "external_dependencies": {"python": ["cryptography<37", "python-jose", "jq", "PyLD"]}, + "external_dependencies": {"python": ["cryptography>36,<37", "python-jose", "jq", "PyLD"]}, "data": [ "security/ir.model.access.csv", "views/vci_issuers.xml", diff --git a/requirements.txt b/requirements.txt index 00937e7a..48229d6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # generated from manifests external_dependencies PyLD boto3<=1.15.18 -cryptography<37 +cryptography>36,<37 extendable-pydantic jq jwcrypto