diff --git a/sync/__manifest__.py b/sync/__manifest__.py index a8258f53..c382e364 100644 --- a/sync/__manifest__.py +++ b/sync/__manifest__.py @@ -1,4 +1,4 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020-2021 Ivan Yelizariev # Copyright 2020-2021 Denis Mudarisov # Copyright 2021 Ilya Ilchenko # License MIT (https://opensource.org/licenses/MIT). @@ -8,7 +8,7 @@ "summary": """Synchronize anything with anything: SystemX↔Odoo, Odoo1↔Odoo2, SystemX↔SystemY. ETL/ESB tool similar to OCA/connector, but more flexible""", "category": "Extra Tools", "images": ["images/sync-studio.jpg"], - "version": "14.0.5.0.1", + "version": "14.0.5.0.2", "application": True, "author": "IT Projects Labs, Ivan Yelizariev", "support": "help@itpp.dev", diff --git a/sync/data/sync_project_trello_github_demo.xml b/sync/data/sync_project_trello_github_demo.xml index ea41bfff..d643cfbc 100644 --- a/sync/data/sync_project_trello_github_demo.xml +++ b/sync/data/sync_project_trello_github_demo.xml @@ -227,12 +227,10 @@ def handle_button(): DELETE_TRELLO_WEBHOOKS - DEBUG - @@ -378,7 +376,6 @@ def process_github_issues(issues): GITHUB_ISSUE_COMMENT - Webhook diff --git a/sync/doc/changelog.rst b/sync/doc/changelog.rst index 65964e78..59814521 100644 --- a/sync/doc/changelog.rst +++ b/sync/doc/changelog.rst @@ -1,3 +1,9 @@ +`5.0.2` +------- + +- **Fix:** avoid base.automation errors after deleting sync.task +- **Improvement:** better names for triggers, Server Actions and Base Automation records + `5.0.1` ------- diff --git a/sync/models/ir_actions.py b/sync/models/ir_actions.py index eb0dada4..cb32f3ce 100644 --- a/sync/models/ir_actions.py +++ b/sync/models/ir_actions.py @@ -1,4 +1,4 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020-2021 Ivan Yelizariev # License MIT (https://opensource.org/licenses/MIT). from odoo import fields, models diff --git a/sync/models/sync_project.py b/sync/models/sync_project.py index 91ac0382..28c23af7 100644 --- a/sync/models/sync_project.py +++ b/sync/models/sync_project.py @@ -89,6 +89,10 @@ def copy(self, default=None): default["active"] = False return super(SyncProject, self).copy(default) + def unlink(self): + self.with_context(active_test=False).mapped("task_ids").unlink() + return super().unlink() + def _compute_eval_context_description(self): for r in self: if not r.eval_context: diff --git a/sync/models/sync_trigger_automation.py b/sync/models/sync_trigger_automation.py index 2611c3ea..191852c2 100644 --- a/sync/models/sync_trigger_automation.py +++ b/sync/models/sync_trigger_automation.py @@ -1,9 +1,12 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020-2021 Ivan Yelizariev # Copyright 2021 Denis Mudarisov # License MIT (https://opensource.org/licenses/MIT). +import logging from odoo import api, fields, models +_logger = logging.getLogger(__name__) + class SyncTriggerAutomation(models.Model): @@ -11,14 +14,25 @@ class SyncTriggerAutomation(models.Model): _inherit = ["sync.trigger.mixin", "sync.trigger.mixin.actions"] _description = "DB Trigger" _sync_handler = "handle_db" - _default_name = "DB Trigger" automation_id = fields.Many2one( "base.automation", delegate=True, required=True, ondelete="cascade" ) + def unlink(self): + self.mapped("automation_id").unlink() + return super().unlink() + def start(self, records): if self.active: + if not self.sync_task_id: + # workaround for old deployments + _logger.warning( + "Task was deleted, but there is still base.automation record for it: %s" + % self.automation_id + ) + return + self.sync_task_id.start(self, args=(records,), with_delay=True) def get_code(self): diff --git a/sync/models/sync_trigger_cron.py b/sync/models/sync_trigger_cron.py index 1613593d..226014af 100644 --- a/sync/models/sync_trigger_cron.py +++ b/sync/models/sync_trigger_cron.py @@ -20,6 +20,12 @@ class SyncTriggerCron(models.Model): "ir.cron", delegate=True, required=True, ondelete="cascade" ) + def unlink(self): + crons = self.mapped("cron_id") + if crons: + crons.unlink() + return super().unlink() + @api.model_create_multi def create(self, vals_list): for vals in vals_list: diff --git a/sync/models/sync_trigger_mixin.py b/sync/models/sync_trigger_mixin.py index ac75137b..0a675bd9 100644 --- a/sync/models/sync_trigger_mixin.py +++ b/sync/models/sync_trigger_mixin.py @@ -1,4 +1,4 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020-2021 Ivan Yelizariev # License MIT (https://opensource.org/licenses/MIT). from odoo import api, fields, models @@ -9,7 +9,6 @@ class SyncTriggerMixin(models.AbstractModel): _name = "sync.trigger.mixin" _description = "Mixing for trigger models" _rec_name = "trigger_name" - _default_name = None trigger_name = fields.Char( "Trigger Name", help="Technical name to be used in task code", required=True @@ -21,22 +20,38 @@ def _compute_job_count(self): for r in self: r.job_count = len(r.job_ids) + def _update_name(self, vals): + if not ("sync_task_id" in vals or "trigger_name" in vals): + return + if not self._fields["name"].required: + return + for record in self: + if record.name != self._description: + continue + name = "Sync Studio: %s -> %s" % ( + record.sync_project_id.name, + record.trigger_name, + ) + record.write({"name": name}) + + def write(self, vals): + res = super().write(vals) + self._update_name(vals) + return res + @api.model + def create(self, vals): + res = super().create(vals) + res._update_name(vals) + return res + def default_get(self, fields): vals = super(SyncTriggerMixin, self).default_get(fields) - if self._default_name: - vals["name"] = self._default_name + # put model description in case if name is required field + if self._fields["name"].required: + vals["name"] = self._description return vals - def name_get(self): - result = [] - for r in self: - name = r.trigger_name - if r.name and r.name != self._default_name: - name += " " + r.name - result.append((r.id, name)) - return result - class SyncTriggerMixinModelId(models.AbstractModel): diff --git a/sync/models/sync_trigger_webhook.py b/sync/models/sync_trigger_webhook.py index 0a488906..242185d9 100644 --- a/sync/models/sync_trigger_webhook.py +++ b/sync/models/sync_trigger_webhook.py @@ -20,7 +20,6 @@ class SyncTriggerWebhook(models.Model): ] _description = "Webhook Trigger" _sync_handler = "handle_webhook" - _default_name = "Webhook" action_server_id = fields.Many2one( "ir.actions.server", delegate=True, required=True, ondelete="cascade" diff --git a/sync/wizard/sync_make_module.py b/sync/wizard/sync_make_module.py index 493d2d91..a7fc26c8 100644 --- a/sync/wizard/sync_make_module.py +++ b/sync/wizard/sync_make_module.py @@ -140,7 +140,6 @@ def act_makefile(self): ( "trigger_name", "active", - "name", "sync_task_id", "webhook_type", ), diff --git a/sync_facebook/data/crm/sync_project_data.xml b/sync_facebook/data/crm/sync_project_data.xml index 6a318794..195d1574 100644 --- a/sync_facebook/data/crm/sync_project_data.xml +++ b/sync_facebook/data/crm/sync_project_data.xml @@ -46,7 +46,6 @@ def process_lead(fb_lead): PAGE - Webhook json diff --git a/sync_shopify/data/sync_project_data.xml b/sync_shopify/data/sync_project_data.xml index e96eede5..b509ef2d 100644 --- a/sync_shopify/data/sync_project_data.xml +++ b/sync_shopify/data/sync_project_data.xml @@ -266,19 +266,16 @@ def handle_webhook(httprequest): SHOPIFY_PRODUCT_CREATED - Webhook SHOPIFY_PRODUCT_UPDATED - Webhook SHOPIFY_PRODUCT_DELETED - Webhook diff --git a/sync_viber/data/sync_project_data.xml b/sync_viber/data/sync_project_data.xml index 6fd6bd96..01249da4 100644 --- a/sync_viber/data/sync_project_data.xml +++ b/sync_viber/data/sync_project_data.xml @@ -79,7 +79,6 @@ VIBER_THREAD="VIBER_THREAD" SETUP_WEBHOOK - @@ -167,7 +166,6 @@ VIBER_THREAD="VIBER_THREAD" VIBER - Webhook json