Skip to content

Commit

Permalink
[MIG] product_template_multi_link: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvh332 committed Dec 12, 2024
1 parent 02332b1 commit 3ed491e
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 62 deletions.
8 changes: 8 additions & 0 deletions product_template_multi_link/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ Contributors

- David Luis Mora <d.luis@binhex.cloud>

- Vo Hong Thien <thienvh@trobz.com>

Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion product_template_multi_link/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Product Multi Links (Template)",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Generic Modules",
"author": "GRAP, ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/e-commerce",
Expand Down
8 changes: 4 additions & 4 deletions product_template_multi_link/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections import defaultdict

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import AccessError


Expand Down Expand Up @@ -43,7 +43,7 @@ def _compute_product_template_link_count(self):
link_model = self.env["product.template.link"]
# Set product_template_link_qty to 0 if user has no access on the model
try:
link_model.check_access_rights("read")
link_model.check_access("read")
except AccessError:
for rec in self:
rec.product_template_link_count = 0
Expand Down Expand Up @@ -82,9 +82,9 @@ def _compute_product_template_link_count(self):
def show_product_template_links(self):
self.ensure_one()
return {
"name": _("Product links"),
"name": self.env._("Product links"),
"type": "ir.actions.act_window",
"view_mode": "tree,form",
"view_mode": "list,form",
"res_model": "product.template.link",
"domain": [
"|",
Expand Down
16 changes: 12 additions & 4 deletions product_template_multi_link/models/product_template_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from psycopg2.extensions import AsIs

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError


Expand All @@ -21,13 +21,19 @@ class ProductTemplateLink(models.Model):
ondelete="cascade",
index=True,
)
left_product_img = fields.Image(
string="Left Product Image", related="left_product_tmpl_id.image_128"
)
right_product_tmpl_id = fields.Many2one(
string="Linked Product",
comodel_name="product.template",
required=True,
ondelete="cascade",
index=True,
)
right_product_img = fields.Image(
string="Right Product Image", related="right_product_tmpl_id.image_128"
)
type_id = fields.Many2one(
string="Link type",
comodel_name="product.template.link.type",
Expand Down Expand Up @@ -59,7 +65,7 @@ def _check_products(self):
self.flush_recordset() # flush required since the method uses plain sql
if any(rec._check_product_not_different() for rec in self):
raise ValidationError(
_("You can only create a link between 2 different products")
self.env._("You can only create a link between 2 different products")
)

products = self.mapped("left_product_tmpl_id") + self.mapped(
Expand All @@ -75,7 +81,7 @@ def _check_products(self):
[link._duplicate_link_error_msg() for link in self.browse(ids)]
)
raise ValidationError(
_(
self.env._(
"Only one link with the same type is allowed between 2 "
"products. \n %s"
)
Expand Down Expand Up @@ -147,7 +153,9 @@ def _check_products_query_params(self):
)

def _duplicate_link_error_msg(self):
return f"{self.left_product_tmpl_id.name} <-> {self.link_type_name} / {self.link_type_inverse_name} <-> {self.right_product_tmpl_id.name}"
return f"""(
{self.left_product_tmpl_id.name} <-> {self.link_type_name} /
{self.link_type_inverse_name} <-> {self.right_product_tmpl_id.name})"""

@contextmanager
def _invalidate_links_on_product_template(self):
Expand Down
3 changes: 2 additions & 1 deletion product_template_multi_link/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Sylvain LE GAL \<<http://www.twitter.com/legalsylvain>\>
- [Binhex](https://binhex.cloud//com):
- David Luis Mora \<<d.luis@binhex.cloud>\>
- David Luis Mora \<<d.luis@binhex.cloud>\>
- Vo Hong Thien \<<thienvh@trobz.com>\>
1 change: 1 addition & 0 deletions product_template_multi_link/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
6 changes: 6 additions & 0 deletions product_template_multi_link/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,14 @@ <h1>Contributors</h1>
<li>David Luis Mora &lt;<a class="reference external" href="mailto:d.luis&#64;binhex.cloud">d.luis&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
<li>Vo Hong Thien &lt;<a class="reference external" href="mailto:thienvh&#64;trobz.com">thienvh&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h1>Other credits</h1>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h1>Maintainers</h1>
<p>This module is maintained by the OCA.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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

from odoo.addons.base.tests.common import BaseCommon

class TestProductTemplateLink(TransactionCase):

class TestProductTemplateLink(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
tracking_disable=True,
# compatibility flag when you run tests on a db
# where `product_variant_multi_link` is installed.
_product_variant_link_bypass_check=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from psycopg2 import IntegrityError

from odoo.tests import TransactionCase
from odoo.tools import mute_logger

from odoo.addons.base.tests.common import BaseCommon

class TestProductTemplateLinkType(TransactionCase):

class TestProductTemplateLinkType(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.LinkType = cls.env["product.template.link.type"]
cls.link_type_cross_selling = cls.env.ref(
"product_template_multi_link.product_template_link_type_cross_selling"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from odoo.addons.base.tests.common import BaseCommon


class TestProductTemplateLinker(TransactionCase):
class TestProductTemplateLinker(BaseCommon):
"""
Tests for product.template.linker
"""

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.wizard_obj = cls.env["product.template.linker"]
cls.product_link_obj = cls.env["product.template.link"]
cls.cross_sell = cls.env.ref(
Expand Down
4 changes: 2 additions & 2 deletions product_template_multi_link/views/action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<record id="action_product_template_link" model="ir.actions.act_window">
<field name="name">Product Links</field>
<field name="res_model">product.template.link</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_mode">list,kanban,form</field>
</record>
<record
id="action_product_template_link_from_product_template"
model="ir.actions.act_window"
>
<field name="name">Product Links</field>
<field name="res_model">product.template.link</field>
<field name="view_mode">tree,kanban</field>
<field name="view_mode">list,kanban</field>
<field name="domain">[('product_template_id', '=', id)]</field>
<field name="context">{'default_product_template_id': id}</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
<record model="ir.ui.view" id="product_template_link_type_tree_view">
<field
name="name"
>product.template.link.type.tree (in product_template_multi_link)</field>
>product.template.link.type.list (in product_template_multi_link)</field>
<field name="model">product.template.link.type</field>
<field name="arch" type="xml">
<tree editable="top">
<list editable="top">
<field name="is_symmetric" />
<field name="name" />
<field name="inverse_name" required="1" readonly="is_symmetric" />
<field name="code" />
<field name="inverse_code" readonly="is_symmetric" />
</tree>
</list>
</field>
</record>
<record model="ir.actions.act_window" id="product_template_link_type_act_window">
<field name="name">Product Template Link Type</field>
<field name="res_model">product.template.link.type</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="domain">[]</field>
<field name="context">{}</field>
</record>
Expand Down
68 changes: 33 additions & 35 deletions product_template_multi_link/views/product_template_link_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,60 @@
See odoo/addons/product/models/product_template.py // def name_search()
-->
<record id="product_template_link_tree" model="ir.ui.view">
<field name="name">Product.template.link.tree</field>
<field name="name">Product.template.link.list</field>
<field name="model">product.template.link</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="left_product_tmpl_id" domain="[('id', '!=', 0)]" />
<list editable="top">
<field name="left_product_tmpl_id" />
<field name="type_id" />
<field name="right_product_tmpl_id" domain="[('id', '!=', 0)]" />
</tree>
<field name="right_product_tmpl_id" />
</list>
</field>
</record>
<record id="product_template_link_kanban" model="ir.ui.view">
<field name="name">Product.template.link.kanban</field>
<field name="model">product.template.link</field>
<field name="arch" type="xml">
<kanban>
<field name="left_product_tmpl_id" />
<field name="right_product_tmpl_id" />
<field name="type_id" />
<templates>
<t t-name="kanban-box">
<div>
<div style="height: 64px; width: 45%; float:left;">
<div class="o_kanban_image">
<img
t-att-src="kanban_image('product.template', 'image_128', record.left_product_tmpl_id.raw_value)"
<t t-name="card" class="row g-0">
<div class="d-flex">
<div class="d-flex w-50" style="height: 64px;">
<aside class="p-0">
<field
name="left_product_img"
widget="image"
alt="Product"
class="o_image_64_contain"
/>
</div>
<div class="oe_kanban_details" style="font-size: 10px;">
</aside>
<main
class="col-8 d-flex flex-column overflow-hidden"
style="font-size: 10px;"
>
<field name="left_product_tmpl_id" />
</div>
</main>
</div>
<div
name="product_template_link_type"
style="height: 64px; width: 10%; float:left;"
class="overflow-hidden"
style="height: 64px; width: 15%;"
>
<field name="type_id" />
</div>
<div style="height: 64px; width: 45%; float:left;">
<div class="o_kanban_image">
<img
t-att-src="kanban_image('product.template', 'image_128', record.right_product_tmpl_id.raw_value)"
<div class="d-flex w-50" style="height: 64px;">
<aside class="p-0">
<field
name="right_product_img"
widget="image"
alt="Product"
class="o_image_64_contain"
/>
</div>
<div class="oe_kanban_details" style="font-size: 10px;">
</aside>
<main
class="col-8 d-flex flex-column overflow-hidden"
style="font-size: 10px;"
>
<field name="right_product_tmpl_id" />
</div>
</main>
</div>
</div>
</t>
Expand All @@ -93,14 +97,8 @@
<group name="main">
<group name="products">
<field name="type_id" />
<field
name="left_product_tmpl_id"
domain="[('id', '!=', 0)]"
/>
<field
name="right_product_tmpl_id"
domain="[('id', '!=', 0)]"
/>
<field name="left_product_tmpl_id" />
<field name="right_product_tmpl_id" />
</group>
</group>
</sheet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
colspan="2"
options="{'no_open':True, 'no_create':True}"
>
<tree>
<list>
<field name="name" />
<field name="default_code" />
</tree>
</list>
</field>
</group>
<footer>
Expand Down

0 comments on commit 3ed491e

Please sign in to comment.