[MIG] web_m2x_options_manager : Migration to 16.0.

pull/2587/head
AmmarOfficewalaSerpentCS 2023-03-13 23:12:45 +05:30 committed by Quoc Duong
parent a14f9a6c07
commit 3e18b4ebf9
12 changed files with 70 additions and 67 deletions

View File

@ -0,0 +1 @@
../../../../web_m2x_options_manager

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -2,10 +2,13 @@
Web M2X Options Manager Web M2X Options Manager
======================= =======================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2c7c70fbcb74be8ffaed3747c322112463936bb6fbb5a48c42d659a5f8ddce7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status :target: https://odoo-community.org/page/development-status
@ -14,14 +17,14 @@ Web M2X Options Manager
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github .. |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 :alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/15.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0
:alt: Try me on Runbot :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -49,8 +52,8 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. 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. 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 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:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `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. Do not contact contributors directly about support or help with technical issues.
@ -68,6 +71,7 @@ Contributors
* `Camptocamp <https://www.camptocamp.com>`__: * `Camptocamp <https://www.camptocamp.com>`__:
* Silvio Gregorini * Silvio Gregorini
* Duong (Tran Quoc) <duongtq@trobz.com>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -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 mission is to support the collaborative development of Odoo features and
promote its widespread use. 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. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -6,7 +6,7 @@
"summary": 'Adds an interface to manage the "Create" and' "summary": 'Adds an interface to manage the "Create" and'
' "Create and Edit" options for specific models and' ' "Create and Edit" options for specific models and'
" fields.", " fields.",
"version": "15.0.1.0.0", "version": "16.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)", "author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Web", "category": "Web",

View File

@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 15.0\n" "Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -16,7 +16,7 @@ msgstr ""
#. module: web_m2x_options_manager #. module: web_m2x_options_manager
#: code:addons/web_m2x_options_manager/models/m2x_create_edit_option.py:0 #: code:addons/web_m2x_options_manager/models/m2x_create_edit_option.py:0
#, python-format #, 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 "" msgstr ""
#. module: web_m2x_options_manager #. module: web_m2x_options_manager
@ -81,6 +81,9 @@ msgid ""
msgstr "" msgstr ""
#. module: web_m2x_options_manager #. 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 #: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__display_name
msgid "Display Name" msgid "Display Name"
msgstr "" msgstr ""
@ -111,6 +114,11 @@ msgstr ""
msgid "Fields" msgid "Fields"
msgstr "" 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 #. module: web_m2x_options_manager
#: model_terms:ir.ui.view,arch_db:web_m2x_options_manager.view_model_form_inherit #: model_terms:ir.ui.view,arch_db:web_m2x_options_manager.view_model_form_inherit
msgid "Fill" msgid "Fill"
@ -129,11 +137,17 @@ msgid "Force Remove"
msgstr "" msgstr ""
#. module: web_m2x_options_manager #. 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 #: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option__id
msgid "ID" msgid "ID"
msgstr "" msgstr ""
#. module: web_m2x_options_manager #. 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 #: model:ir.model.fields,field_description:web_m2x_options_manager.field_m2x_create_edit_option____last_update
msgid "Last Modified on" msgid "Last Modified on"
msgstr "" msgstr ""

View File

@ -1,7 +1,7 @@
# Copyright 2021 Camptocamp SA # Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class IrModel(models.Model):
@ -36,17 +36,4 @@ class IrModel(models.Model):
class IrModelFields(models.Model): class IrModelFields(models.Model):
_inherit = "ir.model.fields" _inherit = "ir.model.fields"
_rec_names_search = ["name", "field_description"]
@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()

View File

@ -11,8 +11,7 @@ class IrUiView(models.Model):
res = super()._postprocess_tag_field(node, name_manager, node_info) res = super()._postprocess_tag_field(node, name_manager, node_info)
if node.tag == "field": if node.tag == "field":
mname = name_manager.model._name mname = name_manager.model._name
fname = node.attrib["name"] field = name_manager.model._fields.get(node.get("name"))
field = self.env[mname]._fields.get(fname)
if field and field.type in ("many2many", "many2one"): if field and field.type in ("many2many", "many2one"):
rec = self.env["m2x.create.edit.option"].get(mname, field.name) rec = self.env["m2x.create.edit.option"].get(mname, field.name)
if rec: if rec:

View File

@ -22,7 +22,6 @@ class M2xCreateEditOption(models.Model):
field_name = fields.Char( field_name = fields.Char(
related="field_id.name", related="field_id.name",
store=True, store=True,
string="Field Name",
) )
model_id = fields.Many2one( model_id = fields.Many2one(
@ -125,9 +124,9 @@ class M2xCreateEditOption(models.Model):
for opt in self: for opt in self:
if opt.field_id.model_id != opt.model_id: if opt.field_id.model_id != opt.model_id:
msg = _( msg = _(
"%(field)s is not a valid field for model %(model)s!", "'%(field_name)s' is not a valid field for model '%(model_name)s'!",
field=opt.field_name, field_name=opt.field_name,
model=opt.model_name, model_name=opt.model_name,
) )
raise ValidationError(msg) raise ValidationError(msg)
@ -144,17 +143,19 @@ class M2xCreateEditOption(models.Model):
options = node.attrib.get("options") or {} options = node.attrib.get("options") or {}
if isinstance(options, str): if isinstance(options, str):
options = safe_eval(options, dict(self.env.context or [])) or {} options = safe_eval(options, dict(self.env.context or [])) or {}
for k in ("create", "create_edit"): for k in ("create", "create_edit"):
opt = self["option_%s" % k] opt = self["option_%s" % k]
if opt == "none": if opt == "none":
continue continue
mode, val = opt.split("_") mode, val = opt.split("_")
if mode == "force" or k not in options: if k not in options:
options[k] = val == "true" 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: if not self.option_create_edit_wizard:
node.set("can_create", "false") options["no_quick_create"] = True
node.set("can_write", "false") node.set("options", str(options))
@api.model @api.model
def get(self, model_name, field_name): def get(self, model_name, field_name):

View File

@ -1,3 +1,4 @@
* `Camptocamp <https://www.camptocamp.com>`__: * `Camptocamp <https://www.camptocamp.com>`__:
* Silvio Gregorini * Silvio Gregorini
* Duong (Tran Quoc) <duongtq@trobz.com>

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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> <title>Web M2X Options Manager</title>
<style type="text/css"> <style type="text/css">
@ -366,8 +366,10 @@ ul.auto-toc {
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! 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> <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> and <cite>Many2many</cite> fields directly from the <cite>ir.model</cite> form view.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
@ -395,8 +397,8 @@ Button “Empty” will remove every option.</p>
<h1><a class="toc-backref" href="#id2">Bug Tracker</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>. <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. 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 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:%2015.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/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> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -414,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Silvio Gregorini</li> <li>Silvio Gregorini</li>
</ul> </ul>
</li> </li>
<li>Duong (Tran Quoc) &lt;<a class="reference external" href="mailto:duongtq&#64;trobz.com">duongtq&#64;trobz.com</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -423,7 +426,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> 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> <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>

View File

@ -75,7 +75,7 @@ class TestM2xCreateEditOption(TransactionCase):
) )
def test_apply_options(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 # Check fields on res.partner form view
form_arch = res["arch"] form_arch = res["arch"]
@ -97,37 +97,24 @@ class TestM2xCreateEditOption(TransactionCase):
safe_eval(categ_node.attrib.get("options"), nocopy=True), safe_eval(categ_node.attrib.get("options"), nocopy=True),
{"create": False, "create_edit": 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) # Check fields on res.users tree view (contained in ``user_ids`` field)
tree_arch = res["fields"]["user_ids"]["views"]["tree"]["arch"] company_node = form_doc.xpath("//field[@name='company_id']")[0]
tree_doc = etree.XML(tree_arch)
company_node = tree_doc.xpath("//field[@name='company_id']")[0]
self.assertEqual( self.assertEqual(
safe_eval(company_node.attrib.get("options"), nocopy=True), safe_eval(company_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": True}, {
"create": False,
"no_create": False,
"create_edit": True,
"no_quick_create": True,
},
) )
self.assertEqual(
(
company_node.attrib.get("can_create"),
company_node.attrib.get("can_write"),
),
("false", "false"),
)
# Update options, check that node has been updated too # Update options, check that node has been updated too
self.title_opt.option_create_edit = "force_false" 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_arch = res["arch"]
form_doc = etree.XML(form_arch) form_doc = etree.XML(form_arch)
title_node = form_doc.xpath("//field[@name='title']")[0] title_node = form_doc.xpath("//field[@name='title']")[0]
self.assertEqual( self.assertEqual(
safe_eval(title_node.attrib.get("options"), nocopy=True), safe_eval(title_node.attrib.get("options"), nocopy=True),
{"create": True, "create_edit": False}, {"create": True, "create_edit": False, "no_create_edit": True},
) )

View File

@ -21,7 +21,7 @@
<field name="model_name" invisible="1" /> <field name="model_name" invisible="1" />
<field <field
name="field_id" 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)]" domain="[('ttype', 'in', ('many2many', 'many2one')), ('model_id.model', '=', model_name)]"
options="{'create': False, 'create_edit': False}" options="{'create': False, 'create_edit': False}"
/> />