From 1557adc203030dc09183ec550b6ee05589508701 Mon Sep 17 00:00:00 2001 From: Ivan Kropotkin Date: Sat, 11 May 2024 16:44:37 +0200 Subject: [PATCH] :sparkles: sync: make links dependent on project --- sync/__manifest__.py | 4 ++-- sync/doc/changelog.rst | 6 ++++++ sync/models/sync_link.py | 11 ++++++++--- sync/models/sync_project.py | 9 ++++++++- sync/tests/test_links.py | 9 +++++++-- sync/views/sync_link_views.xml | 13 ++++++++++++- sync/views/sync_project_views.xml | 14 ++++---------- 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/sync/__manifest__.py b/sync/__manifest__.py index 6fbd62d9..9a093f7b 100644 --- a/sync/__manifest__.py +++ b/sync/__manifest__.py @@ -7,7 +7,7 @@ "name": "Sync 🪬 Studio", "summary": """Join the Amazing 😍 Community ⤵️""", "category": "VooDoo ✨ Magic", - "version": "16.0.7.0.0", + "version": "16.0.11.0.0", "application": True, "author": "Ivan Kropotkin", "support": "info@odoomagic.com", @@ -26,8 +26,8 @@ "views/sync_trigger_webhook_views.xml", "views/sync_trigger_button_views.xml", "views/sync_task_views.xml", - "views/sync_project_views.xml", "views/sync_link_views.xml", + "views/sync_project_views.xml", "data/queue_job_function_data.xml", ], "assets": { diff --git a/sync/doc/changelog.rst b/sync/doc/changelog.rst index 1515164c..6ff2ee99 100644 --- a/sync/doc/changelog.rst +++ b/sync/doc/changelog.rst @@ -1,3 +1,9 @@ +`11.0.0` +------- + +- **New:** Use prime numbers for major releases ;-) +- **Improvement:** make links dependent on project + `7.0.0` ------- diff --git a/sync/models/sync_link.py b/sync/models/sync_link.py index f711dfc6..704ca036 100644 --- a/sync/models/sync_link.py +++ b/sync/models/sync_link.py @@ -1,4 +1,4 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020,2024 Ivan Yelizariev # License MIT (https://opensource.org/licenses/MIT). import logging @@ -23,6 +23,7 @@ class SyncLink(models.Model): _description = "Resource Links" _order = "id desc" + project_id = fields.Char("Project") relation = fields.Char("Relation Name", required=True) system1 = fields.Char("System 1", required=True) # index system2 only to make search "Odoo links" @@ -40,7 +41,7 @@ def _auto_init(self): self._cr, "sync_link_refs_uniq_index", self._table, - ["relation", "system1", "system2", "ref1", "ref2", "model"], + ["project_id", "relation", "system1", "system2", "ref1", "ref2", "model"], ) return res @@ -81,6 +82,7 @@ def _set_link_external( self, relation, external_refs, sync_date=None, allow_many2many=False, model=None ): vals = self.refs2vals(external_refs) + vals["project_id"] = self.env.context.get("sync_project_id") # Check for existing records if allow_many2many: existing = self._search_links_external(relation, external_refs) @@ -142,7 +144,10 @@ def _search_links_external( self, relation, external_refs, model=None, make_logs=False ): vals = self.refs2vals(external_refs) - domain = [("relation", "=", relation)] + domain = [ + ("relation", "=", relation), + ("project_id", "=", self.env.context.get("sync_project_id")), + ] if model: domain.append(("model", "=", model)) for k, v in vals.items(): diff --git a/sync/models/sync_project.py b/sync/models/sync_project.py index 91a70c11..d4a8885f 100644 --- a/sync/models/sync_project.py +++ b/sync/models/sync_project.py @@ -105,6 +105,8 @@ class SyncProject(models.Model): job_count = fields.Integer(compute="_compute_job_count") log_ids = fields.One2many("ir.logging", "sync_project_id") log_count = fields.Integer(compute="_compute_log_count") + link_ids = fields.One2many("sync.link", "project_id") + link_count = fields.Integer(compute="_compute_link_count") def copy(self, default=None): default = dict(default or {}) @@ -134,6 +136,11 @@ def _compute_log_count(self): for r in self: r.log_count = len(r.log_ids) + @api.depends("link_ids") + def _compute_link_count(self): + for r in self: + r.link_count = len(r.link_ids) + def _compute_triggers(self): for r in self: r.trigger_cron_count = len(r.mapped("task_ids.cron_ids")) @@ -249,7 +256,7 @@ def record2image(record, fname="image_1920"): ) ) - context = dict(self.env.context, log_function=log) + context = dict(self.env.context, log_function=log, sync_project_id=self.id) env = self.env(context=context) link_functions = env["sync.link"]._get_eval_context() MAGIC = AttrDict( diff --git a/sync/tests/test_links.py b/sync/tests/test_links.py index f11ca733..1e97c964 100644 --- a/sync/tests/test_links.py +++ b/sync/tests/test_links.py @@ -1,4 +1,4 @@ -# Copyright 2020 Ivan Yelizariev +# Copyright 2020,2024 Ivan Yelizariev # License MIT (https://opensource.org/licenses/MIT). import uuid @@ -17,7 +17,12 @@ def generate_ref(): class TestLink(TransactionCase): def setUp(self): super(TestLink, self).setUp() - funcs = self.env["sync.link"]._get_eval_context() + project = self.env["sync.project"].create({"name": "Test Project"}) + funcs = ( + self.env["sync.link"] + .with_context(sync_project_id=project.id) + ._get_eval_context() + ) self.get_link = funcs["get_link"] self.set_link = funcs["set_link"] self.search_links = funcs["search_links"] diff --git a/sync/views/sync_link_views.xml b/sync/views/sync_link_views.xml index 10e499c9..a050d006 100644 --- a/sync/views/sync_link_views.xml +++ b/sync/views/sync_link_views.xml @@ -1,5 +1,5 @@ - @@ -7,6 +7,7 @@ sync.link + @@ -25,6 +26,7 @@ + @@ -79,6 +81,15 @@ tree,form + + Links + sync.link + tree,form + [('project_id', '=', active_id)] + + {'default_project_id': active_id, 'active_test': False} + + - @@ -45,20 +45,14 @@ > -