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.

142 lines
4.4 KiB

  1. ===========================
  2. Base Many2many Custom Field
  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/base_m2m_custom_field
  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-base_m2m_custom_field
  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 module adds a new Many2many custom field with a `create_table` attribute.
  25. **Table of contents**
  26. .. contents::
  27. :local:
  28. Usage
  29. =====
  30. Many2manyCustom field is useful when a direct access to the relational table
  31. is needed, for example to be editable in a dedicated tree view.
  32. Let's consider following models:
  33. .. code-block:: python
  34. class MyModelA(models.Model):
  35. _name = 'my.model.a'
  36. my_model_b_ids = fields.Many2manyCustom(
  37. 'my.model.b',
  38. 'my_model_a_b_rel',
  39. 'my_model_a_id',
  40. 'my_model_b_id',
  41. create_table=False,
  42. )
  43. class MyModelB(models.Model):
  44. _name = 'my.model.b'
  45. my_model_a_ids = fields.Many2manyCustom(
  46. 'my.model.a',
  47. 'my_model_a_b_rel',
  48. 'my_model_b_id',
  49. 'my_model_a_id',
  50. create_table=False,
  51. )
  52. class MyModelABRel(models.Model):
  53. _name = 'my.model.a.b.rel'
  54. my_model_a_id = fields.Many2one(
  55. 'my.model.a',
  56. required=True,
  57. index=True, # Index is mandatory here
  58. )
  59. my_model_b_id = fields.Many2one(
  60. 'my.model.b',
  61. required=True,
  62. index=True, # Index is mandatory here
  63. )
  64. By setting `create_table=False` on the Many2manyCustom field, and using the
  65. relational table name, as `_name` for the relational model, we're able to
  66. define a dedicated tree view for `my.model.a.b.rel`.
  67. .. code-block:: xml
  68. <record id="my_model_a_b_rel_tree_view" model="ir.ui.view">
  69. <field name="name">my.model.a.b.rel.tree.view</field>
  70. <field name="model">my.model.a.b.rel</field>
  71. <field name="arch" type="xml">
  72. <tree editable="top">
  73. <field name="my_model_a_id" />
  74. <field name="my_model_b_id" />
  75. </tree>
  76. </field>
  77. </record>
  78. Bug Tracker
  79. ===========
  80. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
  81. In case of trouble, please check there if your issue has already been reported.
  82. If you spotted it first, help us smashing it by providing a detailed and welcomed
  83. `feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_m2m_custom_field%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
  84. Do not contact contributors directly about support or help with technical issues.
  85. Credits
  86. =======
  87. Authors
  88. ~~~~~~~
  89. * Camptocamp
  90. Contributors
  91. ~~~~~~~~~~~~
  92. * Akim Juillerat <akim.juillerat@camptocamp.com>
  93. Maintainers
  94. ~~~~~~~~~~~
  95. This module is maintained by the OCA.
  96. .. image:: https://odoo-community.org/logo.png
  97. :alt: Odoo Community Association
  98. :target: https://odoo-community.org
  99. OCA, or the Odoo Community Association, is a nonprofit organization whose
  100. mission is to support the collaborative development of Odoo features and
  101. promote its widespread use.
  102. This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/12.0/base_m2m_custom_field>`_ project on GitHub.
  103. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.