[IMP] onchange_helper: pre-commit auto fixes

pull/2806/head
John Herholz 2024-01-11 12:02:20 +01:00
parent 0c16e16420
commit 12807b9902
10 changed files with 153 additions and 105 deletions

View File

@ -17,18 +17,19 @@ Onchange Helper
: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%2Fserver--tools-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/16.0/onchange_helper :target: https://github.com/OCA/server-tools/tree/17.0/onchange_helper
:alt: OCA/server-tools :alt: OCA/server-tools
.. |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/server-tools-16-0/server-tools-16-0-onchange_helper :target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-onchange_helper
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |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=16.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
This is a technical module. Its goal is to ease the play of onchange method directly called from Python code. This is a technical module. Its goal is to ease the play of onchange
method directly called from Python code.
**Table of contents** **Table of contents**
@ -40,49 +41,62 @@ Usage
To use this module, you need to: To use this module, you need to:
* depend on this module - depend on this module
* call `yourmodel.play_onchanges(values, ['field'])` - call yourmodel.play_onchanges(values, ['field'])
Example if you want to create a sale order and you want to get the values relative to partner_id field (as if you fill the field from UI) Example if you want to create a sale order and you want to get the
values relative to partner_id field (as if you fill the field from UI)
`vals = {'partner_id': 1}` vals = {'partner_id': 1}
`vals = self.env['sale.order'].play_onchanges(vals, ['partner_id'])` vals = self.env['sale.order'].play_onchanges(vals, ['partner_id'])
Then, `vals` will be updated with partner_invoice_id, partner_shipping_id, pricelist_id, etc... Then, vals will be updated with partner_invoice_id, partner_shipping_id,
pricelist_id, etc...
Default values will be used to process onchange methods, if respective fields are not set in `vals`. Default values will be used to process onchange methods, if respective
You can get them if you pass fields name in the list of fields. fields are not set in vals. You can get them if you pass fields name in
the list of fields.
vals = {'partner_id': 1}
`vals = {'partner_id': 1}` vals = self.env['sale.order'].play_onchanges(vals, ['partner_id',
'date_order'])
`vals = self.env['sale.order'].play_onchanges(vals, ['partner_id', 'date_order'])`
`vals` will contain, in addition to the changed values, the default value for `date_order`
vals will contain, in addition to the changed values, the default value
for date_order
You can also use it on existing record for example: You can also use it on existing record for example:
`vals = {'partner_shipping_id': 1}` vals = {'partner_shipping_id': 1}
`vals = sale.play_onchanges(vals, ['partner_shipping_id'])` vals = sale.play_onchanges(vals, ['partner_shipping_id'])
Then the onchange will be played with the vals passed and the existing vals of the sale. `vals` will be updated with partner_invoice_id, pricelist_id, etc.. Then the onchange will be played with the vals passed and the existing
vals of the sale. vals will be updated with partner_invoice_id,
Behind the scene, `play_onchanges` will execute **all the methods** registered for the list of changed fields, so you do not have to call manually each onchange. To avoid performance issue when the method is called on a record, the record will be transformed into a memory record before calling the registered methods to avoid to trigger SQL updates command when values are assigned to the record by the onchange pricelist_id, etc..
Behind the scene, play_onchanges will execute **all the methods**
registered for the list of changed fields, so you do not have to call
manually each onchange. To avoid performance issue when the method is
called on a record, the record will be transformed into a memory record
before calling the registered methods to avoid to trigger SQL updates
command when values are assigned to the record by the onchange
Notes: Notes:
- Order in onchange_fields is very important as onchanges methods will be played in that order. - Order in onchange_fields is very important as onchanges methods will
- If you use memory object in `vals`, be award that onchange method in base model call `self.invalidate_cache()` that reset it. be played in that order.
- If you use memory object in vals, be award that onchange method in
base model call self.invalidate_cache() that reset it.
Known issues / Roadmap Known issues / Roadmap
====================== ======================
Note that onchanges tend to disappear due to the introduction of 'computed stored readonly False fields' in most cases. Note that onchanges tend to disappear due to the introduction of
When migrating, it is best to prefer changing it to that way instead of using this module. 'computed stored readonly False fields' in most cases. When migrating,
it is best to prefer changing it to that way instead of using this
module.
Bug Tracker Bug Tracker
=========== ===========
@ -90,7 +104,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. 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. 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 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:%20onchange_helper%0Aversion:%2016.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:%20onchange_helper%0Aversion:%2017.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.
@ -98,22 +112,22 @@ Credits
======= =======
Authors Authors
~~~~~~~ -------
* Akretion * Akretion
* Camptocamp * Camptocamp
Contributors Contributors
~~~~~~~~~~~~ ------------
* Guewen Baconnier <guewen.baconnier@camptocamp.com> - Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Florian da Costa <florian.dacosta@akretion.com> - Florian da Costa <florian.dacosta@akretion.com>
* Andrea Stirpe <a.stirpe@onestein.nl> - Andrea Stirpe <a.stirpe@onestein.nl>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu> - Souheil Bejaoui <souheil.bejaoui@acsone.eu>
* Kevin Khao <kevin.khao@akretion.com> - Kevin Khao <kevin.khao@akretion.com>
Maintainers Maintainers
~~~~~~~~~~~ -----------
This module is maintained by the OCA. This module is maintained by the OCA.
@ -125,6 +139,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/server-tools <https://github.com/OCA/server-tools/tree/16.0/onchange_helper>`_ project on GitHub. This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/onchange_helper>`_ 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

@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"

View File

@ -0,0 +1,5 @@
- Guewen Baconnier \<<guewen.baconnier@camptocamp.com>\>
- Florian da Costa \<<florian.dacosta@akretion.com>\>
- Andrea Stirpe \<<a.stirpe@onestein.nl>\>
- Souheil Bejaoui \<<souheil.bejaoui@acsone.eu>\>
- Kevin Khao \<<kevin.khao@akretion.com>\>

View File

@ -1,5 +0,0 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Florian da Costa <florian.dacosta@akretion.com>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
* Kevin Khao <kevin.khao@akretion.com>

View File

@ -1 +1,2 @@
This is a technical module. Its goal is to ease the play of onchange method directly called from Python code. This is a technical module. Its goal is to ease the play of onchange
method directly called from Python code.

View File

@ -0,0 +1,4 @@
Note that onchanges tend to disappear due to the introduction of
'computed stored readonly False fields' in most cases. When migrating,
it is best to prefer changing it to that way instead of using this
module.

View File

@ -1,2 +0,0 @@
Note that onchanges tend to disappear due to the introduction of 'computed stored readonly False fields' in most cases.
When migrating, it is best to prefer changing it to that way instead of using this module.

View File

@ -0,0 +1,50 @@
To use this module, you need to:
- depend on this module
- call yourmodel.play_onchanges(values, \['field'\])
Example if you want to create a sale order and you want to get the
values relative to partner_id field (as if you fill the field from UI)
> vals = {'partner_id': 1}
>
> vals = self.env\['sale.order'\].play_onchanges(vals, \['partner_id'\])
Then, vals will be updated with partner_invoice_id, partner_shipping_id,
pricelist_id, etc...
Default values will be used to process onchange methods, if respective
fields are not set in vals. You can get them if you pass fields name in
the list of fields.
> vals = {'partner_id': 1}
>
> vals = self.env\['sale.order'\].play_onchanges(vals, \['partner_id',
> 'date_order'\])
vals will contain, in addition to the changed values, the default value
for date_order
You can also use it on existing record for example:
> vals = {'partner_shipping_id': 1}
>
> vals = sale.play_onchanges(vals, \['partner_shipping_id'\])
Then the onchange will be played with the vals passed and the existing
vals of the sale. vals will be updated with partner_invoice_id,
pricelist_id, etc..
Behind the scene, play_onchanges will execute **all the methods**
registered for the list of changed fields, so you do not have to call
manually each onchange. To avoid performance issue when the method is
called on a record, the record will be transformed into a memory record
before calling the registered methods to avoid to trigger SQL updates
command when values are assigned to the record by the onchange
Notes:
- Order in onchange_fields is very important as onchanges methods will
be played in that order.
- If you use memory object in vals, be award that onchange method in
base model call self.invalidate_cache() that reset it.

View File

@ -1,39 +0,0 @@
To use this module, you need to:
* depend on this module
* call `yourmodel.play_onchanges(values, ['field'])`
Example if you want to create a sale order and you want to get the values relative to partner_id field (as if you fill the field from UI)
`vals = {'partner_id': 1}`
`vals = self.env['sale.order'].play_onchanges(vals, ['partner_id'])`
Then, `vals` will be updated with partner_invoice_id, partner_shipping_id, pricelist_id, etc...
Default values will be used to process onchange methods, if respective fields are not set in `vals`.
You can get them if you pass fields name in the list of fields.
`vals = {'partner_id': 1}`
`vals = self.env['sale.order'].play_onchanges(vals, ['partner_id', 'date_order'])`
`vals` will contain, in addition to the changed values, the default value for `date_order`
You can also use it on existing record for example:
`vals = {'partner_shipping_id': 1}`
`vals = sale.play_onchanges(vals, ['partner_shipping_id'])`
Then the onchange will be played with the vals passed and the existing vals of the sale. `vals` will be updated with partner_invoice_id, pricelist_id, etc..
Behind the scene, `play_onchanges` will execute **all the methods** registered for the list of changed fields, so you do not have to call manually each onchange. To avoid performance issue when the method is called on a record, the record will be transformed into a memory record before calling the registered methods to avoid to trigger SQL updates command when values are assigned to the record by the onchange
Notes:
- Order in onchange_fields is very important as onchanges methods will be played in that order.
- If you use memory object in `vals`, be award that onchange method in base model call `self.invalidate_cache()` that reset it.

View File

@ -369,8 +369,9 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:556ec1d279174035dfcc8805dad664de965fafb926ddc617899c4a7f51756444 !! source digest: sha256:556ec1d279174035dfcc8805dad664de965fafb926ddc617899c4a7f51756444
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/server-tools/tree/16.0/onchange_helper"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-onchange_helper"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&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><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/server-tools/tree/17.0/onchange_helper"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-onchange_helper"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This is a technical module. Its goal is to ease the play of onchange method directly called from Python code.</p> <p>This is a technical module. Its goal is to ease the play of onchange
method directly called from Python code.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
@ -390,45 +391,61 @@ ul.auto-toc {
<p>To use this module, you need to:</p> <p>To use this module, you need to:</p>
<ul class="simple"> <ul class="simple">
<li>depend on this module</li> <li>depend on this module</li>
<li>call <cite>yourmodel.play_onchanges(values, [field])</cite></li> <li>call yourmodel.play_onchanges(values, [field])</li>
</ul> </ul>
<p>Example if you want to create a sale order and you want to get the values relative to partner_id field (as if you fill the field from UI)</p> <p>Example if you want to create a sale order and you want to get the
values relative to partner_id field (as if you fill the field from UI)</p>
<blockquote> <blockquote>
<p><cite>vals = {partner_id: 1}</cite></p> <p>vals = {partner_id: 1}</p>
<p><cite>vals = self.env[sale.order].play_onchanges(vals, [partner_id])</cite></p> <p>vals = self.env[sale.order].play_onchanges(vals, [partner_id])</p>
</blockquote> </blockquote>
<p>Then, <cite>vals</cite> will be updated with partner_invoice_id, partner_shipping_id, pricelist_id, etc…</p> <p>Then, vals will be updated with partner_invoice_id, partner_shipping_id,
<p>Default values will be used to process onchange methods, if respective fields are not set in <cite>vals</cite>. pricelist_id, etc…</p>
You can get them if you pass fields name in the list of fields.</p> <p>Default values will be used to process onchange methods, if respective
fields are not set in vals. You can get them if you pass fields name in
the list of fields.</p>
<blockquote> <blockquote>
<p><cite>vals = {partner_id: 1}</cite></p> <p>vals = {partner_id: 1}</p>
<p><cite>vals = self.env[sale.order].play_onchanges(vals, [partner_id, date_order])</cite></p> <p>vals = self.env[sale.order].play_onchanges(vals, [partner_id,
date_order])</p>
</blockquote> </blockquote>
<p><cite>vals</cite> will contain, in addition to the changed values, the default value for <cite>date_order</cite></p> <p>vals will contain, in addition to the changed values, the default value
for date_order</p>
<p>You can also use it on existing record for example:</p> <p>You can also use it on existing record for example:</p>
<blockquote> <blockquote>
<p><cite>vals = {partner_shipping_id: 1}</cite></p> <p>vals = {partner_shipping_id: 1}</p>
<p><cite>vals = sale.play_onchanges(vals, [partner_shipping_id])</cite></p> <p>vals = sale.play_onchanges(vals, [partner_shipping_id])</p>
</blockquote> </blockquote>
<p>Then the onchange will be played with the vals passed and the existing vals of the sale. <cite>vals</cite> will be updated with partner_invoice_id, pricelist_id, etc..</p> <p>Then the onchange will be played with the vals passed and the existing
<p>Behind the scene, <cite>play_onchanges</cite> will execute <strong>all the methods</strong> registered for the list of changed fields, so you do not have to call manually each onchange. To avoid performance issue when the method is called on a record, the record will be transformed into a memory record before calling the registered methods to avoid to trigger SQL updates command when values are assigned to the record by the onchange</p> vals of the sale. vals will be updated with partner_invoice_id,
pricelist_id, etc..</p>
<p>Behind the scene, play_onchanges will execute <strong>all the methods</strong>
registered for the list of changed fields, so you do not have to call
manually each onchange. To avoid performance issue when the method is
called on a record, the record will be transformed into a memory record
before calling the registered methods to avoid to trigger SQL updates
command when values are assigned to the record by the onchange</p>
<p>Notes:</p> <p>Notes:</p>
<ul class="simple"> <ul class="simple">
<li>Order in onchange_fields is very important as onchanges methods will be played in that order.</li> <li>Order in onchange_fields is very important as onchanges methods will
<li>If you use memory object in <cite>vals</cite>, be award that onchange method in base model call <cite>self.invalidate_cache()</cite> that reset it.</li> be played in that order.</li>
<li>If you use memory object in vals, be award that onchange method in
base model call self.invalidate_cache() that reset it.</li>
</ul> </ul>
</div> </div>
<div class="section" id="known-issues-roadmap"> <div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1> <h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<p>Note that onchanges tend to disappear due to the introduction of computed stored readonly False fields in most cases. <p>Note that onchanges tend to disappear due to the introduction of
When migrating, it is best to prefer changing it to that way instead of using this module.</p> computed stored readonly False fields in most cases. When migrating,
it is best to prefer changing it to that way instead of using this
module.</p>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>. <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. 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 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/server-tools/issues/new?body=module:%20onchange_helper%0Aversion:%2016.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:%20onchange_helper%0Aversion:%2017.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">
@ -457,7 +474,7 @@ If you spotted it first, help us to smash 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/server-tools/tree/16.0/onchange_helper">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/17.0/onchange_helper">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> <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>