From e9b81ef01a385a826bed912bb17c9bc0bdb79ca9 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Thu, 24 Oct 2024 11:14:18 +0200 Subject: [PATCH] [MIG] edi_oca: Migration to V18 --- edi_oca/__manifest__.py | 2 +- edi_oca/data/cron.xml | 4 -- edi_oca/migrations/16.0.1.0.0/pre-migrate.py | 45 ------------------- edi_oca/models/edi_backend_type.py | 2 +- edi_oca/models/edi_exchange_record.py | 29 ++++++------ edi_oca/models/edi_exchange_type.py | 7 ++- edi_oca/tests/common.py | 2 +- edi_oca/tests/test_backend_jobs.py | 2 +- edi_oca/tests/test_backend_output.py | 2 +- edi_oca/tests/test_consumer_mixin.py | 2 +- edi_oca/tests/test_security.py | 2 +- edi_oca/utils.py | 5 +-- edi_oca/views/edi_backend_type_views.xml | 8 ++-- edi_oca/views/edi_backend_views.xml | 8 ++-- edi_oca/views/edi_exchange_record_views.xml | 27 +++++------ .../views/edi_exchange_type_rule_views.xml | 6 +-- edi_oca/views/edi_exchange_type_views.xml | 17 +++---- 17 files changed, 55 insertions(+), 115 deletions(-) delete mode 100644 edi_oca/migrations/16.0.1.0.0/pre-migrate.py diff --git a/edi_oca/__manifest__.py b/edi_oca/__manifest__.py index bf1cb344d..571890786 100644 --- a/edi_oca/__manifest__.py +++ b/edi_oca/__manifest__.py @@ -9,7 +9,7 @@ Define backends, exchange types, exchange records, basic automation and views for handling EDI exchanges. """, - "version": "17.0.1.1.2", + "version": "18.0.1.0.0", "website": "https://github.com/OCA/edi-framework", "development_status": "Beta", "license": "LGPL-3", diff --git a/edi_oca/data/cron.xml b/edi_oca/data/cron.xml index e182b10ac..c8a3d3813 100644 --- a/edi_oca/data/cron.xml +++ b/edi_oca/data/cron.xml @@ -10,8 +10,6 @@ 1 hours - -1 - code model.search([])._cron_check_output_exchange_sync() @@ -27,8 +25,6 @@ 1 hours - -1 - code model.search([])._cron_check_input_exchange_sync() diff --git a/edi_oca/migrations/16.0.1.0.0/pre-migrate.py b/edi_oca/migrations/16.0.1.0.0/pre-migrate.py deleted file mode 100644 index 04bb489ee..000000000 --- a/edi_oca/migrations/16.0.1.0.0/pre-migrate.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2023 Camptocamp SA (http://www.camptocamp.com) -# @author: Simone Orsi -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - -import logging - -from psycopg2 import sql - -from odoo import SUPERUSER_ID, api, tools - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - if not version: - return - env = api.Environment(cr, SUPERUSER_ID, {}) - rename_disable_auto_columns(env) - - -def rename_disable_auto_columns(env): - tables = _get_consumer_model_tables(env) - for table in tables: - if tools.sql.column_exists(env.cr, table, "disable_edi_auto"): - env.cr.execute(_make_query(table)) - _logger.info( - "table %s: renamed column `disable_edi_auto` to `edi_disable_auto`" - ) - - -def _make_query(table): - return sql.SQL( - "ALTER TABLE {} RENAME COLUMN 'disable_edi_auto' TO 'edi_disable_auto'" - ).format( - sql.Identifier(table), - ) - - -def _get_consumer_model_tables(env): - tables = [] - mixin = "edi.exchange.consumer.mixin" - for model in env.values(): - if model._name != mixin and not model._abstract and mixin in model._inherit: - tables.append(model._table) - return tables diff --git a/edi_oca/models/edi_backend_type.py b/edi_oca/models/edi_backend_type.py index 3cb5b03ef..08ecfd4f9 100644 --- a/edi_oca/models/edi_backend_type.py +++ b/edi_oca/models/edi_backend_type.py @@ -31,4 +31,4 @@ def _onchange_code(self): def _inverse_code(self): for rec in self: # Make sure it's always normalized - rec.code = normalize_string(rec.code) + rec.code = normalize_string(self, rec.code) diff --git a/edi_oca/models/edi_exchange_record.py b/edi_oca/models/edi_exchange_record.py index 298497c8c..290a2d48b 100644 --- a/edi_oca/models/edi_exchange_record.py +++ b/edi_oca/models/edi_exchange_record.py @@ -461,13 +461,12 @@ def _notify_ack_received_error(self): self._trigger_edi_event("done", suffix="ack_received_error") @api.model - def _search(self, domain, offset=0, limit=None, order=None, access_rights_uid=None): + def _search(self, domain, offset=0, limit=None, order=None): query = super()._search( domain=domain, offset=offset, limit=limit, order=order, - access_rights_uid=access_rights_uid, ) if self.env.is_superuser(): # restrictions do not apply for the superuser @@ -484,14 +483,14 @@ def _search(self, domain, offset=0, limit=None, order=None, access_rights_uid=No ids = set(orig_ids) result = [] model_data = defaultdict(lambda: defaultdict(set)) + sub_query = """ + SELECT id, res_id, model + FROM %(table)s + WHERE id = ANY (%%(ids)s) + """ for sub_ids in self._cr.split_for_in_conditions(ids): self._cr.execute( - """ - SELECT id, res_id, model - FROM "%s" - WHERE id = ANY (%%(ids)s) - """ - % self._table, + sub_query % {"table": self._table}, dict(ids=list(sub_ids)), ) for eid, res_id, model in self._cr.fetchall(): @@ -501,7 +500,7 @@ def _search(self, domain, offset=0, limit=None, order=None, access_rights_uid=No model_data[model][res_id].add(eid) for model, targets in model_data.items(): - if not self.env[model].check_access_rights("read", False): + if not self.env[model].check_access("read"): continue recs = self.env[model].browse(list(targets)) missing = recs - recs.exists() @@ -530,7 +529,6 @@ def _search(self, domain, offset=0, limit=None, order=None, access_rights_uid=No offset=offset + len(orig_ids), limit=limit, order=order, - access_rights_uid=access_rights_uid, ) extend_ids = list(extend_query) result.extend(extend_ids[: limit - len(result)]) @@ -545,13 +543,13 @@ def _search(self, domain, offset=0, limit=None, order=None, access_rights_uid=No def read(self, fields=None, load="_classic_read"): """Override to explicitely call check_access_rule, that is not called by the ORM. It instead directly fetches ir.rules and apply them.""" - self.check_access_rule("read") + self.check_access("read") return super().read(fields=fields, load=load) - def check_access_rule(self, operation): + def check_access(self, operation): """In order to check if we can access a record, we are checking if we can access the related document""" - super().check_access_rule(operation) + super().check_access(operation) if self.env.is_superuser(): return default_checker = self.env["edi.exchange.consumer.mixin"].get_edi_access @@ -573,11 +571,10 @@ def check_access_rule(self, operation): check_operation = checker( [record.id], operation, model_name=record._name ) - record.check_access_rights(check_operation) - record.check_access_rule(check_operation) + record.check_access(check_operation) def write(self, vals): - self.check_access_rule("write") + self.check_access("write") return super().write(vals) def _job_delay_params(self): diff --git a/edi_oca/models/edi_exchange_type.py b/edi_oca/models/edi_exchange_type.py index 56fa5d48f..a175c5bc5 100644 --- a/edi_oca/models/edi_exchange_type.py +++ b/edi_oca/models/edi_exchange_type.py @@ -12,7 +12,6 @@ from odoo.tools import groupby from odoo.addons.base_sparse_field.models.fields import Serialized -from odoo.addons.http_routing.models.ir_http import slugify _logger = logging.getLogger(__name__) @@ -247,7 +246,7 @@ def _make_exchange_filename_datetime(self): date_pattern = pattern_settings.get("date_pattern", DATETIME_FORMAT) tz = timezone(force_tz) if force_tz else None now = datetime.now(utc).astimezone(tz) - return slugify(now.strftime(date_pattern)) + return self.env["ir.http"]._slugify(now.strftime(date_pattern)) def _make_exchange_filename_sequence(self): self.ensure_one() @@ -281,10 +280,10 @@ def _make_exchange_filename(self, exchange_record): def _get_record_name(self, exchange_record): if not exchange_record.res_id or not exchange_record.model: - return slugify(exchange_record.display_name) + return self.env["ir.http"]._slugify(exchange_record.display_name) if hasattr(exchange_record.record, "_get_edi_exchange_record_name"): return exchange_record.record._get_edi_exchange_record_name(exchange_record) - return slugify(exchange_record.record.display_name) + return self.env["ir.http"]._slugify(exchange_record.record.display_name) def is_partner_enabled(self, partner): """Check if given partner record is allowed for the current type. diff --git a/edi_oca/tests/common.py b/edi_oca/tests/common.py index fc0051934..ca84243cd 100644 --- a/edi_oca/tests/common.py +++ b/edi_oca/tests/common.py @@ -17,7 +17,7 @@ class EDIBackendTestMixin: @classmethod def _setup_context(cls, **kw): return dict( - cls.env.context, tracking_disable=True, test_queue_job_no_delay=True, **kw + cls.env.context, tracking_disable=True, queue_job__no_delay=True, **kw ) @classmethod diff --git a/edi_oca/tests/test_backend_jobs.py b/edi_oca/tests/test_backend_jobs.py index 3961f813e..164986359 100644 --- a/edi_oca/tests/test_backend_jobs.py +++ b/edi_oca/tests/test_backend_jobs.py @@ -15,7 +15,7 @@ class EDIBackendTestJobsCase(EDIBackendCommonTestCase, JobMixin): @classmethod def _setup_context(cls): - return dict(super()._setup_context(), test_queue_job_no_delay=None) + return dict(super()._setup_context(), queue_job__no_delay=None) def test_output(self): job_counter = self.job_counter() diff --git a/edi_oca/tests/test_backend_output.py b/edi_oca/tests/test_backend_output.py index acf521032..8e2c452be 100644 --- a/edi_oca/tests/test_backend_output.py +++ b/edi_oca/tests/test_backend_output.py @@ -130,7 +130,7 @@ def setUpClass(cls): @classmethod def _setup_context(cls): # Re-enable jobs - return dict(super()._setup_context(), test_queue_job_no_delay=False) + return dict(super()._setup_context(), queue_job__no_delay=False) def test_job(self): with trap_jobs() as trap: diff --git a/edi_oca/tests/test_consumer_mixin.py b/edi_oca/tests/test_consumer_mixin.py index b70af1491..dcd6826a8 100644 --- a/edi_oca/tests/test_consumer_mixin.py +++ b/edi_oca/tests/test_consumer_mixin.py @@ -10,7 +10,7 @@ from lxml import etree from odoo_test_helper import FakeModelLoader -from odoo.tests.common import Form, tagged +from odoo.tests import Form, tagged from .common import EDIBackendCommonTestCase diff --git a/edi_oca/tests/test_security.py b/edi_oca/tests/test_security.py index 2cf77d764..ae1f20afc 100644 --- a/edi_oca/tests/test_security.py +++ b/edi_oca/tests/test_security.py @@ -5,7 +5,7 @@ from odoo_test_helper import FakeModelLoader from odoo.exceptions import AccessError -from odoo.tests.common import tagged +from odoo.tests import tagged from odoo.tools import mute_logger from .common import EDIBackendCommonTestCase diff --git a/edi_oca/utils.py b/edi_oca/utils.py index 5ca764e0c..809896ac2 100644 --- a/edi_oca/utils.py +++ b/edi_oca/utils.py @@ -4,13 +4,12 @@ import hashlib -from odoo.addons.http_routing.models.ir_http import slugify from odoo.addons.queue_job.job import identity_exact_hasher -def normalize_string(a_string, sep="_"): +def normalize_string(cls, a_string, sep="_"): """Normalize given string, replace dashes with given separator.""" - return slugify(a_string).replace("-", sep) + return cls.env["ir.http"]._slugify(a_string).replace("-", sep) def get_checksum(filecontent): diff --git a/edi_oca/views/edi_backend_type_views.xml b/edi_oca/views/edi_backend_type_views.xml index 019c6c18c..775839594 100644 --- a/edi_oca/views/edi_backend_type_views.xml +++ b/edi_oca/views/edi_backend_type_views.xml @@ -3,10 +3,10 @@ edi.backend.type - + - + @@ -35,7 +35,7 @@ EDI Backend Type ir.actions.act_window edi.backend.type - tree,form + list,form [] {} @@ -49,7 +49,7 @@ - tree + list diff --git a/edi_oca/views/edi_backend_views.xml b/edi_oca/views/edi_backend_views.xml index 84efdcf17..2f557e0d3 100644 --- a/edi_oca/views/edi_backend_views.xml +++ b/edi_oca/views/edi_backend_views.xml @@ -3,7 +3,7 @@ edi.backend - + - + @@ -95,7 +95,7 @@ EDI Backend ir.actions.act_window edi.backend - tree,form + list,form [] {'search_default_filter_all': 1} @@ -109,7 +109,7 @@ - tree + list diff --git a/edi_oca/views/edi_exchange_record_views.xml b/edi_oca/views/edi_exchange_record_views.xml index abe641b59..2a4104b66 100644 --- a/edi_oca/views/edi_exchange_record_views.xml +++ b/edi_oca/views/edi_exchange_record_views.xml @@ -3,7 +3,7 @@ edi.exchange.record - + @@ -24,7 +24,7 @@ decoration-danger="edi_exchange_state in ['validate_error', 'output_error_on_send', 'output_sent_and_error', 'input_receive_error', 'input_processed_error']" widget="badge" /> - + @@ -160,21 +160,18 @@ - + - + -
- - -
+
@@ -290,7 +287,7 @@ Recent exchanges ir.actions.act_window edi.exchange.record - tree,form + list,form Exchanges ir.actions.act_window edi.exchange.record - tree,form + list,form [] {'search_default_filter_created_today': 1} @@ -316,7 +313,7 @@ Exchanges - pending ir.actions.act_window edi.exchange.record - tree,form + list,form [] Exchanges - failed ir.actions.act_window edi.exchange.record - tree,form + list,form [] Exchanges - inbound ir.actions.act_window edi.exchange.record - tree,form + list,form [] Exchanges - outbound ir.actions.act_window edi.exchange.record - tree,form + list,form [] - tree + list
diff --git a/edi_oca/views/edi_exchange_type_rule_views.xml b/edi_oca/views/edi_exchange_type_rule_views.xml index 7b85f6d4a..a54e8ae24 100644 --- a/edi_oca/views/edi_exchange_type_rule_views.xml +++ b/edi_oca/views/edi_exchange_type_rule_views.xml @@ -3,13 +3,13 @@ edi.exchange.type.rule - + - + @@ -116,7 +116,7 @@ EDI Exchange Type Rule ir.actions.act_window edi.exchange.type.rule - tree,form + list,form [] {'search_default_filter_all': 1} diff --git a/edi_oca/views/edi_exchange_type_views.xml b/edi_oca/views/edi_exchange_type_views.xml index 59d0f0cdd..8c11119ab 100644 --- a/edi_oca/views/edi_exchange_type_views.xml +++ b/edi_oca/views/edi_exchange_type_views.xml @@ -3,7 +3,7 @@ edi.exchange.type - + @@ -11,7 +11,7 @@ - + @@ -81,16 +81,13 @@ string="Model rules" groups="edi_oca.group_edi_advanced_settings_manager" > - - + + - + @@ -146,7 +143,7 @@ EDI Exchange Type ir.actions.act_window edi.exchange.type - tree,form + list,form []