Skip to content

Commit

Permalink
[MIG] base_url: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Jul 28, 2023
1 parent a31e7f8 commit 95a6b84
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_url/|
^partner_contact_company/|
^product_online_category/|
^shopinvader/|
Expand Down
4 changes: 2 additions & 2 deletions base_url/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Base Url",
"version": "14.0.1.0.2",
"version": "16.0.1.0.0",
"category": "tools",
"license": "AGPL-3",
"summary": "keep history of url for products & categories ",
Expand All @@ -16,5 +16,5 @@
"external_dependencies": {"python": ["python-slugify"]},
"data": ["views/url_view.xml", "security/ir.model.access.csv"],
"url": "",
"installable": False,
"installable": True,
}
29 changes: 15 additions & 14 deletions base_url/models/abstract_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AbstractUrl(models.AbstractModel):
compute="_compute_redirect_url_url_ids", comodel_name="url.url"
)
lang_id = fields.Many2one("res.lang", string="Lang", required=True)
active = fields.Boolean(string="Active", default=True)
active = fields.Boolean(default=True)

@api.constrains("url_builder", "manual_url_key")
def _check_manual_url_key(self):
Expand Down Expand Up @@ -128,7 +128,7 @@ def _compute_url_key(self):

@api.depends("url_key")
def _compute_redirect_url_url_ids(self):
self.flush()
self.flush_model()
for record in self:
record.redirect_url_url_ids = record.env["url.url"].search(
[
Expand All @@ -139,7 +139,7 @@ def _compute_redirect_url_url_ids(self):

@api.depends("url_key")
def _compute_url_url_ids(self):
self.flush()
self.flush_model()
for record in self:
record.url_url_ids = record.env["url.url"].search(
[("model_id", "=", get_model_ref(record))]
Expand Down Expand Up @@ -182,15 +182,16 @@ def set_url(self, url_key):
else:
raise UserError(
_(
"Url_key already exist in other model"
"\n- name: %s\n - id: %s\n"
"- url_key: %s\n - url_key_id %s"
)
% (
existing_url.model_id.name,
existing_url.model_id.id,
existing_url.url_key,
existing_url.id,
"Url_key already exist in other model\n"
"- name: {model_name}\n"
"- id: {model_id}\n"
"- url_key: {url_key}\n"
"- url_key_id {ur_id}"
).format(
model_name=existing_url.model_id.name,
model_id=existing_url.model_id.id,
url_key=existing_url.url_key,
url_id=existing_url.id,
)
)
else:
Expand All @@ -210,7 +211,7 @@ def set_url(self, url_key):
# we must explicitly invalidate the cache since there is no depends
# defined on this computed fields and this field could have already
# been loaded into the cache
self.invalidate_cache(fnames=["url_url_ids"], ids=self.ids)
self.invalidate_recordset(fnames=["url_url_ids"])

def _redirect_existing_url(self):
"""
Expand All @@ -226,5 +227,5 @@ def unlink(self):
[("model_id", "=", get_model_ref(record))]
)
urls.unlink()
self.flush()
self.flush_model()
return super(AbstractUrl, self).unlink()
2 changes: 1 addition & 1 deletion base_url/models/url_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UrlUrl(models.Model):
readonly=True,
string="Model",
required=True,
index=True,
index="btree",
)
redirect = fields.Boolean(help="If tick this url is a redirection to the new url")
backend_id = fields.Reference(
Expand Down
3 changes: 1 addition & 2 deletions base_url/tests/models_mixin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright 2018 Simone Orsi - Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from operator import attrgetter

import mock
from unittest import mock


class TestMixin(object):
Expand Down
13 changes: 7 additions & 6 deletions base_url/tests/test_abstract_url.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock

from odoo_test_helper import FakeModelLoader

from odoo.exceptions import ValidationError
from odoo.tests import SavepointCase
from odoo.tests import TransactionCase


class TestAbstractUrl(SavepointCase, FakeModelLoader):
class TestAbstractUrl(TransactionCase, FakeModelLoader):
@classmethod
def setUpClass(cls):
super(TestAbstractUrl, cls).setUpClass()
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_write_url_builder(self):
def test_write_launching_automatic_url_key(self):
my_partner = self._create_auto()
# call flush to force to apply the recompute
my_partner.flush()
my_partner.flush_recordset()
my_partner.name = "my new name"
self.assertEqual(2, len(my_partner.url_url_ids))
url_keys = set(my_partner.mapped("url_url_ids.url_key"))
Expand All @@ -105,7 +106,7 @@ def test_write_launching_automatic_url_key(self):
def test_write_on_related_record_launching_automatic_url_key(self):
my_partner = self._create_auto()
# call flush to force to apply the recompute
my_partner.flush()
my_partner.flush_recordset()
my_partner.record_id.name = "my new name"
self.assertEqual(2, len(my_partner.url_url_ids))
url_keys = set(my_partner.mapped("url_url_ids.url_key"))
Expand All @@ -119,5 +120,5 @@ def test_write_inactive(self):
) as mocked_redirect:
my_partner.active = False
# call flush to force to apply the recompute
my_partner.flush()
my_partner.flush_recordset()
mocked_redirect.assert_called_once()
2 changes: 1 addition & 1 deletion base_url/views/url_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<record id="url_view_tree" model="ir.ui.view">
<field name="model">url.url</field>
<field name="arch" type="xml">
<tree string="">
<tree>
<field name="url_key" />
<field name="model_id" />
<field name="redirect" />
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# generated from manifests external_dependencies
openupgradelib
python-slugify
1 change: 1 addition & 0 deletions setup/base_url/odoo/addons/base_url
6 changes: 6 additions & 0 deletions setup/base_url/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 95a6b84

Please sign in to comment.