-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[19.0][MIG] base_partition: Migration to 19.0 #3465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
therbin200
wants to merge
24
commits into
OCA:19.0
Choose a base branch
from
apikcloud:19.0-mig-base_partition
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+912
−0
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8107893
[ADD] base_partition: add partition method to base model
cce4e09
[IMP] models: backport filtered_domain
a4315a4
[IMP] base_partition: add batch method on base
858643e
[IMP] base_partition: add read_per_record method
df1e578
[TEST] base_partition: add coverage
1303cda
[16.0][MIG] base_partition
glitchov 67af1d8
[UPD] Update base_partition.pot
34cdca4
[UPD] README.rst
OCA-git-bot f315906
[UPD] README.rst
OCA-git-bot bda56dc
Added translation using Weblate (Spanish)
Ivorra78 aac8aee
Translated using Weblate (Spanish)
Ivorra78 f755c7c
Added translation using Weblate (Italian)
mymage af4ccfe
Translated using Weblate (Italian)
mymage 4f1ddaa
[IMP] base_partition: pre-commit auto fixes
nguyenminhchien 6223f2e
[MIG] base_partition: Migration to 17.0
nguyenminhchien 19f7b1c
[UPD] Update base_partition.pot
3bd7ca2
[BOT] post-merge updates
OCA-git-bot c2a186c
Added translation using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha 690beac
Translated using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha c9e63f9
[MIG] base_partition: Migration to 18.0
06d38e4
[UPD] Update base_partition.pot
632b48a
[BOT] post-merge updates
OCA-git-bot bbbb26e
Update translation files
weblate 8b0c8f0
[MIG] base_partition: Migration to 19.0
therbin200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| ============== | ||
| Base Partition | ||
| ============== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:505fafa7278c9732b9e8b76a4e69e5320eaae57addb3848ced966c35cad279ff | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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/license-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/19.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-19-0/server-tools-19-0-base_partition | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This module adds a partition(self, accessor) method to every model. It | ||
| accepts for accessor any parameter that would be accepted by mapped, | ||
| i.e. a string "field(.subfield)\*" or a function (lambda x: not x.b). It | ||
| returns a dictionary with keys that are equal to | ||
| set(record.mapped(accessor)), and with values that are recordsets (these | ||
| recordsets forming a partition of the initial recordset, conveniently). | ||
|
|
||
| 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)}. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| 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 to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_partition%0Aversion:%2019.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. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Acsone SA/NV | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - Nans Lefebvre <nans.lefebvre@acsone.eu> | ||
| - Hughes Damry <hughes.damry@acsone.eu> | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| 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/19.0/base_partition>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright 2020 Acsone (http://www.acsone.eu) | ||
| # Nans Lefebvre <nans.lefebvre@acsone.eu> | ||
| # 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": "19.0.1.0.0", | ||
| "category": "Uncategorized", | ||
| "website": "https://github.com/OCA/server-tools", | ||
| "author": "Acsone SA/NV, Odoo Community Association (OCA)", | ||
| "license": "LGPL-3", | ||
| "installable": True, | ||
| "depends": ["base"], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * base_partition | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 18.0\n" | ||
| "Report-Msgid-Bugs-To: \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 | ||
| msgid "" | ||
| "Either set up a '_default_batch_size' on the model or provide a batch_size " | ||
| "parameter." | ||
| msgstr "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "PO-Revision-Date: 2023-12-07 18:34+0000\n" | ||
| "Last-Translator: Ivorra78 <informatica@totmaterial.es>\n" | ||
| "Language-Team: none\n" | ||
| "Language: es\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
| "X-Generator: Weblate 4.17\n" | ||
|
|
||
| #. module: base_partition | ||
| #: model:ir.model,name:base_partition.model_base | ||
| msgid "Base" | ||
| msgstr "Base" | ||
|
|
||
| #. module: base_partition | ||
| #. odoo-python | ||
| #: code:addons/base_partition/models/models.py:0 | ||
| msgid "" | ||
| "Either set up a '_default_batch_size' on the model or provide a batch_size " | ||
| "parameter." | ||
| msgstr "" | ||
| "Configure un '_default_batch_size' en el modelo o proporcione un parámetro " | ||
| "de tamaño de lote." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "PO-Revision-Date: 2024-01-02 16:34+0000\n" | ||
| "Last-Translator: mymage <stefano.consolaro@mymage.it>\n" | ||
| "Language-Team: none\n" | ||
| "Language: it\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
| "X-Generator: Weblate 4.17\n" | ||
|
|
||
| #. module: base_partition | ||
| #: model:ir.model,name:base_partition.model_base | ||
| msgid "Base" | ||
| msgstr "Base" | ||
|
|
||
| #. module: base_partition | ||
| #. odoo-python | ||
| #: code:addons/base_partition/models/models.py:0 | ||
| msgid "" | ||
| "Either set up a '_default_batch_size' on the model or provide a batch_size " | ||
| "parameter." | ||
| msgstr "" | ||
| "Impostare un '_default_batch_size' nel modello o frnire un parametro " | ||
| "batch_size." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * base_partition | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 17.0\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "PO-Revision-Date: 2024-06-16 17:40+0000\n" | ||
| "Last-Translator: xtanuiha <feihu.zhang@live.com>\n" | ||
| "Language-Team: none\n" | ||
| "Language: zh_CN\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: nplurals=1; plural=0;\n" | ||
| "X-Generator: Weblate 4.17\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 | ||
| msgid "" | ||
| "Either set up a '_default_batch_size' on the model or provide a batch_size " | ||
| "parameter." | ||
| msgstr "" | ||
| "要么在模型上设置一个'_default_batch_size',要么提供一个batch_size参数。" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # © 2020 Acsone (http://www.acsone.eu) | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
|
||
| from odoo import models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class Base(models.AbstractModel): | ||
| _inherit = "base" | ||
|
|
||
| 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. | ||
| """ | ||
| partition = {} | ||
|
|
||
| if isinstance(accessor, str): | ||
| if "." not in accessor: | ||
| func = lambda r: r[accessor] # noqa: E731 | ||
| else: | ||
| func = lambda r: r.mapped(accessor) # noqa: E731 | ||
| else: | ||
| func = accessor | ||
|
|
||
| for record in self: | ||
| key = func(record) | ||
| if not key.__hash__: | ||
| key = str(key) | ||
| if key not in partition: | ||
| partition[key] = record | ||
| else: | ||
| partition[key] += record | ||
|
|
||
| return partition | ||
|
|
||
| def batch(self, batch_size=None): | ||
| """Yield successive batches of size batch_size, or .""" | ||
| if not (batch_size or "_default_batch_size" in dir(self)): | ||
| raise UserError( | ||
| self.env._( | ||
| "Either set up a '_default_batch_size' on the model" | ||
| " or provide a batch_size parameter." | ||
| ) | ||
| ) | ||
| batch_size = batch_size or self._default_batch_size | ||
| for i in range(0, len(self), batch_size): | ||
| yield self[i : i + batch_size] | ||
|
|
||
| def read_per_record(self, fields=None, load="_classic_read"): | ||
| result = {} | ||
| data_list = self.read(fields=fields, load=load) | ||
| for d in data_list: | ||
| key = d.pop("id") | ||
| result[key] = d | ||
| return result | ||
|
Comment on lines
+57
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - Nans Lefebvre \<<nans.lefebvre@acsone.eu>\> | ||
| - Hughes Damry \<<hughes.damry@acsone.eu>\> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| This module adds a partition(self, accessor) method to every model. It | ||
| accepts for accessor any parameter that would be accepted by mapped, | ||
| i.e. a string "field(.subfield)\*" or a function (lambda x: not x.b). It | ||
| returns a dictionary with keys that are equal to | ||
| set(record.mapped(accessor)), and with values that are recordsets (these | ||
| recordsets forming a partition of the initial recordset, conveniently). | ||
|
|
||
| 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)}. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice include some documentation in addon's description about this method too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently I discovered split_every. Maybe this could be deprecated in favor of the built-in helper.