You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.5 KiB

  1. ===============
  2. Onchange Helper
  3. ===============
  4. .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. !! This file is generated by oca-gen-addon-readme !!
  6. !! changes will be overwritten. !!
  7. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8. .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
  9. :target: https://odoo-community.org/page/development-status
  10. :alt: Beta
  11. .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
  12. :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
  13. :alt: License: AGPL-3
  14. .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
  15. :target: https://github.com/OCA/server-tools/tree/12.0/onchange_helper
  16. :alt: OCA/server-tools
  17. .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
  18. :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-onchange_helper
  19. :alt: Translate me on Weblate
  20. .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
  21. :target: https://runbot.odoo-community.org/runbot/149/12.0
  22. :alt: Try me on Runbot
  23. |badge1| |badge2| |badge3| |badge4| |badge5|
  24. This is a technical module. Its goal is to ease the play of onchange method directly called from Python code.
  25. **Table of contents**
  26. .. contents::
  27. :local:
  28. Usage
  29. =====
  30. To use this module, you need to:
  31. * depend on this module
  32. * call `yourmodel.play_onchanges(values, ['field'])`
  33. 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)
  34. `vals = {'partner_id': 1}`
  35. `vals = self.env['sale.order'].play_onchanges(vals, ['partner_id'])`
  36. Then, `vals` will be updated with partner_invoice_id, partner_shipping_id, pricelist_id, etc...
  37. Default values will be used to process onchange methods, if respective fields are not set in `vals`.
  38. You can get them if you pass fields name in the list of fields.
  39. `vals = {'partner_id': 1}`
  40. `vals = self.env['sale.order'].play_onchanges(vals, ['partner_id', 'date_order'])`
  41. `vals` will contain, in addition to the changed values, the default value for `date_order`
  42. You can also use it on existing record for example:
  43. `vals = {'partner_shipping_id': 1}`
  44. `vals = sale.play_onchanges(vals, ['partner_shipping_id'])`
  45. 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..
  46. 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
  47. Notes:
  48. - Order in onchange_fields is very important as onchanges methods will be played in that order.
  49. - If you use memory object in `vals`, be award that onchange method in base model call `self.invalidate_cache()` that reset it.
  50. Bug Tracker
  51. ===========
  52. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
  53. In case of trouble, please check there if your issue has already been reported.
  54. If you spotted it first, help us smashing it by providing a detailed and welcomed
  55. `feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20onchange_helper%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
  56. Do not contact contributors directly about support or help with technical issues.
  57. Credits
  58. =======
  59. Authors
  60. ~~~~~~~
  61. * Akretion
  62. * Camptocamp
  63. Contributors
  64. ~~~~~~~~~~~~
  65. * Guewen Baconnier <guewen.baconnier@camptocamp.com>
  66. * Florian da Costa <florian.dacosta@akretion.com>
  67. * Andrea Stirpe <a.stirpe@onestein.nl>
  68. * Souheil Bejaoui <souheil.bejaoui@acsone.eu>
  69. Maintainers
  70. ~~~~~~~~~~~
  71. This module is maintained by the OCA.
  72. .. image:: https://odoo-community.org/logo.png
  73. :alt: Odoo Community Association
  74. :target: https://odoo-community.org
  75. OCA, or the Odoo Community Association, is a nonprofit organization whose
  76. mission is to support the collaborative development of Odoo features and
  77. promote its widespread use.
  78. This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/12.0/onchange_helper>`_ project on GitHub.
  79. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.