Skip to content

Commit

Permalink
Merge PR #478 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
shopinvader-git-bot committed Oct 29, 2019
2 parents b13b7a7 + 1fda49a commit a9c87c1
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ force_grid_wrap=0
combine_as_imports=True
use_parentheses=True
line_length=79
known_third_party = StringIO,mock,odoo,openupgradelib,psycopg2,requests,urllib2,vcr,vcr_unittest,werkzeug
known_third_party = StringIO,mock,odoo,openupgradelib,psycopg2,requests,setuptools,urllib2,vcr,vcr_unittest,werkzeug
6 changes: 3 additions & 3 deletions base_url/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

{
"name": "Base Url",
"version": "12.0.0.1.0",
"version": "13.0.1.0.0",
"category": "tools",
"license": "AGPL-3",
"summary": "keep history of url for products & categories ",
"author": "Akretion, ACSONE SA/NV",
"website": "https://github.com/shopinvader",
# any module necessary for this one to work correctly
"depends": ["base"],
"external_dependencies": {"python": ["slugify"]},
"external_dependencies": {"python": ["python-slugify"]},
"data": ["views/url_view.xml", "security/ir.model.access.csv"],
"url": "",
"installable": False,
"installable": True,
}
12 changes: 4 additions & 8 deletions base_url/models/abstract_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,16 @@ def on_url_key_change(self):
}
}

@api.multi
@api.depends("url_key")
def _compute_is_urls_sync_required(self):
for record in self:
record.is_urls_sync_required = True

@api.multi
def _compute_automatic_url_key(self):
raise NotImplementedError(
"Automatic url key must be computed in concrete model"
)

@api.multi
@api.depends(
"manual_url_key", "automatic_url_key", "url_builder", "active"
)
Expand All @@ -94,7 +91,6 @@ def _compute_url_key(self):
new_url = record.automatic_url_key
record.url_key = new_url

@api.multi
def _compute_redirect_url_url_ids(self):
for record in self:
record.redirect_url_url_ids = record.env["url.url"].search(
Expand All @@ -104,7 +100,6 @@ def _compute_redirect_url_url_ids(self):
]
)

@api.multi
def _compute_url_url_ids(self):
for record in self:
record.url_url_ids = record.env["url.url"].search(
Expand Down Expand Up @@ -175,6 +170,10 @@ def set_url(self, url_key):
]
)
redirect_urls.write({"redirect": True})
# 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)

def _redirect_existing_url(self):
"""
Expand All @@ -183,7 +182,6 @@ def _redirect_existing_url(self):
"""
return True

@api.multi
def _sync_urls(self):
"""
This method is in charge of syncing the url.url object related to
Expand All @@ -204,14 +202,12 @@ def create(self, value):
super(AbstractUrl, synced).write({"is_urls_sync_required": False})
return res

@api.multi
def write(self, value):
res = super(AbstractUrl, self).write(value)
synced = self._sync_urls()
super(AbstractUrl, synced).write({"is_urls_sync_required": False})
return res

@api.multi
def unlink(self):
for record in self:
# TODO we should propose to redirect the old url
Expand Down
9 changes: 7 additions & 2 deletions base_url/models/url_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UrlUrl(models.Model):

url_key = fields.Char(required=True)
model_id = fields.Reference(
selection=[],
selection="_selection_target_model",
help="The id of content linked to the url.",
readonly=True,
string="Model",
Expand All @@ -28,7 +28,7 @@ class UrlUrl(models.Model):
help="If tick this url is a redirection to the new url"
)
backend_id = fields.Reference(
selection=[],
selection="_selection_target_model",
compute="_compute_related_fields",
store=True,
help="Backend linked to this URL",
Expand All @@ -46,6 +46,11 @@ class UrlUrl(models.Model):
)
]

@api.model
def _selection_target_model(self):
models = self.env["ir.model"].search([])
return [(model.model, model.name) for model in models]

@api.depends("model_id")
def _compute_related_fields(self):
for record in self:
Expand Down
1 change: 0 additions & 1 deletion base_url/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ResPartnerAddressableFake(models.Model, TestMixin):

backend_id = fields.Many2one(comodel_name="url.backend.fake")

@api.multi
@api.depends("lang_id", "record_id.name")
def _compute_automatic_url_key(self):
key_by_id = {}
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-slugify>=3.0.2
1 change: 1 addition & 0 deletions setup/base_url/odoo/addons/base_url
10 changes: 10 additions & 0 deletions setup/base_url/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import setuptools

setuptools.setup(
setup_requires=["setuptools-odoo"],
odoo_addon={
"external_dependencies_override": {
"python": {"slugify": "python-slugify>=3.0.2"}
}
},
)
1 change: 1 addition & 0 deletions shopinvader_locomotive_elasticsearch/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
"shopinvader_locomotive",
"shopinvader_elasticsearch",
],
"installable": False,
}
1 change: 1 addition & 0 deletions shopinvader_pending_cart_reminder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
"data/mail_template.xml",
"views/shopinvader_backend.xml",
],
"installable": False,
}

0 comments on commit a9c87c1

Please sign in to comment.