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.

117 lines
4.3 KiB

  1. This module allows you to attach custom information to records without the need
  2. to alter the database structure too much.
  3. This module defines several concepts that you have to understand.
  4. Templates
  5. ---------
  6. A *template* is a collection of *properties* that a record should have.
  7. *Templates* always apply to a given model, and then you can choose among the
  8. current templates for the model you are using when you edit a record of that
  9. model.
  10. I.e., This addon includes a demo template called "Smart partners", that applies
  11. to the model ``res.partner``, so if you edit any partner, you can choose that
  12. template and get its properties autofilled.
  13. Properties
  14. ----------
  15. A *property* is the "name" of the field. *Templates* can have any amount of
  16. *properties*, and when you apply a *template* to a record, it automatically
  17. gets all of its *properties* filled, empty (unless they have a *Default
  18. value*), ready to assign *values*.
  19. You can set a property to as *required* to force it have a value, although you
  20. should keep in mind that for yes/no properties, this would mean that only *yes*
  21. can be selected, and for numeric properties, zero would be forbidden.
  22. Also you can set *Minimum* and *Maximum* limits for every *property*, but those
  23. limits are only used when the data type is text (to constrain its length) or
  24. number. To skip this constraint, just set a maximum smaller than the minimum.
  25. *Properties* always belong to a template, and as such, to a model.
  26. *Properties* define the data type (text, number, yes/no...), and when the type
  27. is "Selection", then you can define what *options* are available.
  28. I.e., the "Smart partners" *template* has the following *properties*:
  29. - Name of his/her teacher
  30. - Amount of people that hates him/her for being so smart
  31. - Average note on all subjects
  32. - Does he/she believe he/she is the smartest person on earth?
  33. - What weaknesses does he/she have?
  34. When you set that template to any partner, you will then be able to fill these
  35. *properties* with *values*.
  36. Categories
  37. ----------
  38. *Properties* can also belong to a *category*, which allows you to sort them in
  39. a logical way, and makes further development easier.
  40. For example, the ``website_sale_custom_info`` addon uses these to display a
  41. technical datasheet per product in your online shop, sorted and separated by
  42. category.
  43. You are not required to give a *category* to every *property*.
  44. Options
  45. -------
  46. When a *property*'s type is "Selection", then you define the *options*
  47. available, so the *value* must be one of these *options*.
  48. I.e., the "What weaknesses does he/she have?" *property* has some options:
  49. - Loves junk food
  50. - Needs videogames
  51. - Huge glasses
  52. The *value* will always be one of these.
  53. Value
  54. -----
  55. When you assign a *template* to a partner, and then you get the *properties* it
  56. should have, you still have to set a *value* for each property.
  57. *Values* can be of different types (whole numbers, constrained selection,
  58. booleans...), depending on how the *property* was defined. However, there is
  59. always the ``value`` field, that is a text string, and converts automatically
  60. to/from the correct type.
  61. Why would I need this?
  62. ~~~~~~~~~~~~~~~~~~~~~~
  63. Imagine you have some partners that are foreign, and that for those partners
  64. you need some extra information that is not needed for others, and you do not
  65. want to fill the partners model with a lot of fields that will be empty most of
  66. the time.
  67. In this case, you could define a *template* called "Foreign partners", which
  68. will be applied to ``res.partner`` objects, and defines some *properties* that
  69. these are expected to have.
  70. Then you could assign that *template* to a partner, and automatically you will
  71. get a subtable of all the properties it should have, with tools to fill their
  72. *values* correctly.
  73. Does this work with any model?
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. Yes and no.
  76. Yes, because this is a base module that provides the tools to make this work
  77. with any model.
  78. No, because, although the tools are provided, they are only applied to the
  79. ``res.partner`` model. This is by design, because different models can have
  80. different needs, and we don't want to depend on every possible model.
  81. So, if you want to apply this to other models, you will have to develop a
  82. little additional addon that depends on this one. If you are a developer, refer
  83. to the *Development* section below.