Skip to content

Commit

Permalink
[MIG] edi_oca: Migration to V18
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiMForgeFlow committed Oct 25, 2024
1 parent 9c983af commit e9b81ef
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 115 deletions.
2 changes: 1 addition & 1 deletion edi_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions edi_oca/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model_id" ref="edi_oca.model_edi_backend" />
<field name="state">code</field>
<field name="code">model.search([])._cron_check_output_exchange_sync()</field>
Expand All @@ -27,8 +25,6 @@
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model_id" ref="edi_oca.model_edi_backend" />
<field name="state">code</field>
<field name="code">model.search([])._cron_check_input_exchange_sync()</field>
Expand Down
45 changes: 0 additions & 45 deletions edi_oca/migrations/16.0.1.0.0/pre-migrate.py

This file was deleted.

2 changes: 1 addition & 1 deletion edi_oca/models/edi_backend_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 13 additions & 16 deletions edi_oca/models/edi_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -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()
Expand Down Expand Up @@ -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)])
Expand All @@ -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
Expand All @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions edi_oca/models/edi_exchange_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_backend_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_backend_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_consumer_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions edi_oca/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions edi_oca/views/edi_backend_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<record id="edi_backend_type_view_tree" model="ir.ui.view">
<field name="model">edi.backend.type</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
<field name="code" />
</tree>
</list>
</field>
</record>
<record id="edi_backend_type_view_form" model="ir.ui.view">
Expand Down Expand Up @@ -35,7 +35,7 @@
<field name="name">EDI Backend Type</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">edi.backend.type</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="search_view_id" ref="edi_backend_type_view_search" />
<field name="domain">[]</field>
<field name="context">{}</field>
Expand All @@ -49,7 +49,7 @@
<record model="ir.actions.act_window.view" id="act_open_edi_backend_type_view_tree">
<field name="act_window_id" ref="act_open_edi_backend_type_view" />
<field name="sequence" eval="10" />
<field name="view_mode">tree</field>
<field name="view_mode">list</field>
<field name="view_id" ref="edi_backend_type_view_tree" />
</record>
</odoo>
8 changes: 4 additions & 4 deletions edi_oca/views/edi_backend_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<record id="edi_backend_view_tree" model="ir.ui.view">
<field name="model">edi.backend</field>
<field name="arch" type="xml">
<tree decoration-muted="(not active)">
<list decoration-muted="(not active)">
<field name="name" />
<field name="active" />
<field
name="company_id"
groups="base.group_multi_company"
optional="hide"
/>
</tree>
</list>
</field>
</record>
<record id="edi_backend_view_form" model="ir.ui.view">
Expand Down Expand Up @@ -95,7 +95,7 @@
<field name="name">EDI Backend</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">edi.backend</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="search_view_id" ref="edi_backend_view_search" />
<field name="domain">[]</field>
<field name="context">{'search_default_filter_all': 1}</field>
Expand All @@ -109,7 +109,7 @@
<record model="ir.actions.act_window.view" id="act_open_edi_backend_view_tree">
<field name="act_window_id" ref="act_open_edi_backend_view" />
<field name="sequence" eval="10" />
<field name="view_mode">tree</field>
<field name="view_mode">list</field>
<field name="view_id" ref="edi_backend_view_tree" />
</record>
</odoo>
Loading

0 comments on commit e9b81ef

Please sign in to comment.