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.

107 lines
3.2 KiB

  1. .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
  2. :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
  3. :alt: License: AGPL-3
  4. ================
  5. Web Domain Field
  6. ================
  7. When you define a view you can specify on the relational fields a domain
  8. attribute. This attribute is evaluated as filter to apply when displaying
  9. existing records for selection.
  10. .. code-block:: xml
  11. <field name="product_id" domain="[('type','=','product')]"/>
  12. The value provided for the domain attribute must be a string representing a
  13. valid Odoo domain. This string is evaluated on the client side in a
  14. restricted context where we can reference as right operand the values of
  15. fields present into the form and a limited set of functions.
  16. In this context it's hard to build complex domain and we are facing to some
  17. limitations as:
  18. * The syntax to include in your domain a criteria involving values from a
  19. x2many field is complex.
  20. * The right side of domain in case of x2many can involve huge amount of ids
  21. (performance problem).
  22. * Domains computed by an onchange on an other field are not recomputed when
  23. you modify the form and don't modify the field triggering the onchange.
  24. * It's not possible to extend an existing domain. You must completely redefine
  25. the domain in your specialized addon
  26. * etc...
  27. In order to mitigate these limitations this new addon allows you to use the
  28. value of a field as domain of an other field in the xml definition of your
  29. view.
  30. .. code-block:: xml
  31. <field name="product_id_domain" invisible="1"/>
  32. <field name="product_id" domain="product_id_domain"/>
  33. The field used as domain must provide the domain as a JSON encoded string.
  34. .. code-block:: python
  35. product_id_domain = fields.Char(
  36. compute="_compute_product_id_domain",
  37. readonly=True,
  38. store=False,
  39. )
  40. @api.multi
  41. @api.depends('name')
  42. def _compute_product_id_domain(self):
  43. for rec in self:
  44. rec.product_id_domain = json.dumps(
  45. [('type', '=', 'product'), ('name', 'like', rec.name)]
  46. )
  47. Usage
  48. =====
  49. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
  50. :alt: Try me on Runbot
  51. :target: https://runbot.odoo-community.org/runbot/162/10.0
  52. Bug Tracker
  53. ===========
  54. Bugs are tracked on `GitHub Issues
  55. <https://github.com/OCA/web/issues>`_. In case of trouble, please
  56. check there if your issue has already been reported. If you spotted it first,
  57. help us smashing it by providing a detailed and welcomed feedback.
  58. Credits
  59. =======
  60. Images
  61. ------
  62. * Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
  63. Contributors
  64. ------------
  65. * Laurent Mignon <laurent.mignon@acsone.eu>
  66. * Denis Roussel <denis.roussel@acsone.eu>
  67. Maintainer
  68. ----------
  69. .. image:: https://odoo-community.org/logo.png
  70. :alt: Odoo Community Association
  71. :target: https://odoo-community.org
  72. This module is maintained by the OCA.
  73. OCA, or the Odoo Community Association, is a nonprofit organization whose
  74. mission is to support the collaborative development of Odoo features and
  75. promote its widespread use.
  76. To contribute to this module, please visit https://odoo-community.org.