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

Co-authored-by: Lukas Tran <[email protected]>
  • Loading branch information
fredericgrall and Lukas Tran committed Nov 22, 2024
1 parent 1e869fc commit c9e0dec
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 109 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
33 changes: 14 additions & 19 deletions base_view_inheritance_extension/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ast
import re

import astor
from lxml import etree

from odoo import api, models
Expand All @@ -29,7 +28,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 32 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#L32

Added line #L32 was not covered by tests
elif isinstance(k1, ast.Str):
return k1.s == k2.s
Expand Down Expand Up @@ -83,21 +82,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 86 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#L86

Added line #L86 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 All @@ -124,15 +123,11 @@ def inheritance_handler_attributes_update(self, source, specs):
# Update node ast dict
source_ast = ast_dict_update(source_ast, update_ast)
# Dump the ast back to source
# TODO: once odoo requires python >= 3.9; use `ast.unparse` instead
node.attrib[attr_name] = astor.to_source(
source_ast,
pretty_source=lambda s: "".join(s).strip(),
)
node.attrib[attr_name] = ast.unparse(source_ast).strip()
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 @@ -149,7 +144,7 @@ def inheritance_handler_attributes_text_add(self, source, specs):
return source

@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 @@ -165,16 +160,16 @@ def inheritance_handler_attributes_domain_add(self, source, specs):
old_value = node.get(attribute_name) or ""
if old_value:
old_domain = ast.literal_eval(
self.var2str_domain_text(old_value.strip())
self._var2str_domain_text(old_value.strip())
)
new_domain = ast.literal_eval(
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 169 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#L169

Added line #L169 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)
old_value = "".join(old_value.splitlines())
else:
# We must ensure that the domain definition has not line breaks because
Expand All @@ -186,7 +181,7 @@ def inheritance_handler_attributes_domain_add(self, source, specs):
return source

@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 +192,7 @@ def var2str_domain_text(self, domain_str):
return re.sub(regex, r"'\1_is_a_var_to_replace'", domain_str)

@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
Loading

0 comments on commit c9e0dec

Please sign in to comment.