Skip to content

Commit 9a77352

Browse files
committed
Fix Linters
1 parent 34543fd commit 9a77352

File tree

11 files changed

+193
-158
lines changed

11 files changed

+193
-158
lines changed

product_template_attribute_value_xmlid/README.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,13 @@ Important Considerations
191191
Known issues / Roadmap
192192
======================
193193

194-
[ Enumerate known caveats and future potential improvements. It is
195-
mostly intended for end-users, and can also help potential new
196-
contributors discovering new features to implement. ]
197-
198194
- This module might result in unpredictable behaviour when used with
199195
enterprise module ``product_barcodelookup``.
200196

201197
Changelog
202198
=========
203199

204-
[ The change log. The goal of this file is to help readers understand
205-
changes between version. The primary audience is end users and
206-
integrators. Purely technical changes such as code refactoring must not
207-
be mentioned here.
208200

209-
This file may contain ONE level of section titles, underlined with the ~
210-
(tilde) character. Other section markers are forbidden and will likely
211-
break the structure of the README.rst or other documents where this
212-
fragment is included. ]
213201

214202
Bug Tracker
215203
===========

product_template_attribute_value_xmlid/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Odoo Data Flow
32
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
43

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Odoo Data Flow
32
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
43

54
{
6-
'name': 'Generate XML IDs for Product Template Attribute Values',
7-
'version': '18.0.1.0.0',
8-
'summary': 'Generates predictable XML IDs for product.template.attribute.value records based on template and attribute values. These can be used to generate predictable combinations for product.product records.',
9-
'description': 'This module generates XML IDs for product.template.attribute.value records after importing product.template.attribute.line.',
10-
'author': 'Odoo Data Flow',
11-
'website': 'https://github.com/OdooDataFlow/addons',
12-
'category': 'Technical Settings',
13-
'version': '18.0.1.0.0',
14-
'depends': [
15-
'product',
16-
'sale_management',
17-
5+
"name": "Generate XML IDs for Product Template Attribute Values",
6+
"version": "18.0.1.0.0",
7+
"summary": (
8+
"Generates predictable XML IDs for "
9+
"product.template.attribute.value records based on template "
10+
"and attribute values. These can be used to generate predictable "
11+
"combinations for product.product records."
12+
),
13+
"author": "Odoo Data Flow",
14+
"website": "https://github.com/OdooDataFlow/addons",
15+
"category": "Technical Settings",
16+
"depends": [
17+
"product",
18+
"sale_management",
1819
],
1920
# 'excludes': ['product_barcodelookup',],
20-
'data': ['views/product_template_attribute_view.xml'],
21-
'license': 'LGPL-3',
22-
'installable': True,
23-
'cloc_exclude': [
24-
]
21+
"data": ["views/product_template_attribute_view.xml"],
22+
"license": "LGPL-3",
23+
"installable": True,
24+
"cloc_exclude": [],
2525
}
Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from odoo import models, api, _
1+
from odoo import _, api, models
2+
23

34
class ProductTemplateAttributeValueXMLID(models.Model):
4-
_inherit = 'product.template.attribute.value'
5+
_inherit = "product.template.attribute.value"
56

67
@api.model_create_multi
78
def create(self, vals_list):
@@ -10,33 +11,51 @@ def create(self, vals_list):
1011
"""
1112
records = super().create(vals_list)
1213
for record in records:
13-
self._generate_xmlid_for_record(record) # Generate XML ID for each new record
14+
self._generate_xmlid_for_record(
15+
record
16+
) # Generate XML ID for each new record
1417
return records
1518

1619
def _generate_xmlid_for_record(self, attribute_value):
1720
"""
1821
Generates the XML ID for a given product.template.attribute.value record.
1922
"""
2023
# 2. Generate the XML ID using XML IDs of related records
21-
prod_templ_id = self._get_xml_id(attribute_value.product_tmpl_id) if attribute_value.product_tmpl_id else ''
22-
attribute_id = self._get_xml_id(attribute_value.attribute_id) if attribute_value.attribute_id else ''
23-
attribute_value_id = self._get_xml_id(attribute_value.product_attribute_value_id) if attribute_value.product_attribute_value_id else ''
24+
prod_templ_id = (
25+
self._get_xml_id(attribute_value.product_tmpl_id)
26+
if attribute_value.product_tmpl_id
27+
else ""
28+
)
29+
(
30+
self._get_xml_id(attribute_value.attribute_id)
31+
if attribute_value.attribute_id
32+
else ""
33+
)
34+
attribute_value_id = (
35+
self._get_xml_id(attribute_value.product_attribute_value_id)
36+
if attribute_value.product_attribute_value_id
37+
else ""
38+
)
2439

2540
xml_id = f"{prod_templ_id}_{attribute_value_id}".replace(" ", "_")
2641

2742
# 3. Create the ir.model.data record
2843
try:
29-
self.env['ir.model.data'].create({
30-
'module': 'product_template_attribute_value',
31-
'name': xml_id,
32-
'model': 'product.template.attribute.value',
33-
'res_id': attribute_value.id,
34-
'noupdate': True,
35-
})
44+
self.env["ir.model.data"].create(
45+
{
46+
"module": "product_template_attribute_value",
47+
"name": xml_id,
48+
"model": "product.template.attribute.value",
49+
"res_id": attribute_value.id,
50+
"noupdate": True,
51+
}
52+
)
3653
except Exception as e:
3754
self.env.cr.rollback() # Rollback in case of error
3855
self.env.cr.commit()
39-
self.env.logger.error(f"Error creating XML ID for product.template.attribute.value: {e}")
56+
self.env.logger.error(
57+
f"Error creating XML ID for product.template.attribute.value: {e}"
58+
)
4059

4160
@api.model
4261
def generate_attribute_value_xmlids(self, *args):
@@ -45,21 +64,45 @@ def generate_attribute_value_xmlids(self, *args):
4564
using the format: XMLID = prod_templ_id + attribute_id + attribute_value_id
4665
"""
4766
# 1. Get the product.template.attribute.value records that DO NOT have an XML ID
48-
attribute_values_without_xmlid = self.env['product.template.attribute.value'].search([
49-
('id', 'not in', self.env['ir.model.data'].search([('model', '=', 'product.template.attribute.value')]).mapped('res_id'))
50-
])
67+
attribute_values_without_xmlid = self.env[
68+
"product.template.attribute.value"
69+
].search(
70+
[
71+
(
72+
"id",
73+
"not in",
74+
self.env["ir.model.data"]
75+
.search([("model", "=", "product.template.attribute.value")])
76+
.mapped("res_id"),
77+
)
78+
]
79+
)
5180

5281
for attribute_value in attribute_values_without_xmlid:
5382
self._generate_xmlid_for_record(attribute_value)
5483

55-
return {'type': 'ir.actions.client', 'tag': 'display_notification', 'params': {'title': _('XML IDs Created'), 'message': _('XML IDs for product.template.attribute.value records have been generated.'), 'type': 'success'}}
84+
return {
85+
"type": "ir.actions.client",
86+
"tag": "display_notification",
87+
"params": {
88+
"title": _("XML IDs Created"),
89+
"message": _(
90+
"XML IDs for product.template.attribute.value",
91+
"records have been generated.",
92+
),
93+
"type": "success",
94+
},
95+
}
5696

5797
def _get_xml_id(self, record):
5898
"""Helper function to get the XML ID of a record."""
5999
if not record:
60-
return ''
61-
xml_ids = self.env['ir.model.data'].search([
62-
('model', '=', record._name),
63-
('res_id', '=', record.id),
64-
], limit=1)
65-
return xml_ids.name if xml_ids else ''
100+
return ""
101+
xml_ids = self.env["ir.model.data"].search(
102+
[
103+
("model", "=", record._name),
104+
("res_id", "=", record.id),
105+
],
106+
limit=1,
107+
)
108+
return xml_ids.name if xml_ids else ""
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
[ The change log. The goal of this file is to help readers
2-
understand changes between version. The primary audience is
3-
end users and integrators. Purely technical changes such as
4-
code refactoring must not be mentioned here.
5-
6-
This file may contain ONE level of section titles, underlined
7-
with the ~ (tilde) character. Other section markers are
8-
forbidden and will likely break the structure of the README.rst
9-
or other documents where this fragment is included. ]
101

112

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
[ Enumerate known caveats and future potential improvements.
2-
It is mostly intended for end-users, and can also help
3-
potential new contributors discovering new features to implement. ]
41

52
- This module might result in unpredictable behaviour when used with enterprise module `product_barcodelookup`.

product_template_attribute_value_xmlid/static/description/index.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,24 +521,13 @@ <h1>Important Considerations</h1>
521521
</ul>
522522
<div class="section" id="known-issues-roadmap">
523523
<h2>Known issues / Roadmap</h2>
524-
<p>[ Enumerate known caveats and future potential improvements. It is
525-
mostly intended for end-users, and can also help potential new
526-
contributors discovering new features to implement. ]</p>
527524
<ul class="simple">
528525
<li>This module might result in unpredictable behaviour when used with
529526
enterprise module <tt class="docutils literal">product_barcodelookup</tt>.</li>
530527
</ul>
531528
</div>
532529
<div class="section" id="changelog">
533530
<h2>Changelog</h2>
534-
<p>[ The change log. The goal of this file is to help readers understand
535-
changes between version. The primary audience is end users and
536-
integrators. Purely technical changes such as code refactoring must not
537-
be mentioned here.</p>
538-
<p>This file may contain ONE level of section titles, underlined with the ~
539-
(tilde) character. Other section markers are forbidden and will likely
540-
break the structure of the README.rst or other documents where this
541-
fragment is included. ]</p>
542531
</div>
543532
<div class="section" id="bug-tracker">
544533
<h2>Bug Tracker</h2>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

product_template_attribute_value_xmlid/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Odoo Data Flow
32
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
43

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
from odoo.tests.common import TransactionCase, tagged
2-
from odoo import fields, Command
2+
33

44
@tagged("post_install", "-at_install")
55
class TestProductTemplateAttributeValueXMLID(TransactionCase):
6-
76
def setUp(self):
87
super().setUp()
98
# Create common product template and attribute (dynamic variant creation)
10-
self.product_template = self.env['product.template'].create({
11-
'name': 'Test Template',
12-
})
13-
self.attribute = self.env['product.attribute'].create({
14-
'name': 'Test Attribute',
15-
'create_variant': 'dynamic',
16-
})
17-
self.attribute_value = self.env['product.attribute.value'].create({
18-
'name': 'Test Value',
19-
'attribute_id': self.attribute.id,
20-
})
9+
self.product_template = self.env["product.template"].create(
10+
{
11+
"name": "Test Template",
12+
}
13+
)
14+
self.attribute = self.env["product.attribute"].create(
15+
{
16+
"name": "Test Attribute",
17+
"create_variant": "dynamic",
18+
}
19+
)
20+
self.attribute_value = self.env["product.attribute.value"].create(
21+
{
22+
"name": "Test Value",
23+
"attribute_id": self.attribute.id,
24+
}
25+
)
2126

2227
def test_xmlid_generation_on_ptav_creation(self):
2328
"""
@@ -26,39 +31,61 @@ def test_xmlid_generation_on_ptav_creation(self):
2631
automatically during variant creation.
2732
"""
2833
# 1. Create a product.template.attribute.line
29-
attribute_line = self.env['product.template.attribute.line'].create({
30-
'product_tmpl_id': self.product_template.id,
31-
'attribute_id': self.attribute.id,
32-
'value_ids': [(6, 0, [self.attribute_value.id])],
33-
})
34+
attribute_line = self.env["product.template.attribute.line"].create(
35+
{
36+
"product_tmpl_id": self.product_template.id,
37+
"attribute_id": self.attribute.id,
38+
"value_ids": [(6, 0, [self.attribute_value.id])],
39+
}
40+
)
3441

3542
# 2. Trigger Variant Creation (Simulate Selection)
3643
# This forces Odoo to create the product.template.attribute.value record
37-
context = {'default_product_tmpl_id': self.product_template.id}
38-
self.product_template.with_context(context).write({
39-
'attribute_line_ids': [(1, attribute_line.id, {'value_ids': [(6, 0, [self.attribute_value.id])]})]
40-
})
44+
context = {"default_product_tmpl_id": self.product_template.id}
45+
self.product_template.with_context(**context).write(
46+
{
47+
"attribute_line_ids": [
48+
(
49+
1,
50+
attribute_line.id,
51+
{"value_ids": [(6, 0, [self.attribute_value.id])]},
52+
)
53+
]
54+
}
55+
)
4156

4257
# 3. Find the Automatically Created product.template.attribute.value
43-
ptav = self.env['product.template.attribute.value'].search([
44-
('attribute_line_id', '=', attribute_line.id),
45-
('product_attribute_value_id', '=', self.attribute_value.id)
46-
], limit=1)
58+
ptav = self.env["product.template.attribute.value"].search(
59+
[
60+
("attribute_line_id", "=", attribute_line.id),
61+
("product_attribute_value_id", "=", self.attribute_value.id),
62+
],
63+
limit=1,
64+
)
4765
self.assertTrue(ptav, "product.template.attribute.value was not created")
4866

4967
# 4. Check for XML ID on the product.template.attribute.value
50-
xml_id = self.env['ir.model.data'].search([
51-
('model', '=', 'product.template.attribute.value'),
52-
('res_id', '=', ptav.id),
53-
], limit=1)
54-
self.assertTrue(xml_id, f"No XML ID generated for product.template.attribute.value: {ptav.id}")
68+
xml_id = self.env["ir.model.data"].search(
69+
[
70+
("model", "=", "product.template.attribute.value"),
71+
("res_id", "=", ptav.id),
72+
],
73+
limit=1,
74+
)
75+
self.assertTrue(
76+
xml_id,
77+
f"No XML ID generated for product.template.attribute.value: {ptav.id}",
78+
)
5579

5680
def _get_xml_id(self, record):
5781
"""Helper function to get the XML ID of a record."""
5882
if not record:
59-
return ''
60-
xml_ids = self.env['ir.model.data'].search([
61-
('model', '=', record._name),
62-
('res_id', '=', record.id),
63-
], limit=1)
64-
return xml_ids.name if xml_ids else ''
83+
return ""
84+
xml_ids = self.env["ir.model.data"].search(
85+
[
86+
("model", "=", record._name),
87+
("res_id", "=", record.id),
88+
],
89+
limit=1,
90+
)
91+
return xml_ids.name if xml_ids else ""

0 commit comments

Comments
 (0)