Skip to content

Commit

Permalink
[MIG] web_m2x_options_manager : Migration to 16.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmmarOfficewalaSerpentCS authored and duongtq committed Aug 11, 2023
1 parent febe288 commit b90854d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 52 deletions.
6 changes: 6 additions & 0 deletions setup/web_m2x_options_manager/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
24 changes: 14 additions & 10 deletions web_m2x_options_manager/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Web M2X Options Manager
=======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2c7c70fbcb74be8ffaed3747c322112463936bb6fbb5a48c42d659a5f8ddce7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ Web M2X Options Manager
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/15.0/web_m2x_options_manager
:target: https://github.com/OCA/web/tree/16.0/web_m2x_options_manager
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_m2x_options_manager
:target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_m2x_options_manager
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/15.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

Allows managing the "Create..." and "Create and Edit..." options for `Many2one`
and `Many2many` fields directly from the `ir.model` form view.
Expand All @@ -49,8 +52,8 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options_manager%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options_manager%0Aversion:%2016.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 @@ -68,6 +71,7 @@ Contributors
* `Camptocamp <https://www.camptocamp.com>`__:

* Silvio Gregorini
* Duong (Tran Quoc) <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -82,6 +86,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/web <https://github.com/OCA/web/tree/15.0/web_m2x_options_manager>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/16.0/web_m2x_options_manager>`_ 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 web_m2x_options_manager/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"summary": 'Adds an interface to manage the "Create" and'
' "Create and Edit" options for specific models and'
" fields.",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Web",
Expand Down
18 changes: 16 additions & 2 deletions web_m2x_options_manager/i18n/web_m2x_options_manager.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -16,7 +16,7 @@ msgstr ""
#. module: web_m2x_options_manager
#: code:addons/web_m2x_options_manager/models/m2x_create_edit_option.py:0
#, python-format
msgid "%(field)s is not a valid field for model %(model)s!"
msgid "'%s' is not a valid field for model '%s'!"
msgstr ""

#. module: web_m2x_options_manager
Expand Down Expand Up @@ -81,6 +81,9 @@ msgid ""
msgstr ""

#. module: web_m2x_options_manager
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model__display_name
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model_fields__display_name
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_ui_view__display_name
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__display_name
msgid "Display Name"
msgstr ""
Expand Down Expand Up @@ -111,6 +114,11 @@ msgstr ""
msgid "Fields"
msgstr ""

#. module: web_m2x_options_manager
#: model_terms:ir.ui.view,arch_db:web_m2x_options_manager.view_model_form_inherit
msgid "Fields Description"
msgstr ""

#. module: web_m2x_options_manager
#: model_terms:ir.ui.view,arch_db:web_m2x_options_manager.view_model_form_inherit
msgid "Fill"
Expand All @@ -129,11 +137,17 @@ msgid "Force Remove"
msgstr ""

#. module: web_m2x_options_manager
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model__id
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model_fields__id
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_ui_view__id
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__id
msgid "ID"
msgstr ""

#. module: web_m2x_options_manager
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model____last_update
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_model_fields____last_update
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_ir_ui_view____last_update
#: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option____last_update
msgid "Last Modified on"
msgstr ""
Expand Down
3 changes: 1 addition & 2 deletions web_m2x_options_manager/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def _postprocess_tag_field(self, node, name_manager, node_info):
res = super()._postprocess_tag_field(node, name_manager, node_info)
if node.tag == "field":
mname = name_manager.model._name
fname = node.attrib["name"]
field = self.env[mname]._fields.get(fname)
field = name_manager.model._fields.get(node.get("name"))
if field and field.type in ("many2many", "many2one"):
rec = self.env["m2x.create.edit.option"].get(mname, field.name)
if rec:
Expand Down
15 changes: 5 additions & 10 deletions web_m2x_options_manager/models/m2x_create_edit_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class M2xCreateEditOption(models.Model):
field_name = fields.Char(
related="field_id.name",
store=True,
string="Field Name",
)

model_id = fields.Many2one(
Expand Down Expand Up @@ -124,12 +123,8 @@ def _inverse_model_name(self):
def _check_field_in_model(self):
for opt in self:
if opt.field_id.model_id != opt.model_id:
msg = _(
"%(field)s is not a valid field for model %(model)s!",
field=opt.field_name,
model=opt.model_name,
)
raise ValidationError(msg)
msg = _("'{0}' is not a valid field for model '{1}'!")
raise ValidationError(msg.format(opt.field_name, opt.model_name))

@api.constrains("field_id")
def _check_field_type(self):
Expand All @@ -144,17 +139,17 @@ def _apply_options(self, node):
options = node.attrib.get("options") or {}
if isinstance(options, str):
options = safe_eval(options, dict(self.env.context or [])) or {}

for k in ("create", "create_edit"):
opt = self["option_%s" % k]
if opt == "none":
continue

Check warning on line 146 in web_m2x_options_manager/models/m2x_create_edit_option.py

View check run for this annotation

Codecov / codecov/patch

web_m2x_options_manager/models/m2x_create_edit_option.py#L146

Added line #L146 was not covered by tests
mode, val = opt.split("_")
if mode == "force" or k not in options:
options[k] = val == "true"
node.set("options", str(options))
if not self.option_create_edit_wizard:
node.set("can_create", "false")
node.set("can_write", "false")
options["no_create"] = True
node.set("options", str(options))

@api.model
def get(self, model_name, field_name):
Expand Down
1 change: 1 addition & 0 deletions web_m2x_options_manager/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* `Camptocamp <https://www.camptocamp.com>`__:

* Silvio Gregorini
* Duong (Tran Quoc) <[email protected]>
13 changes: 8 additions & 5 deletions web_m2x_options_manager/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Web M2X Options Manager</title>
<style type="text/css">

Expand Down Expand Up @@ -366,8 +366,10 @@ <h1 class="title">Web M2X Options Manager</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2c7c70fbcb74be8ffaed3747c322112463936bb6fbb5a48c42d659a5f8ddce7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_m2x_options_manager"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_m2x_options_manager"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/16.0/web_m2x_options_manager"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_m2x_options_manager"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Allows managing the “Create…” and “Create and Edit…” options for <cite>Many2one</cite>
and <cite>Many2many</cite> fields directly from the <cite>ir.model</cite> form view.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -395,8 +397,8 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/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 smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options_manager%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
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/web/issues/new?body=module:%20web_m2x_options_manager%0Aversion:%2016.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 @@ -414,6 +416,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<li>Silvio Gregorini</li>
</ul>
</li>
<li>Duong (Tran Quoc) &lt;<a class="reference external" href="mailto:duongtq&#64;trobz.com">duongtq&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -423,7 +426,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<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/web/tree/15.0/web_m2x_options_manager">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/16.0/web_m2x_options_manager">OCA/web</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
26 changes: 4 additions & 22 deletions web_m2x_options_manager/tests/test_m2x_create_edit_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_errors(self):
)

def test_apply_options(self):
res = self.env["res.partner"].fields_view_get(self.view.id)
res = self.env["res.partner"].get_view(self.view.id)

# Check fields on res.partner form view
form_arch = res["arch"]
Expand All @@ -97,33 +97,15 @@ def test_apply_options(self):
safe_eval(categ_node.attrib.get("options"), nocopy=True),
{"create": False, "create_edit": True},
)
self.assertEqual(
(
categ_node.attrib.get("can_create"),
categ_node.attrib.get("can_write"),
),
("true", "true"),
)

# Check fields on res.users tree view (contained in ``user_ids`` field)
tree_arch = res["fields"]["user_ids"]["views"]["tree"]["arch"]
tree_doc = etree.XML(tree_arch)
company_node = tree_doc.xpath("//field[@name='company_id']")[0]
company_node = form_doc.xpath("//field[@name='company_id']")[0]
self.assertEqual(
safe_eval(company_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": True},
)
self.assertEqual(
(
company_node.attrib.get("can_create"),
company_node.attrib.get("can_write"),
),
("false", "false"),
{"create": True, "create_edit": True, "no_create": True},
)

# Update options, check that node has been updated too
self.title_opt.option_create_edit = "force_false"
res = self.env["res.partner"].fields_view_get(self.view.id)
res = self.env["res.partner"].get_view(self.view.id)
form_arch = res["arch"]
form_doc = etree.XML(form_arch)
title_node = form_doc.xpath("//field[@name='title']")[0]
Expand Down

0 comments on commit b90854d

Please sign in to comment.