Skip to content
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
67 changes: 52 additions & 15 deletions base_view_inheritance_extension/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========================
Extended view inheritance
=========================
Expand All @@ -17,7 +13,7 @@ Extended view inheritance
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
: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
Expand Down Expand Up @@ -76,10 +72,43 @@ conditional changes**
$domain_to_add
</attribute>

**Wrap loose text in an element for further processing**

.. code:: xml

<wraptext expr="//some/node" position="text" element="span" />
<wraptext expr="//some/node/other_node" position="tail" element="div" />

which transforms

.. code:: xml

<some>
<node>
plain text 1
<other_node />
plain text2
</node>
</some>

to

.. code:: xml

<some>
<node>
<span>plain text 1</span>
<other_node />
<div>plain text2</div>
</node>
</some>

making those texts accessible for further operations

Known issues / Roadmap
======================

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

Bug Tracker
===========
Expand All @@ -102,19 +131,19 @@ Authors
Contributors
------------

- Holger Brunn <hbrunn@therp.nl>
- Ronald Portier <rportier@therp.nl>
- `Tecnativa <https://www.tecnativa.com>`__:
- Holger Brunn <mail@hunki-enterprises.com>
- Ronald Portier <rportier@therp.nl>
- `Tecnativa <https://www.tecnativa.com>`__:

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

- `Trobz <https://www.trobz.com>`__:
- `Trobz <https://www.trobz.com>`__:

- Nhan Tran <nhant@trobz.com>
- Nhan Tran <nhant@trobz.com>

- Iván Todorovich <ivan.todorovich@camptocamp.com>
- Frederic Grall <fgr@apik.cloud>
- Iván Todorovich <ivan.todorovich@camptocamp.com>
- Frederic Grall <fgr@apik.cloud>

Maintainers
-----------
Expand All @@ -129,6 +158,14 @@ 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.

.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-hbrunn|

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.
1 change: 1 addition & 0 deletions base_view_inheritance_extension/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
"website": "https://github.com/OCA/server-tools",
"depends": ["base"],
"demo": ["demo/ir_ui_view.xml"],
"maintainers": ["hbrunn"],
}
80 changes: 80 additions & 0 deletions base_view_inheritance_extension/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lxml import etree

from odoo import api, models
from odoo.exceptions import ValidationError
from odoo.osv import expression


Expand Down Expand Up @@ -83,6 +84,85 @@ def _get_inheritance_handler(self, node):
handler = getattr(self, f"inheritance_handler_{node.tag}")
return handler

@api.model
def inheritance_handler_wraptext(self, source, specs):
"""Implement wraptext inheritance spec

.. code-block:: xml

<wraptext expr="//some/node" position="text" element="span" />

Which transforms xml like

.. code-block:: xml

<some>
<node>
plain text
<other_node />
</node>
</some>

to

.. code-block:: xml

<some>
<node>
<span>plain text</span>
<other_node />
</node>
</some>

"""
if len(specs):
raise ValidationError(self.env._("wraptext elements cannot have children"))

expression = specs.attrib.get("expr")
found = source.xpath(specs.attrib["expr"])
if not found:
raise ValidationError(
self.env._("wraptext: nothing found for expression %r", expression)
)

found = found[0]
text_position = specs.attrib.get("position", "text")
if text_position not in ("text", "tail"):
raise ValidationError(
self.env._("wraptext: the only valid positions are 'text' or 'tail'")
)

wrapped = etree.Element(specs.attrib.get("element", "t"))
wrapped.text = getattr(found, text_position)
setattr(found, text_position, None)

if self.env.context.get("edit_translations") and not wrapped.text:
# translation might have wrapped the text already in a <span> element
# we wrap this element so that subsequent view manipulations find
# the wrapped element at the same position in the tree it would be at
# without translation
next_sibling = found.getnext()

if (
text_position == "text"
and len(found)
and found[0].attrib.get("data-oe-translation-state")
):
wrapped.append(found[0])
elif (
text_position == "tail"
and next_sibling is not None
and next_sibling.attrib.get("data-oe-translation-state")
):
wrapped.append(next_sibling)

if text_position == "text":
found.insert(0, wrapped)
elif text_position == "tail":
found.addnext(wrapped)

return source

@api.model
def _get_inheritance_handler_attributes(self, node):
handler = super().apply_inheritance_specs
Expand Down
2 changes: 1 addition & 1 deletion base_view_inheritance_extension/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Holger Brunn \<<hbrunn@therp.nl>\>
- Holger Brunn \<<mail@hunki-enterprises.com>\>
- Ronald Portier \<<rportier@therp.nl>\>
- [Tecnativa](https://www.tecnativa.com):
- Sergio Teruel
Expand Down
33 changes: 33 additions & 0 deletions base_view_inheritance_extension/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,36 @@ conditional changes**
$domain_to_add
</attribute>
```

**Wrap loose text in an element for further processing**

``` xml
<wraptext expr="//some/node" position="text" element="span" />
<wraptext expr="//some/node/other_node" position="tail" element="div" />
```

which transforms

``` xml
<some>
<node>
plain text 1
<other_node />
plain text2
</node>
</some>
```

to

``` xml
<some>
<node>
<span>plain text 1</span>
<other_node />
<div>plain text2</div>
</node>
</some>
```

making those texts accessible for further operations
58 changes: 40 additions & 18 deletions base_view_inheritance_extension/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Extended view inheritance</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="extended-view-inheritance">
<h1 class="title">Extended view inheritance</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="extended-view-inheritance">
<h1>Extended view inheritance</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cb2fb0b7f832559d24b4af1f66ac9d92258ed4cb2a2f32b5b1afaa3437f7b9eb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/license-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><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 All @@ -392,7 +387,7 @@ <h1>Extended view inheritance</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p><strong>Change a python dictionary (context for example)</strong></p>
<pre class="code xml literal-block">
<span class="nt">&lt;field</span><span class="w"> </span><span class="na">position=</span><span class="s">&quot;attributes&quot;</span><span class="nt">&gt;</span><span class="w">
Expand All @@ -419,33 +414,59 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
</span>$domain_to_add<span class="w">
</span><span class="nt">&lt;/attribute&gt;</span>
</pre>
<p><strong>Wrap loose text in an element for further processing</strong></p>
<pre class="code xml literal-block">
<span class="nt">&lt;wraptext</span><span class="w"> </span><span class="na">expr=</span><span class="s">&quot;//some/node&quot;</span><span class="w"> </span><span class="na">position=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">element=</span><span class="s">&quot;span&quot;</span><span class="w"> </span><span class="nt">/&gt;</span><span class="w">
</span><span class="nt">&lt;wraptext</span><span class="w"> </span><span class="na">expr=</span><span class="s">&quot;//some/node/other_node&quot;</span><span class="w"> </span><span class="na">position=</span><span class="s">&quot;tail&quot;</span><span class="w"> </span><span class="na">element=</span><span class="s">&quot;div&quot;</span><span class="w"> </span><span class="nt">/&gt;</span>
</pre>
<p>which transforms</p>
<pre class="code xml literal-block">
<span class="nt">&lt;some&gt;</span><span class="w">
</span><span class="nt">&lt;node&gt;</span><span class="w">
</span>plain<span class="w"> </span>text<span class="w"> </span>1<span class="w">
</span><span class="nt">&lt;other_node</span><span class="w"> </span><span class="nt">/&gt;</span><span class="w">
</span>plain<span class="w"> </span>text2<span class="w">
</span><span class="nt">&lt;/node&gt;</span><span class="w">
</span><span class="nt">&lt;/some&gt;</span>
</pre>
<p>to</p>
<pre class="code xml literal-block">
<span class="nt">&lt;some&gt;</span><span class="w">
</span><span class="nt">&lt;node&gt;</span><span class="w">
</span><span class="nt">&lt;span&gt;</span>plain<span class="w"> </span>text<span class="w"> </span>1<span class="nt">&lt;/span&gt;</span><span class="w">
</span><span class="nt">&lt;other_node</span><span class="w"> </span><span class="nt">/&gt;</span><span class="w">
</span><span class="nt">&lt;div&gt;</span>plain<span class="w"> </span>text2<span class="nt">&lt;/div&gt;</span><span class="w">
</span><span class="nt">&lt;/node&gt;</span><span class="w">
</span><span class="nt">&lt;/some&gt;</span>
</pre>
<p>making those texts accessible for further operations</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Support an <tt class="docutils literal">eval</tt> attribute for our new node types.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<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:%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">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Therp BV</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Holger Brunn &lt;<a class="reference external" href="mailto:hbrunn&#64;therp.nl">hbrunn&#64;therp.nl</a>&gt;</li>
<li>Holger Brunn &lt;<a class="reference external" href="mailto:mail&#64;hunki-enterprises.com">mail&#64;hunki-enterprises.com</a>&gt;</li>
<li>Ronald Portier &lt;<a class="reference external" href="mailto:rportier&#64;therp.nl">rportier&#64;therp.nl</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Sergio Teruel</li>
Expand All @@ -461,19 +482,20 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<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>
<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>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/hbrunn"><img alt="hbrunn" src="https://github.com/hbrunn.png?size=40px" /></a></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>
</div>
</div>
</body>
</html>
Loading