Skip to content

Commit

Permalink
Merge pull request #333 from yelizariev/14.0-sync_task_id-ondelete-ca…
Browse files Browse the repository at this point in the history
…scade

commit is created by 👷‍♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
  • Loading branch information
itpp-bot authored Sep 21, 2021
2 parents 10532cf + e204c1c commit ab94a2f
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 29 deletions.
4 changes: 2 additions & 2 deletions sync/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2020-2021 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2020-2021 Denis Mudarisov <https://github.com/trojikman>
# Copyright 2021 Ilya Ilchenko <https://github.com/mentalko>
# License MIT (https://opensource.org/licenses/MIT).
Expand All @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions sync/data/sync_project_trello_github_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@ def handle_button():
</record>
<record id="delete-trello-webhooks_manual-trigger" model="sync.trigger.button">
<field name="trigger_name">DELETE_TRELLO_WEBHOOKS</field>
<field name="name" />
<field name="sync_task_id" ref="sync.trello-github_task_setup" />
</record>
<record id="debug_manual-trigger" model="sync.trigger.button">
<field name="trigger_name">DEBUG</field>
<field name="name" />
<field name="sync_task_id" ref="sync.trello-github_task_setup" />
</record>
<record id="trello-github_task_issues" model="sync.task">
Expand Down Expand Up @@ -378,7 +376,6 @@ def process_github_issues(issues):
<record id="github-issue-comment_webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">GITHUB_ISSUE_COMMENT</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="sync.trello-github_task_issues" />
</record>
<record id="trello-github_task_cards" model="sync.task">
Expand Down
6 changes: 6 additions & 0 deletions sync/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -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`
-------

Expand Down
2 changes: 1 addition & 1 deletion sync/models/ir_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2020-2021 Ivan Yelizariev <https://twitter.com/yelizariev>
# License MIT (https://opensource.org/licenses/MIT).

from odoo import fields, models
Expand Down
4 changes: 4 additions & 0 deletions sync/models/sync_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 16 additions & 2 deletions sync/models/sync_trigger_automation.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
# Copyright 2020 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2020-2021 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2021 Denis Mudarisov <https://github.com/trojikman>
# License MIT (https://opensource.org/licenses/MIT).
import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class SyncTriggerAutomation(models.Model):

_name = "sync.trigger.automation"
_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):
Expand Down
6 changes: 6 additions & 0 deletions sync/models/sync_trigger_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 28 additions & 13 deletions sync/models/sync_trigger_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Ivan Yelizariev <https://twitter.com/yelizariev>
# Copyright 2020-2021 Ivan Yelizariev <https://twitter.com/yelizariev>
# License MIT (https://opensource.org/licenses/MIT).

from odoo import api, fields, models
Expand All @@ -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
Expand All @@ -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):

Expand Down
1 change: 0 additions & 1 deletion sync/models/sync_trigger_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion sync/wizard/sync_make_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def act_makefile(self):
(
"trigger_name",
"active",
"name",
"sync_task_id",
"webhook_type",
),
Expand Down
1 change: 0 additions & 1 deletion sync_facebook/data/crm/sync_project_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def process_lead(fb_lead):
<record id="page_webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">PAGE</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="handle-webhook_sync-task" />
<field name="webhook_type">json</field>
</record>
Expand Down
3 changes: 0 additions & 3 deletions sync_shopify/data/sync_project_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,16 @@ def handle_webhook(httprequest):
<record id="shopify-products-updates--webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">SHOPIFY_PRODUCT_CREATED</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="sync-shopify-products-to-odoo_sync-task" />
</record>
<record id="shopify-product-updated--webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">SHOPIFY_PRODUCT_UPDATED</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="sync-shopify-products-to-odoo_sync-task" />
</record>
<record id="shopify-product-deleted--webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">SHOPIFY_PRODUCT_DELETED</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="sync-shopify-products-to-odoo_sync-task" />
</record>
<record id="sync-odoo-products-to-shopify_sync-task" model="sync.task">
Expand Down
2 changes: 0 additions & 2 deletions sync_viber/data/sync_project_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ VIBER_THREAD="VIBER_THREAD"
</record>
<record id="setup-webhook--manual-trigger" model="sync.trigger.button">
<field name="trigger_name">SETUP_WEBHOOK</field>
<field name="name" />
<field name="sync_task_id" ref="setup--sync-task" />
</record>
<record id="process-viber-events--sync-task" model="sync.task">
Expand Down Expand Up @@ -167,7 +166,6 @@ VIBER_THREAD="VIBER_THREAD"
<record id="viber--webhook-trigger" model="sync.trigger.webhook">
<field name="trigger_name">VIBER</field>
<field name="active" eval="True" />
<field name="name">Webhook</field>
<field name="sync_task_id" ref="process-viber-events--sync-task" />
<field name="webhook_type">json</field>
</record>
Expand Down

0 comments on commit ab94a2f

Please sign in to comment.