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.

104 lines
3.0 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. * Domains computed by an onchange on an other field are not recomputed when
  21. you modify the form and don't modify the field triggering the onchange.
  22. * It's not possible to extend an existing domain. You must completely redefine
  23. the domain in your specialized addon
  24. * ...
  25. In order to mitigate these limitations this new addon allows you to use the
  26. value of a field as domain of an other field in the xml definition of your
  27. view.
  28. .. code-block:: xml
  29. <field name="product_id_domain" invisible="1"/>
  30. <field name="product_id" domain="product_id_domain"/>
  31. The field used as domain must provide the domain as a JSON encoded string.
  32. .. code-block:: python
  33. product_id_domain = fields.Char(
  34. compute="_compute_product_id_domain",
  35. readonly=True,
  36. store=False,
  37. )
  38. @api.multi
  39. @api.depends('name')
  40. def _compute_product_id_domain(self):
  41. for rec in self:
  42. rec.product_id_domain = json.dumps(
  43. [('type', '=', 'product'), ('name', 'like', rec.name)]
  44. )
  45. Usage
  46. =====
  47. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
  48. :alt: Try me on Runbot
  49. :target: https://runbot.odoo-community.org/runbot/162/9.0
  50. Bug Tracker
  51. ===========
  52. Bugs are tracked on `GitHub Issues
  53. <https://github.com/OCA/web/issues>`_. In case of trouble, please
  54. check there if your issue has already been reported. If you spotted it first,
  55. help us smashing it by providing a detailed and welcomed feedback.
  56. Credits
  57. =======
  58. Images
  59. ------
  60. * Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
  61. Contributors
  62. ------------
  63. * Laurent Mignon <laurent.mignon@acsone.eu>
  64. Maintainer
  65. ----------
  66. .. image:: https://odoo-community.org/logo.png
  67. :alt: Odoo Community Association
  68. :target: https://odoo-community.org
  69. This module is maintained by the OCA.
  70. OCA, or the Odoo Community Association, is a nonprofit organization whose
  71. mission is to support the collaborative development of Odoo features and
  72. promote its widespread use.
  73. To contribute to this module, please visit https://odoo-community.org.