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 QuocDuong1306 committed Aug 6, 2024
1 parent a14f9a6 commit 74f81c0
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 68 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
17 changes: 2 additions & 15 deletions web_m2x_options_manager/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class IrModel(models.Model):
Expand Down Expand Up @@ -36,17 +36,4 @@ def _fill_m2x_create_edit_option(self):

class IrModelFields(models.Model):
_inherit = "ir.model.fields"

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
res = super().name_search(name, args, operator, limit)
if not (name and self.env.context.get("search_by_technical_name")):
return res
domain = list(args or []) + [("name", operator, name)]
new_fids = self.search(domain, limit=limit).ids
for fid in [x[0] for x in res]:
if fid not in new_fids:
new_fids.append(fid)
if limit and limit > 0:
new_fids = new_fids[:limit]
return self.browse(new_fids).sudo().name_get()
_rec_names_search = ["name", "field_description"]
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
17 changes: 8 additions & 9 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 @@ -125,11 +124,9 @@ 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,
"'%(field_name)s' is not a valid field for model '%(model_name)s'!"
)
raise ValidationError(msg)
raise ValidationError(msg.format(opt.field_name, opt.model_name))

@api.constrains("field_id")
def _check_field_type(self):
Expand All @@ -144,17 +141,19 @@ 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 148 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#L148

Added line #L148 was not covered by tests
mode, val = opt.split("_")
if mode == "force" or k not in options:
if k not in options:
options[k] = val == "true"
node.set("options", str(options))
if mode == "force":
options["no_%s" % k] = val == "false"
if not self.option_create_edit_wizard:
node.set("can_create", "false")
node.set("can_write", "false")
options["no_quick_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
33 changes: 10 additions & 23 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,37 +97,24 @@ 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": False,
"no_create": False,
"create_edit": True,
"no_quick_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]
self.assertEqual(
safe_eval(title_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": False},
{"create": True, "create_edit": False, "no_create_edit": True},
)
2 changes: 1 addition & 1 deletion web_m2x_options_manager/views/ir_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<field name="model_name" invisible="1" />
<field
name="field_id"
context="{'search_by_technical_name': True, 'display_technical_name': True}"
context="{'display_technical_name': True}"
domain="[('ttype', 'in', ('many2many', 'many2one')), ('model_id.model', '=', model_name)]"
options="{'create': False, 'create_edit': False}"
/>
Expand Down

0 comments on commit 74f81c0

Please sign in to comment.