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

[FIX] attribute_set: fix wizard vlidate button #199

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions attribute_set/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Contributors
* Akretion Raphaël VALYI <raphael.valyi@akretion.com>
* David Dufresne <david.dufresne@savoirfairelinux.com>
* Denis Roussel <denis.roussel@acsone.eu>
* Mohamed Alkobrosli <malkobrosly@kencove.com>

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions attribute_set/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* Akretion Raphaël VALYI <raphael.valyi@akretion.com>
* David Dufresne <david.dufresne@savoirfairelinux.com>
* Denis Roussel <denis.roussel@acsone.eu>
* Mohamed Alkobrosli <malkobrosly@kencove.com>
13 changes: 8 additions & 5 deletions attribute_set/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -436,12 +436,15 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Akretion Raphaël VALYI &lt;<a class="reference external" href="mailto:raphael.valyi&#64;akretion.com">raphael.valyi&#64;akretion.com</a>&gt;</li>
<li>David Dufresne &lt;<a class="reference external" href="mailto:david.dufresne&#64;savoirfairelinux.com">david.dufresne&#64;savoirfairelinux.com</a>&gt;</li>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li>Mohamed Alkobrosli &lt;<a class="reference external" href="mailto:malkobrosly&#64;kencove.com">malkobrosly&#64;kencove.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
37 changes: 37 additions & 0 deletions attribute_set/tests/test_custom_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,40 @@ def test_create_attribute_company_dependent(self):
self.assertTrue(
self.env["res.partner"]._fields[attribute.name].company_dependent
)

def test_wizard_validate(self):
model_id = self.env["ir.model"].search([("model", "=", "res.partner")])
attribute = self._create_attribute(
{
"attribute_type": "select",
"option_ids": [
(0, 0, {"name": "Value 1"}),
(0, 0, {"name": "Value 2"}),
],
"relation_model_id": model_id.id,
}
)
PartnerModel = self.env["res.partner"]
partner = PartnerModel.create({"name": "John Doe"})
vals = {
"attribute_id": attribute.id,
"option_ids": [[[attribute.id], partner.name, [partner.id]]],
}
OptionWizard = self.env["attribute.option.wizard"]
# attribute has only two options
len_2 = len(attribute.option_ids)
self.assertTrue(len_2 == 2)
# a new option should be created
wizard1 = OptionWizard.create(vals)
len_3 = len(attribute.option_ids)
self.assertTrue(len_3 > 2)
self.assertIn(partner.name, attribute.option_ids.mapped("name"))
vals = {
"attribute_id": attribute.id,
}
# no option should be created
# as option_ids key is not passed in vals
wizard2 = OptionWizard.create(vals)
len_default = len(attribute.option_ids)
self.assertTrue(wizard1 != wizard2)
self.assertEqual(len_default, len_3)
8 changes: 7 additions & 1 deletion attribute_set/wizard/attribute_option_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
default=lambda self: self.env.context.get("attribute_id", False),
ondelete="cascade",
)
option_ids = fields.Many2many(
"attribute.option",
string="Attribute Options",
)

def validate(self):
return True
Expand All @@ -37,6 +41,8 @@
model = attr.relation_model_id.model

name = self.env[model].browse(op_id).name_get()[0][1]
vals["option_ids"][0][1] = name
vals["option_ids"][0][0] = [vals["attribute_id"]]
opt_obj.create(
{
"attribute_id": vals["attribute_id"],
Expand Down Expand Up @@ -82,7 +88,7 @@
)

eview = etree.fromstring(res["arch"])
options = etree.Element("field", name="option_ids", nolabel="1")
options = etree.Element("field", name="option_ids", widget="many2many_tags")

Check warning on line 91 in attribute_set/wizard/attribute_option_wizard.py

View check run for this annotation

Codecov / codecov/patch

attribute_set/wizard/attribute_option_wizard.py#L91

Added line #L91 was not covered by tests
placeholder = eview.xpath("//separator[@string='options_placeholder']")[0]
placeholder.getparent().replace(placeholder, options)
res["arch"] = etree.tostring(eview, pretty_print=True)
Expand Down