Browse Source

[8.0][ADD] Add list manipulation operations to base_view_inheritance_extension. (#804)

* Add list_add operation.
* Add list_remove operation.

OCA Transbot updated translations from Transifex
pull/1407/head
Ronald Portier 8 years ago
committed by Pedro M. Baeza
parent
commit
e748842dda
  1. 42
      base_view_inheritance_extension/README.rst
  2. 2
      base_view_inheritance_extension/__openerp__.py
  3. 34
      base_view_inheritance_extension/i18n/ca.po
  4. 7
      base_view_inheritance_extension/i18n/de.po
  5. 34
      base_view_inheritance_extension/i18n/it.po
  6. 37
      base_view_inheritance_extension/models/ir_ui_view.py
  7. 83
      base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py

42
base_view_inheritance_extension/README.rst

@ -6,7 +6,8 @@
Extended view inheritance Extended view inheritance
========================= =========================
This module was written to make it simple to add custom operators for view inheritance.
This module was written to make it simple to add custom operators for view
inheritance.
Usage Usage
===== =====
@ -24,7 +25,8 @@ Change a python dictionary (context for example)
$new_value $new_value
</attribute> </attribute>
Note that views are subject to evaluation of xmlids anyways, so if you need to refer to some xmlid, say ``%(xmlid)s``.
Note that views are subject to evaluation of xmlids anyways, so if you need
to refer to some xmlid, say ``%(xmlid)s``.
Move an element in the view Move an element in the view
--------------------------- ---------------------------
@ -33,13 +35,30 @@ Move an element in the view
<xpath expr="$xpath" position="move" target="$targetxpath" /> <xpath expr="$xpath" position="move" target="$targetxpath" />
This can also be used to wrap some element into another, create the target element first, then move the node youwant to wrap there.
This can also be used to wrap some element into another, create the target
element first, then move the node youwant to wrap there.
Add to values in a list (states for example)
--------------------------------------------
.. code-block:: xml
<attribute name="$attribute" operation="list_add">
$new_value(s)
</attribute>
Remove values from a list (states for example)
----------------------------------------------
.. code-block:: xml
<attribute name="$attribute" operation="list_remove">
$remove_value(s)
</attribute>
Known issues / Roadmap Known issues / Roadmap
====================== ======================
* add ``<attribute operation="python_list_add">$value</attribute>``
* add ``<attribute operation="python_list_remove">$index</attribute>``
* add ``<attribute operation="json_dict" key="$key">$value</attribute>`` * add ``<attribute operation="json_dict" key="$key">$value</attribute>``
* support ``<xpath expr="$xpath" position="move" target="xpath" target_position="position" />`` * support ``<xpath expr="$xpath" position="move" target="xpath" target_position="position" />``
* support an ``eval`` attribute for our new node types * support an ``eval`` attribute for our new node types
@ -58,14 +77,21 @@ Credits
Images Images
------ ------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Odoo Community Association:
`Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors Contributors
------------ ------------
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
* Ronald Portier <rportier@therp.nl>
Do not contact contributors directly about help with questions or problems
concerning this addon, but use the
`community mailing list <mailto:community@mail.odoo.com>`_ or the
`appropriate specialized mailinglist <https://odoo-community.org/groups>`_
for help, and the bug tracker linked in `Bug Tracker`_ above for
technical issues.
Maintainer Maintainer
---------- ----------

2
base_view_inheritance_extension/__openerp__.py

@ -3,7 +3,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{ {
"name": "Extended view inheritance", "name": "Extended view inheritance",
"version": "9.0.1.0.0",
"version": "9.0.1.1.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"license": "LGPL-3", "license": "LGPL-3",
"category": "Hidden/Dependency", "category": "Hidden/Dependency",

34
base_view_inheritance_extension/i18n/ca.po

@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_view_inheritance_extension
#
# Translators:
# Marc Tormo i Bochaca <mtbochaca@gmail.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-19 17:59+0000\n"
"PO-Revision-Date: 2017-04-19 17:59+0000\n"
"Last-Translator: Marc Tormo i Bochaca <mtbochaca@gmail.com>, 2017\n"
"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: ca\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: base_view_inheritance_extension
#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_form
msgid "A new page"
msgstr "Una nova pàgina "
#. module: base_view_inheritance_extension
#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_form
msgid "Partner form"
msgstr "Empresa de "
#. module: base_view_inheritance_extension
#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view
msgid "ir.ui.view"
msgstr "ir.ui.view"

7
base_view_inheritance_extension/i18n/de.po

@ -3,13 +3,14 @@
# * base_view_inheritance_extension # * base_view_inheritance_extension
# #
# Translators: # Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
# Rudolf Schnapka <rs@techno-flex.de>, 2017 # Rudolf Schnapka <rs@techno-flex.de>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n" "Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-04 07:39+0000\n"
"PO-Revision-Date: 2017-03-04 07:39+0000\n"
"POT-Creation-Date: 2017-04-19 17:59+0000\n"
"PO-Revision-Date: 2017-04-19 17:59+0000\n"
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>, 2017\n" "Last-Translator: Rudolf Schnapka <rs@techno-flex.de>, 2017\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" "Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -31,4 +32,4 @@ msgstr "Partner-Formular"
#. module: base_view_inheritance_extension #. module: base_view_inheritance_extension
#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view #: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view
msgid "ir.ui.view" msgid "ir.ui.view"
msgstr ""
msgstr "ir.ui.view"

34
base_view_inheritance_extension/i18n/it.po

@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_view_inheritance_extension
#
# Translators:
# Paolo Valier <paolo.valier@hotmail.it>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-19 17:59+0000\n"
"PO-Revision-Date: 2017-04-19 17:59+0000\n"
"Last-Translator: Paolo Valier <paolo.valier@hotmail.it>, 2017\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: it\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: base_view_inheritance_extension
#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_form
msgid "A new page"
msgstr "Una nuova pagina"
#. module: base_view_inheritance_extension
#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_form
msgid "Partner form"
msgstr ""
#. module: base_view_inheritance_extension
#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view
msgid "ir.ui.view"
msgstr ""

37
base_view_inheritance_extension/models/ir_ui_view.py

@ -122,3 +122,40 @@ class IrUiView(models.Model):
) )
target_node.append(node) target_node.append(node)
return source return source
@api.model
def inheritance_handler_attributes_list_add(
self, source, specs, inherit_id
):
"""Implement
<$node position="attributes">
<attribute name="$attribute" operation="list_add">
$new_value
</attribute>
</$node>"""
node = self.locate_node(source, specs)
for attribute_node in specs:
attribute_name = attribute_node.get('name')
old_value = node.get(attribute_name) or ''
new_value = old_value + ',' + attribute_node.text
node.attrib[attribute_name] = new_value
return source
@api.model
def inheritance_handler_attributes_list_remove(
self, source, specs, inherit_id
):
"""Implement
<$node position="attributes">
<attribute name="$attribute" operation="list_remove">
$value_to_remove
</attribute>
</$node>"""
node = self.locate_node(source, specs)
for attribute_node in specs:
attribute_name = attribute_node.get('name')
old_values = (node.get(attribute_name) or '').split(',')
remove_values = attribute_node.text.split(',')
new_values = [x for x in old_values if x not in remove_values]
node.attrib[attribute_name] = ','.join(filter(None, new_values))
return source

83
base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py

@ -6,6 +6,7 @@ from openerp.tests.common import TransactionCase
class TestBaseViewInheritanceExtension(TransactionCase): class TestBaseViewInheritanceExtension(TransactionCase):
def test_base_view_inheritance_extension(self): def test_base_view_inheritance_extension(self):
view_id = self.env.ref('base.view_partner_form').id view_id = self.env.ref('base.view_partner_form').id
fields_view_get = self.env['res.partner'].fields_view_get( fields_view_get = self.env['res.partner'].fields_view_get(
@ -28,3 +29,85 @@ class TestBaseViewInheritanceExtension(TransactionCase):
view.xpath('//field[@name="child_ids"]')[0].getparent(), view.xpath('//field[@name="child_ids"]')[0].getparent(),
view.xpath('//page[@name="my_new_page"]')[0] view.xpath('//page[@name="my_new_page"]')[0]
) )
def test_list_add(self):
view_model = self.env['ir.ui.view']
inherit_id = self.env.ref('base.view_partner_form').id
source = etree.fromstring(
"""\
<form>
<button name="test" states="draft,open"/>
</form>
"""
)
# extend with single value
specs = etree.fromstring(
"""\
<button name="test" position="attributes">
<attribute
name="states"
operation="list_add"
>valid</attribute>
</button>
"""
)
modified_source = \
view_model.inheritance_handler_attributes_list_add(
source, specs, inherit_id
)
button_node = modified_source.xpath('//button[@name="test"]')[0]
self.assertEqual(
button_node.attrib['states'],
'draft,open,valid'
)
# extend with list of values
specs = etree.fromstring(
"""\
<button name="test" position="attributes">
<attribute
name="states"
operation="list_add"
>payable,paid</attribute>
</button>
"""
)
modified_source = \
view_model.inheritance_handler_attributes_list_add(
source, specs, inherit_id
)
button_node = modified_source.xpath('//button[@name="test"]')[0]
self.assertEqual(
button_node.attrib['states'],
'draft,open,valid,payable,paid'
)
def test_list_remove(self):
view_model = self.env['ir.ui.view']
inherit_id = self.env.ref('base.view_partner_form').id
source = etree.fromstring(
"""\
<form>
<button name="test" states="draft,open,valid,payable,paid"/>
</form>
"""
)
# remove list of values
specs = etree.fromstring(
"""\
<button name="test" position="attributes">
<attribute
name="states"
operation="list_remove"
>open,payable</attribute>
</button>
"""
)
modified_source = \
view_model.inheritance_handler_attributes_list_remove(
source, specs, inherit_id
)
button_node = modified_source.xpath('//button[@name="test"]')[0]
self.assertEqual(
button_node.attrib['states'],
'draft,valid,paid'
)
Loading…
Cancel
Save