Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] Fix/improve URL mgmt #1566

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions base_url/models/abstract_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ def _compute_redirect_url_url_ids(self):
self.flush()
for record in self:
record.redirect_url_url_ids = record.env["url.url"].search(
[
("model_id", "=", get_model_ref(record)),
("redirect", "=", True),
]
record._redirect_url_domain()
)

def _redirect_url_domain(self):
return [
("model_id", "=", get_model_ref(self)),
("redirect", "=", True),
]

@api.depends("url_key")
def _compute_url_url_ids(self):
self.flush()
Expand Down Expand Up @@ -228,3 +231,16 @@ def unlink(self):
urls.unlink()
self.flush()
return super(AbstractUrl, self).unlink()

def action_view_redirect_url(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id(
"base_url.base_url_action_view"
)
action["name"] = action["display_name"] = _("Redirects")
action["domain"] = self._redirect_url_domain()
action["context"] = {
"default_model_id": get_model_ref(self),
"default_redirect": True,
}
return action
2 changes: 1 addition & 1 deletion base_url/models/url_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UrlUrl(models.Model):
selection="_selection_target_model",
help="The id of content linked to the url.",
readonly=True,
string="Model",
string="Record",
required=True,
index=True,
)
Expand Down
27 changes: 22 additions & 5 deletions base_url/views/url_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,28 @@
<record id="url_view_tree" model="ir.ui.view">
<field name="model">url.url</field>
<field name="arch" type="xml">
<tree string="">
<field name="url_key" />
<field name="model_id" />
<field name="redirect" />
</tree>
<tree string="">
<field name="url_key" />
<field name="model_id" />
<field name="redirect" />
</tree>
</field>
</record>

<record id="url_view_search" model="ir.ui.view">
<field name="model">url.url</field>
<field name="arch" type="xml">
<search string="">
<field name="url_key" />
<field name="model_id" />
<group expand="0" string="Group By">
<filter
string="Record"
name="groupby_model_id"
context="{'group_by': 'model_id'}"
/>
</group>
</search>
</field>
</record>

Expand Down
6 changes: 6 additions & 0 deletions shopinvader/views/shopinvader_category_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<field name="url_key" />
</tree>
</field>
<button
name="action_view_redirect_url"
type="object"
string="Manage redirects"
class="oe_inline"
/>
</group>
</page>
</notebook>
Expand Down
7 changes: 7 additions & 0 deletions shopinvader/views/shopinvader_product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@
<field name="url_key" string="Redirect Url" />
</tree>
</field>
<button
name="action_view_redirect_url"
type="object"
string="Manage redirects"
class="oe_inline"
/>

</group>
</page>
<page name="variant" string="Variant">
Expand Down
14 changes: 14 additions & 0 deletions shopinvader/views/shopinvader_variant_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,18 @@
<field name="sequence" eval="20" />
</record>

<record id="shopinvader_urls_act_window" model="ir.actions.act_window">
<field name="name">URLs</field>
<field name="res_model">url.url</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('model_id', 'like', 'shopinvader.%')]</field>
</record>

<record model="ir.ui.menu" id="menu_shopinvader_urls">
<field name="name">URLs</field>
<field name="parent_id" ref="menu_shopinvader_products" />
<field name="action" ref="shopinvader_urls_act_window" />
<field name="sequence" eval="999" />
</record>

</odoo>
Loading