Skip to content

Commit

Permalink
[MIG] base_view_inheritance_extension: Migration to 18.0
Browse files Browse the repository at this point in the history
[MIG] base_view_inheritance_extension: Migration to 18.0

fix review point

fix test case adap v18

Co-authored-by: Lukas Tran <[email protected]>
  • Loading branch information
fredericgrall and Lukas Tran committed Nov 15, 2024
1 parent 0dcd178 commit 7fc2f5d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 102 deletions.
29 changes: 17 additions & 12 deletions base_view_inheritance_extension/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Extended view inheritance
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/17.0/base_view_inheritance_extension
:target: https://github.com/OCA/server-tools/tree/18.0/base_view_inheritance_extension
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-base_view_inheritance_extension
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_view_inheritance_extension
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -75,15 +75,15 @@ conditional changes**
Known issues / Roadmap
======================

- Support an ``eval`` attribute for our new node types.
- Support an ``eval`` attribute for our new node types.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_view_inheritance_extension%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_view_inheritance_extension%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -98,14 +98,19 @@ Authors
Contributors
------------

- Holger Brunn <[email protected]>
- Ronald Portier <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:
- Holger Brunn <[email protected]>
- Ronald Portier <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Sergio Teruel
- Carlos Dauden
- Sergio Teruel
- Carlos Dauden

- Iván Todorovich <[email protected]>
- `Trobz <https://www.trobz.com>`__:

- Nhan Tran <[email protected]>

- Iván Todorovich <[email protected]>
- Frederic Grall <[email protected]>

Maintainers
-----------
Expand All @@ -120,6 +125,6 @@ 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.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/base_view_inheritance_extension>`_ project on GitHub.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/base_view_inheritance_extension>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_view_inheritance_extension/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Extended view inheritance",
"version": "17.0.1.0.1",
"version": "18.0.1.0.0",
"development_status": "Mature",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "LGPL-3",
Expand Down
26 changes: 13 additions & 13 deletions base_view_inheritance_extension/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def ast_dict_update(source, update):

def ast_key_eq(k1, k2):
# python < 3.8 uses ast.Str; python >= 3.8 uses ast.Constant
if type(k1) != type(k2):
if type(k1) is not type(k2):
return False

Check warning on line 34 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L34

Added line #L34 was not covered by tests
elif isinstance(k1, ast.Str):
return k1.s == k2.s
Expand Down Expand Up @@ -84,21 +84,21 @@ def _iter_inheritance_specs(self, spec):
@api.model
def _get_inheritance_handler(self, node):
handler = super().apply_inheritance_specs
if hasattr(self, "inheritance_handler_%s" % node.tag):
handler = getattr(self, "inheritance_handler_%s" % node.tag)
if hasattr(self, f"inheritance_handler_{node.tag}"):
handler = getattr(self, f"inheritance_handler_{node.tag}")

Check warning on line 88 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L88

Added line #L88 was not covered by tests
return handler

@api.model
def _get_inheritance_handler_attributes(self, node):
handler = super().apply_inheritance_specs
if hasattr(self, "inheritance_handler_attributes_%s" % node.get("operation")):
if hasattr(self, f"_inheritance_handler_attributes_{node.get('operation')}"):
handler = getattr(
self, "inheritance_handler_attributes_%s" % node.get("operation")
self, f"_inheritance_handler_attributes_{node.get('operation')}"
)
return handler

@api.model
def inheritance_handler_attributes_update(self, source, specs):
def _inheritance_handler_attributes_update(self, source, specs):
"""Implement dict `update` operation on the attribute node.
.. code-block:: xml
Expand Down Expand Up @@ -133,7 +133,7 @@ def inheritance_handler_attributes_update(self, source, specs):
return source

@api.model
def inheritance_handler_attributes_text_add(self, source, specs):
def _inheritance_handler_attributes_text_add(self, source, specs):
"""Implement
<$node position="attributes">
<attribute name="$attribute" operation="text_add">
Expand All @@ -150,7 +150,7 @@ def inheritance_handler_attributes_text_add(self, source, specs):
return source

Check warning on line 150 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L150

Added line #L150 was not covered by tests

@api.model
def inheritance_handler_attributes_domain_add(self, source, specs):
def _inheritance_handler_attributes_domain_add(self, source, specs):
"""Implement
<$node position="attributes">
<attribute name="$attribute" operation="domain_add"
Expand All @@ -166,16 +166,16 @@ def inheritance_handler_attributes_domain_add(self, source, specs):
old_value = node.get(attribute_name) or ""

Check warning on line 166 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L163-L166

Added lines #L163 - L166 were not covered by tests
if old_value:
old_domain = ast.literal_eval(

Check warning on line 168 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L168

Added line #L168 was not covered by tests
self.var2str_domain_text(old_value.strip())
self._var2str_domain_text(old_value.strip())
)
new_domain = ast.literal_eval(

Check warning on line 171 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L171

Added line #L171 was not covered by tests
self.var2str_domain_text(attribute_node.text.strip())
self._var2str_domain_text(attribute_node.text.strip())
)
if join_operator == "OR":
new_value = str(expression.OR([old_domain, new_domain]))

Check warning on line 175 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L175

Added line #L175 was not covered by tests
else:
new_value = str(expression.AND([old_domain, new_domain]))
new_value = self.str2var_domain_text(new_value)
new_value = self._str2var_domain_text(new_value)

Check warning on line 178 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L177-L178

Added lines #L177 - L178 were not covered by tests
else:
# We must ensure that the domain definition has not line breaks because
# in update mode the domain cause an invalid syntax error
Expand All @@ -186,7 +186,7 @@ def inheritance_handler_attributes_domain_add(self, source, specs):
return source

Check warning on line 186 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L184-L186

Added lines #L184 - L186 were not covered by tests

@api.model
def var2str_domain_text(self, domain_str):
def _var2str_domain_text(self, domain_str):
"""Replaces var names with str names to allow eval without defined vars"""
# Replace fields in 2 steps because 1 step returns "parent_sufix"."var_sufix"
regex_parent = re.compile(r"parent\.(\b\w+\b)")
Expand All @@ -197,7 +197,7 @@ def var2str_domain_text(self, domain_str):
return re.sub(regex, r"'\1_is_a_var_to_replace'", domain_str)

Check warning on line 197 in base_view_inheritance_extension/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

base_view_inheritance_extension/models/ir_ui_view.py#L196-L197

Added lines #L196 - L197 were not covered by tests

@api.model
def str2var_domain_text(self, domain_str):
def _str2var_domain_text(self, domain_str):
"""Revert var2str_domain_text cleaning apostrophes and suffix in vars"""
pattern = re.compile(r"'(parent\.[^']+)_is_a_var_to_replace'")
domain_str = pattern.sub(r"\1", domain_str)
Expand Down
3 changes: 3 additions & 0 deletions base_view_inheritance_extension/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
- [Tecnativa](https://www.tecnativa.com):
- Sergio Teruel
- Carlos Dauden
- [Trobz](https://www.trobz.com):
- Nhan Tran \<<[email protected]>\>
- Iván Todorovich \<<[email protected]>\>
- Frederic Grall \<<[email protected]>>
22 changes: 15 additions & 7 deletions base_view_inheritance_extension/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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 @@ -274,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 @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

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

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Extended view inheritance</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:40e4b7b41dc5bf755dd39eedafb3e373b93138ec06e6e21c52c55857a4f28dd5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/17.0/base_view_inheritance_extension"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-base_view_inheritance_extension"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/base_view_inheritance_extension"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_view_inheritance_extension"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to make it simple to add custom operators for
view inheritance.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -425,7 +426,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_view_inheritance_extension%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_view_inheritance_extension%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -446,17 +447,24 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Carlos Dauden</li>
</ul>
</li>
<li><a class="reference external" href="https://www.trobz.com">Trobz</a>:<ul>
<li>Nhan Tran &lt;<a class="reference external" href="mailto:nhant&#64;trobz.com">nhant&#64;trobz.com</a>&gt;</li>
</ul>
</li>
<li>Iván Todorovich &lt;<a class="reference external" href="mailto:ivan.todorovich&#64;camptocamp.com">ivan.todorovich&#64;camptocamp.com</a>&gt;</li>
<li>Frederic Grall &lt;<a class="reference external" href="mailto:fgr&#64;apik.cloud">fgr&#64;apik.cloud</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">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>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/17.0/base_view_inheritance_extension">OCA/server-tools</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/18.0/base_view_inheritance_extension">OCA/server-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,70 +104,7 @@ def test_update_context_complex(self):
]
self.assertEqual(
res.xpath('//field[@name="invoice_line_ids"]')[0].attrib["context"],
"{%s}" % ", ".join(expected_items),
)

def test_update_attrs_new_key(self):
"""Test that we can add new keys to an existing dict"""
source = etree.fromstring(
"""
<form>
<field
name="ref"
attrs="{'invisible': [('state', '=', 'draft')]}"
/>
</form>
"""
)
specs = etree.fromstring(
"""
<field name="ref" position="attributes">
<attribute name="attrs" operation="update">
{
"required": [("state", "!=", "draft")],
}
</attribute>
</field>
"""
)
res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs)
self.assertEqual(
res.xpath('//field[@name="ref"]')[0].attrib["attrs"],
"{'invisible': [('state', '=', 'draft')], "
"'required': [('state', '!=', 'draft')]}",
)

def test_update_attrs_replace(self):
"""Test that we can replace an existing dict key"""
source = etree.fromstring(
"""
<form>
<field
name="ref"
attrs="{
'invisible': [('state', '=', 'draft')],
'required': [('state', '=', False)],
}"
/>
</form>
"""
)
specs = etree.fromstring(
"""
<field name="ref" position="attributes">
<attribute name="attrs" operation="update">
{
"required": [('state', '!=', 'draft')],
}
</attribute>
</field>
"""
)
res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs)
self.assertEqual(
res.xpath('//field[@name="ref"]')[0].attrib["attrs"],
"{'invisible': [('state', '=', 'draft')], "
"'required': [('state', '!=', 'draft')]}",
"{%s}" % ", ".join(expected_items), # noqa: UP031
)

def test_update_empty_source_dict(self):
Expand All @@ -182,18 +119,18 @@ def test_update_empty_source_dict(self):
specs = etree.fromstring(
"""
<field name="ref" position="attributes">
<attribute name="attrs" operation="update">
<attribute name="context" operation="update">
{
"required": [('state', '!=', 'draft')],
"default_company": 1,
}
</attribute>
</field>
"""
)
res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs)
self.assertEqual(
res.xpath('//field[@name="ref"]')[0].attrib["attrs"],
"{'required': [('state', '!=', 'draft')]}",
res.xpath('//field[@name="ref"]')[0].attrib["context"],
"{'default_company': 1}",
)

def test_update_operation_not_a_dict(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated from manifests external_dependencies
astor
dataclasses
mako
odoorpc
openupgradelib
astor

0 comments on commit 7fc2f5d

Please sign in to comment.