diff --git a/base_partition/README.rst b/base_partition/README.rst index 118427dea..d66f63daa 100644 --- a/base_partition/README.rst +++ b/base_partition/README.rst @@ -10,18 +10,18 @@ Base Partition .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 +.. |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 - :target: https://github.com/OCA/server-tools/tree/12.0/base_partition + :target: https://github.com/OCA/server-tools/tree/16.0/base_partition :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_partition + :target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_partition :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/149/12.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/server-tools&target_branch=16.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -35,9 +35,6 @@ and with values that are recordsets So if we have a recordset (x | y | z ) such that x.f == True, y.f == z.f == False, then (x | y | z ).partition("f") == {True: x, False: (y | z)}. -It also provides a backport of `filtered_domain`, -which filters a recordset in place with a provided domain. - **Table of contents** .. contents:: @@ -49,7 +46,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/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/server-tools/issues/new?body=module:%20base_partition%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. +`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_partition%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. @@ -59,12 +56,13 @@ Credits Authors ~~~~~~~ -* Acsone +* Acsone SA/NV Contributors ~~~~~~~~~~~~ * Nans Lefebvre <nans.lefebvre@acsone.eu> +* Hughes Damry <hughes.damry@acsone.eu> Maintainers ~~~~~~~~~~~ @@ -79,6 +77,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/server-tools <https://github.com/OCA/server-tools/tree/12.0/base_partition>`_ project on GitHub. +This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/base_partition>`_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_partition/__manifest__.py b/base_partition/__manifest__.py index a68fdf91b..9fa23c695 100644 --- a/base_partition/__manifest__.py +++ b/base_partition/__manifest__.py @@ -1,15 +1,15 @@ # Copyright 2020 Acsone (http://www.acsone.eu) # Nans Lefebvre <nans.lefebvre@acsone.eu> -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). { "name": "Base Partition", "summary": "Base module that provide the partition method on all models", - "version": "12.0.1.0.0", + "version": "16.0.1.0.0", "category": "Uncategorized", "website": "https://github.com/OCA/server-tools", - "author": "Acsone, Odoo Community Association (OCA)", - "license": "AGPL-3", + "author": "Acsone SA/NV, Odoo Community Association (OCA)", + "license": "LGPL-3", "installable": True, "depends": ["base"], } diff --git a/base_partition/i18n/base_partition.pot b/base_partition/i18n/base_partition.pot index f62105226..ab5717e74 100644 --- a/base_partition/i18n/base_partition.pot +++ b/base_partition/i18n/base_partition.pot @@ -1,14 +1,14 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * base_partition +# * base_partition # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 16.0+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-09-04 13:29+0000\n" -"PO-Revision-Date: 2020-09-04 13:29+0000\n" -"Last-Translator: <>\n" +"POT-Creation-Date: 2023-04-24 15:38+0000\n" +"PO-Revision-Date: 2023-04-24 15:38+0000\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -20,3 +20,11 @@ msgstr "" msgid "Base" msgstr "" +#. module: base_partition +#. odoo-python +#: code:addons/base_partition/models/models.py:0 +#, python-format +msgid "" +"Either set up a '_default_batch_size' on the model or provide a batch_size " +"parameter." +msgstr "" diff --git a/base_partition/i18n/fr_BE.pot b/base_partition/i18n/fr_BE.pot new file mode 100644 index 000000000..4befdf2a7 --- /dev/null +++ b/base_partition/i18n/fr_BE.pot @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_partition +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-04-24 15:38+0000\n" +"PO-Revision-Date: 2023-04-24 15:38+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_partition +#: model:ir.model,name:base_partition.model_base +msgid "Base" +msgstr "" + +#. module: base_partition +#. odoo-python +#: code:addons/base_partition/models/models.py:0 +#, python-format +msgid "" +"Either set up a '_default_batch_size' on the model or provide a batch_size " +"parameter." +msgstr "" +"Définir '_default_batch_size' sur le modèle ou fournir une valeur de " +"batch_size en paramètre." diff --git a/base_partition/models/models.py b/base_partition/models/models.py index 8e73f1d1c..4adf275ce 100644 --- a/base_partition/models/models.py +++ b/base_partition/models/models.py @@ -1,20 +1,8 @@ # © 2020 Acsone (http://www.acsone.eu) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -import fnmatch - -from odoo import _, fields, models +from odoo import _, models from odoo.exceptions import UserError -from odoo.osv import expression - -LIKE_COMPARATORS = ( - "like", - "ilike", - "=like", - "=ilike", - "not ilike", - "not like", -) class Base(models.AbstractModel): @@ -23,15 +11,15 @@ class Base(models.AbstractModel): def partition(self, accessor): """Returns a dictionary forming a partition of self into a dictionary - value/recordset for each value obtained from the accessor. - The accessor itself can be either a string that can be passed to mapped, - or an arbitrary function. - Note that it is always at least as fast to pass a function, - hence the current implementation. - If we have a 'field.subfield' accessor such that subfield is not a relational - then the result is a list (not hashable). Then the str(key) are used. - In the general case a value could both not be hashable nor stringifiable, - in a which case this function would crash. + value/recordset for each value obtained from the accessor. + The accessor itself can be either a string that can be passed to mapped, + or an arbitrary function. + Note that it is always at least as fast to pass a function, + hence the current implementation. + If we have a 'field.subfield' accessor such that subfield is not a relational + then the result is a list (not hashable). Then the str(key) are used. + In the general case a value could both not be hashable nor stringifiable, + in a which case this function would crash. """ partition = {} @@ -74,109 +62,3 @@ class Base(models.AbstractModel): key = d.pop("id") result[key] = d return result - - def filtered_domain(self, domain): - """Backport from standard. - """ - if not domain: - return self - result = [] - for d in reversed(domain): - if d == "|": - result.append(result.pop() | result.pop()) - elif d == "!": - result.append(self - result.pop()) - elif d == "&": - result.append(result.pop() & result.pop()) - elif d == expression.TRUE_LEAF: - result.append(self) - elif d == expression.FALSE_LEAF: - result.append(self.browse()) - else: - (key, comparator, value) = d - if key.endswith(".id"): - key = key[:-3] - if key == "id": - key = "" - # determine the field with the final type for values - field = None - if key: - model = self.browse() - for fname in key.split("."): - field = model._fields[fname] - model = model[fname] - - if comparator in LIKE_COMPARATORS: - value_esc = ( - value.replace("_", "?").replace("%", "*").replace("[", "?") - ) - records = self.browse() - for rec in self: - data = rec.mapped(key) - if comparator in ("child_of", "parent_of"): - records = data.search([(data._parent_name, comparator, value)]) - value = records.ids - comparator = "in" - if isinstance(data, models.BaseModel): - v = value - if isinstance(value, (list, tuple)) and len(value): - v = value[0] - if isinstance(v, str): - data = data.mapped("display_name") - else: - data = data.ids if data else [False] - elif field and field.type in ("date", "datetime"): - # convert all date and datetime values to datetime - normalize = fields.Datetime.to_datetime - if isinstance(value, (list, tuple)): - value = [normalize(v) for v in value] - else: - value = normalize(value) - data = [normalize(d) for d in data] - if comparator in ("in", "not in"): - if not (isinstance(value, list) or isinstance(value, tuple)): - value = [value] - - if comparator == "=": - ok = value in data - elif comparator == "in": - ok = any(map(lambda x: x in data, value)) - elif comparator == "<": - ok = any(map(lambda x: x is not None and x < value, data)) - elif comparator == ">": - ok = any(map(lambda x: x is not None and x > value, data)) - elif comparator == "<=": - ok = any(map(lambda x: x is not None and x <= value, data)) - elif comparator == ">=": - ok = any(map(lambda x: x is not None and x >= value, data)) - elif comparator in ("!=", "<>"): - ok = value not in data - elif comparator == "not in": - ok = all(map(lambda x: x not in data, value)) - elif comparator == "not ilike": - ok = all(map(lambda x: value.lower() not in x.lower(), data)) - elif comparator == "ilike": - data = [x.lower() for x in data] - match = fnmatch.filter( - data, "*" + (value_esc or "").lower() + "*" - ) - ok = bool(match) - elif comparator == "not like": - ok = all(map(lambda x: value not in x, data)) - elif comparator == "like": - ok = bool(fnmatch.filter(data, value and "*" + value_esc + "*")) - elif comparator == "=?": - ok = (value in data) or not value - elif comparator == "=like": - ok = bool(fnmatch.filter(data, value_esc)) - elif comparator == "=ilike": - data = [x.lower() for x in data] - ok = bool(fnmatch.filter(data, value and value_esc.lower())) - else: - raise ValueError - if ok: - records |= rec - result.append(records) - while len(result) > 1: - result.append(result.pop() & result.pop()) - return result[0] diff --git a/base_partition/readme/CONTRIBUTORS.rst b/base_partition/readme/CONTRIBUTORS.rst index 4e30b28db..e2702f048 100644 --- a/base_partition/readme/CONTRIBUTORS.rst +++ b/base_partition/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Nans Lefebvre <nans.lefebvre@acsone.eu> +* Hughes Damry <hughes.damry@acsone.eu> diff --git a/base_partition/readme/DESCRIPTION.rst b/base_partition/readme/DESCRIPTION.rst index 7b96e6257..bd33c61d6 100644 --- a/base_partition/readme/DESCRIPTION.rst +++ b/base_partition/readme/DESCRIPTION.rst @@ -7,6 +7,3 @@ and with values that are recordsets So if we have a recordset (x | y | z ) such that x.f == True, y.f == z.f == False, then (x | y | z ).partition("f") == {True: x, False: (y | z)}. - -It also provides a backport of `filtered_domain`, -which filters a recordset in place with a provided domain. diff --git a/base_partition/static/description/index.html b/base_partition/static/description/index.html index 9b0627c68..c65a625bf 100644 --- a/base_partition/static/description/index.html +++ b/base_partition/static/description/index.html @@ -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>Base Partition</title> <style type="text/css"> @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -<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/server-tools/tree/12.0/base_partition"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_partition"><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/149/12.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/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" href="https://github.com/OCA/server-tools/tree/16.0/base_partition"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_partition"><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/webui/builds.html?repo=OCA/server-tools&target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p>This module adds a <cite>partition(self, accessor)</cite> method to every model. It accepts for accessor any parameter that would be accepted by <cite>mapped</cite>, i.e. a string <cite>“field(.subfield)*”</cite> or a function <cite>(lambda x: not x.b)</cite>. @@ -376,8 +376,6 @@ and with values that are recordsets (these recordsets forming a partition of the initial recordset, conveniently).</p> <p>So if we have a recordset (x | y | z ) such that x.f == True, y.f == z.f == False, then (x | y | z ).partition(“f”) == {True: x, False: (y | z)}.</p> -<p>It also provides a backport of <cite>filtered_domain</cite>, -which filters a recordset in place with a provided domain.</p> <p><strong>Table of contents</strong></p> <div class="contents local topic" id="contents"> <ul class="simple"> @@ -395,7 +393,7 @@ which filters a recordset in place with a provided domain.</p> <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 smashing it by providing a detailed and welcomed -<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_partition%0Aversion:%2012.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/server-tools/issues/new?body=module:%20base_partition%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"> @@ -403,13 +401,14 @@ If you spotted it first, help us smashing it by providing a detailed and welcome <div class="section" id="authors"> <h2><a class="toc-backref" href="#id3">Authors</a></h2> <ul class="simple"> -<li>Acsone</li> +<li>Acsone SA/NV</li> </ul> </div> <div class="section" id="contributors"> <h2><a class="toc-backref" href="#id4">Contributors</a></h2> <ul class="simple"> <li>Nans Lefebvre <<a class="reference external" href="mailto:nans.lefebvre@acsone.eu">nans.lefebvre@acsone.eu</a>></li> +<li>Hughes Damry <<a class="reference external" href="mailto:hughes.damry@acsone.eu">hughes.damry@acsone.eu</a>></li> </ul> </div> <div class="section" id="maintainers"> @@ -419,7 +418,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 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/server-tools/tree/12.0/base_partition">OCA/server-tools</a> project on GitHub.</p> +<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/base_partition">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> diff --git a/base_partition/tests/test_partition.py b/base_partition/tests/test_partition.py index 1fcb720c8..568c4ff6e 100644 --- a/base_partition/tests/test_partition.py +++ b/base_partition/tests/test_partition.py @@ -1,58 +1,58 @@ # Copyright 2017 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). import functools import math -from datetime import datetime -from odoo import fields from odoo.exceptions import UserError +from odoo.fields import Command from odoo.tests.common import TransactionCase class TestPartition(TransactionCase): - def setUp(self): - super(TestPartition, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() - self.Category = self.env["res.partner.category"] - self.c1 = self.Category.create({"name": "c1"}) - self.c2 = self.Category.create({"name": "c2"}) - self.c3 = self.Category.create({"name": "c3"}) + cls.Category = cls.env["res.partner.category"] + cls.c1 = cls.Category.create({"name": "c1"}) + cls.c2 = cls.Category.create({"name": "c2"}) + cls.c3 = cls.Category.create({"name": "c3"}) - self.Partner = self.env["res.partner"] - self.parent1 = self.Partner.create({"name": "parent1"}) - self.parent2 = self.Partner.create({"name": "parent2"}) - self.child1 = self.Partner.create({"name": "child1"}) - self.child2 = self.Partner.create({"name": "child2"}) - self.child3 = self.Partner.create({"name": "child3"}) - self.x = self.Partner.create( + cls.Partner = cls.env["res.partner"] + cls.parent1 = cls.Partner.create({"name": "parent1"}) + cls.parent2 = cls.Partner.create({"name": "parent2"}) + cls.child1 = cls.Partner.create({"name": "child1"}) + cls.child2 = cls.Partner.create({"name": "child2"}) + cls.child3 = cls.Partner.create({"name": "child3"}) + cls.x = cls.Partner.create( { "name": "x", - "customer": True, - "category_id": [(6, 0, [self.c1.id, self.c2.id])], - "child_ids": [(6, 0, [self.child1.id, self.child2.id])], - "parent_id": self.parent1.id, + "employee": True, + "category_id": [Command.set([cls.c1.id, cls.c2.id])], + "child_ids": [Command.set([cls.child1.id, cls.child2.id])], + "parent_id": cls.parent1.id, } ) - self.y = self.Partner.create( + cls.y = cls.Partner.create( { "name": "y", - "customer": False, - "category_id": [(6, 0, [self.c2.id, self.c3.id])], - "child_ids": [(6, 0, [self.child2.id, self.child3.id])], - "parent_id": self.parent2.id, + "employee": False, + "category_id": [Command.set([cls.c2.id, cls.c3.id])], + "child_ids": [Command.set([cls.child2.id, cls.child3.id])], + "parent_id": cls.parent2.id, } ) - self.z = self.Partner.create( + cls.z = cls.Partner.create( { "name": "z", - "customer": False, - "category_id": [(6, 0, [self.c1.id, self.c3.id])], - "child_ids": [(6, 0, [self.child1.id, self.child3.id])], - "parent_id": self.parent2.id, + "employee": False, + "category_id": [Command.set([cls.c1.id, cls.c3.id])], + "child_ids": [Command.set([cls.child1.id, cls.child3.id])], + "parent_id": cls.parent2.id, } ) - self.xyz = self.x + self.y + self.z + cls.xyz = cls.x + cls.y + cls.z def test_partition_many2many(self): self.partition_field_test("category_id") @@ -64,7 +64,7 @@ class TestPartition(TransactionCase): self.partition_field_test("child_ids") def test_partition_boolean(self): - self.partition_field_test("customer", relational=False) + self.partition_field_test("employee", relational=False) def test_partition_dotdot_relational(self): self.partition_field_test("parent_id.category_id", relational=True, dotdot=True) @@ -74,8 +74,8 @@ class TestPartition(TransactionCase): def partition_field_test(self, field_name, relational=True, dotdot=False): """To check that we have a partition we need to check that: - - all field values are keys - - the set of all keys is the same + - all field values are keys + - the set of all keys is the same """ partition = self.xyz.partition(field_name) @@ -97,8 +97,8 @@ class TestPartition(TransactionCase): def test_batch(self): """The sum of all batches should be the original recordset; - an empty recordset should return no batch; - without a batch parameter, the model's _default_batch_size should be used. + an empty recordset should return no batch; + without a batch parameter, the model's _default_batch_size should be used. """ records = self.xyz batch_size = 2 @@ -132,74 +132,3 @@ class TestPartition(TransactionCase): self.assertTrue(record.id in data) record_data = data[record.id] self.assertEqual(list(record_data.keys()), field_list) - - def test_filtered_domain(self): - """Initially to satisfy the coverage tools, this test actually documents - a number of pitfalls of filtered_domain and the differences with a search. - Commented examples would cause warnings, and even though these are edge-cases - these behaviours should be known. - """ - - records = self.xyz - empty_recordset = records.browse() - - def filtered_search(domain): - search = self.xyz.search(domain) - return search.filtered(lambda r: r.id in self.xyz.ids) - - self.assertEqual(records, records.filtered_domain([])) - self.assertEqual(empty_recordset, records.filtered_domain([(0, "=", 1)])) - - for field in ["name"]: - for r in self.xyz: - domain = [(field, "=", r[field])] - self.assertEqual(self.xyz.filtered_domain(domain), r) - self.assertEqual(filtered_search(domain), r) - - domain = [(field, "in", r[field])] - self.assertTrue(self.xyz.filtered_domain(domain), r) - with self.assertRaises(ValueError): - filtered_search(domain) - - for field in ["customer"]: - for r in [self.x, self.y | self.z]: - value = r[0][field] - domain = [(field, "=", value)] - self.assertEqual(self.xyz.filtered_domain(domain), r) - self.assertEqual(filtered_search(domain), r) - # domain = [(field, "in", value)] - # self.assertEqual(self.xyz.filtered_domain(domain), r) - # expected_result = r if value else empty_recordset # ! - # self.assertEqual(filtered_search(domain), expected_result) - - for field in ["parent_id"]: - for r in [self.x, self.y | self.z]: - domain = [(field, "=", r[0][field].id)] - self.assertEqual(self.xyz.filtered_domain(domain), r) - self.assertEqual(filtered_search(domain), r) - domain = [(field, "in", r[0][field].ids)] - self.assertEqual(self.xyz.filtered_domain(domain), r) - self.assertEqual(filtered_search(domain), r) - - for r in self.xyz: - field = "category_id" - in_domain = [(field, "in", r[field].ids)] - self.assertEqual(self.xyz.filtered_domain(in_domain), self.xyz) - self.assertEqual(self.xyz.search(in_domain), self.xyz) - # eq_domain = [(field, "=", r[field].ids)] - # self.assertEqual(self.xyz.search(eq_domain), self.xyz) - # self.assertEqual(self.xyz.filtered_domain(eq_domain), empty_recordset) - - # coverage - records.filtered_domain(["!", (1, "=", 1)]) - for operator in ["<", ">", "<=", ">="]: - date_now_str = fields.Datetime.to_string(datetime.now()) - records.filtered_domain([("create_date", operator, date_now_str)]) - for operator in ["!=", "like", "not like", "=?", "ilike", "=like", "not ilike"]: - records.filtered_domain([("name", operator, "c")]) - records.filtered_domain( - ["&", ("parent_id.id", "in", [self.parent1.id]), (1, "=", 1)] - ) - records.filtered_domain(["|", ("parent_id", "child_of", [42]), (0, "=", 1)]) - with self.assertRaises(ValueError): - records.filtered_domain([("name", "===", "test")]) diff --git a/setup/base_partition/odoo/addons/base_partition b/setup/base_partition/odoo/addons/base_partition new file mode 120000 index 000000000..78b8f5a2e --- /dev/null +++ b/setup/base_partition/odoo/addons/base_partition @@ -0,0 +1 @@ +../../../../base_partition \ No newline at end of file diff --git a/setup/base_partition/setup.py b/setup/base_partition/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_partition/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)