Skip to content

Commit 15284ab

Browse files
authored
Merge pull request OCA#971 from Rad0van/15.0-mig-base_custom_info
[MIG] base_custom_info
2 parents ec78c57 + 35eb989 commit 15284ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+19752
-0
lines changed

base_custom_info/README.rst

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
================
2+
Base Custom Info
3+
================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15+
:alt: License: LGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
17+
:target: https://github.com/OCA/server-tools/tree/14.0/base_custom_info
18+
:alt: OCA/server-tools
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-base_custom_info
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/149/14.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module allows you to attach custom information to records without the need
29+
to alter the database structure too much.
30+
31+
This module defines several concepts that you have to understand.
32+
33+
Templates
34+
---------
35+
36+
A *template* is a collection of *properties* that a record should have.
37+
*Templates* always apply to a given model, and then you can choose among the
38+
current templates for the model you are using when you edit a record of that
39+
model.
40+
41+
I.e., This addon includes a demo template called "Smart partners", that applies
42+
to the model ``res.partner``, so if you edit any partner, you can choose that
43+
template and get its properties autofilled.
44+
45+
Properties
46+
----------
47+
48+
A *property* is the "name" of the field. *Templates* can have any amount of
49+
*properties*, and when you apply a *template* to a record, it automatically
50+
gets all of its *properties* filled, empty (unless they have a *Default
51+
value*), ready to assign *values*.
52+
53+
You can set a property to as *required* to force it have a value, although you
54+
should keep in mind that for yes/no properties, this would mean that only *yes*
55+
can be selected, and for numeric properties, zero would be forbidden.
56+
57+
Also you can set *Minimum* and *Maximum* limits for every *property*, but those
58+
limits are only used when the data type is text (to constrain its length) or
59+
number. To skip this constraint, just set a maximum smaller than the minimum.
60+
61+
*Properties* always belong to a template, and as such, to a model.
62+
63+
*Properties* define the data type (text, number, yes/no...), and when the type
64+
is "Selection", then you can define what *options* are available.
65+
66+
I.e., the "Smart partners" *template* has the following *properties*:
67+
68+
- Name of his/her teacher
69+
- Amount of people that hates him/her for being so smart
70+
- Average note on all subjects
71+
- Does he/she believe he/she is the smartest person on earth?
72+
- What weaknesses does he/she have?
73+
74+
When you set that template to any partner, you will then be able to fill these
75+
*properties* with *values*.
76+
77+
Categories
78+
----------
79+
80+
*Properties* can also belong to a *category*, which allows you to sort them in
81+
a logical way, and makes further development easier.
82+
83+
For example, the ``website_sale_custom_info`` addon uses these to display a
84+
technical datasheet per product in your online shop, sorted and separated by
85+
category.
86+
87+
You are not required to give a *category* to every *property*.
88+
89+
Options
90+
-------
91+
92+
When a *property*'s type is "Selection", then you define the *options*
93+
available, so the *value* must be one of these *options*.
94+
95+
I.e., the "What weaknesses does he/she have?" *property* has some options:
96+
97+
- Loves junk food
98+
- Needs videogames
99+
- Huge glasses
100+
101+
The *value* will always be one of these.
102+
103+
Value
104+
-----
105+
106+
When you assign a *template* to a partner, and then you get the *properties* it
107+
should have, you still have to set a *value* for each property.
108+
109+
*Values* can be of different types (whole numbers, constrained selection,
110+
booleans...), depending on how the *property* was defined. However, there is
111+
always the ``value`` field, that is a text string, and converts automatically
112+
to/from the correct type.
113+
114+
Why would I need this?
115+
~~~~~~~~~~~~~~~~~~~~~~
116+
117+
Imagine you have some partners that are foreign, and that for those partners
118+
you need some extra information that is not needed for others, and you do not
119+
want to fill the partners model with a lot of fields that will be empty most of
120+
the time.
121+
122+
In this case, you could define a *template* called "Foreign partners", which
123+
will be applied to ``res.partner`` objects, and defines some *properties* that
124+
these are expected to have.
125+
126+
Then you could assign that *template* to a partner, and automatically you will
127+
get a subtable of all the properties it should have, with tools to fill their
128+
*values* correctly.
129+
130+
Does this work with any model?
131+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
Yes and no.
134+
135+
Yes, because this is a base module that provides the tools to make this work
136+
with any model.
137+
138+
No, because, although the tools are provided, they are only applied to the
139+
``res.partner`` model. This is by design, because different models can have
140+
different needs, and we don't want to depend on every possible model.
141+
142+
So, if you want to apply this to other models, you will have to develop a
143+
little additional addon that depends on this one. If you are a developer, refer
144+
to the *Development* section below.
145+
146+
**Table of contents**
147+
148+
.. contents::
149+
:local:
150+
151+
Installation
152+
============
153+
154+
This module serves as a base for other modules that implement this behavior in
155+
concrete models.
156+
157+
This module is a technical dependency and is to be installed in parallel to
158+
other modules.
159+
160+
Configuration
161+
=============
162+
163+
To enable the main *Custom Info* menu:
164+
165+
#. Enable *Settings > General Settings > Manage custom information*.
166+
167+
To enable partner's custom info tab:
168+
169+
#. Enable *Settings > General Settings > Edit custom information in partners*.
170+
171+
Usage
172+
=====
173+
174+
This module defines *Custom Info Templates* that define what properties are
175+
expected for a given record.
176+
177+
To define a template, you need to:
178+
179+
* Go to *Custom Info > Templates*.
180+
* Create one.
181+
* Add some *Properties* to it.
182+
183+
All database records with that template enabled will automatically fill those
184+
properties.
185+
186+
To manage the properties, you need to:
187+
188+
* Go to *Custom Info > Properties*.
189+
190+
To manage the property categories, you need to:
191+
192+
* Go to *Custom Info > Categories*.
193+
194+
Some properties can have a number of options to choose, to manage them:
195+
196+
* Go to *Custom Info > Options*.
197+
198+
To manage their values, you need to:
199+
200+
* Go to *Custom Info > Values*.
201+
202+
Development
203+
===========
204+
205+
To create a module that supports custom information, just depend on this module
206+
and inherit from the ``custom.info`` model.
207+
208+
See an example in the ``product_custom_info`` addon.
209+
210+
Known issues / Roadmap
211+
======================
212+
213+
* Custom properties cannot be shared among templates.
214+
* Required attributes are for now only set in the UI, not in the ORM itself.
215+
* Support recursive templates using options
216+
217+
.. figure:: https://raw.githubusercontent.com/base_custom_info/static/description/customizations-everywhere.jpg
218+
:alt: Customizations Everywhere
219+
220+
If you assign an *additional template* to an option, and while using the owner
221+
form you choose that option, you can then press *reload custom information
222+
templates* to make the owner update itself to include all the properties in all
223+
the involved templates. If you do not press the button, anyway the reloading
224+
will be performed when saving the owner record.
225+
226+
.. figure:: https://raw.githubusercontent.com/base_custom_info/static/description/templateception.jpg
227+
:alt: Templateception
228+
229+
I.e., if you select the option "Needs videogames" for the property "What
230+
weaknesses does he/she have?" of a smart partner and press *reload custom
231+
information templates*, you will get 2 new properties to fill: "Favourite
232+
videogames genre" and "Favourite videogame".
233+
234+
Bug Tracker
235+
===========
236+
237+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
238+
In case of trouble, please check there if your issue has already been reported.
239+
If you spotted it first, help us smashing it by providing a detailed and welcomed
240+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_custom_info%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
241+
242+
Do not contact contributors directly about support or help with technical issues.
243+
244+
Credits
245+
=======
246+
247+
Authors
248+
~~~~~~~
249+
250+
* Tecnativa
251+
252+
Contributors
253+
~~~~~~~~~~~~
254+
255+
* `Tecnativa <https://www.tecnativa.com>`__:
256+
257+
* Rafael Blasco <rafael.blasco@tecnativa.com>
258+
* Carlos Dauden <carlos.dauden@tecnativa.com>
259+
* Sergio Teruel <sergio.teruel@tecnativa.com>
260+
* Jairo Llopis <jairo.llopis@tecnativa.com>
261+
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
262+
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
263+
* Creu Blanca:
264+
265+
* Enric Tobella <etobella@creublanca.es>
266+
* Solvos:
267+
268+
* David Alonso <david.alonso@solvos.es>
269+
* Ecosoft:
270+
271+
* Kitti U. <kittiu@ecosoft.co.th> (migration to v14)
272+
273+
Maintainers
274+
~~~~~~~~~~~
275+
276+
This module is maintained by the OCA.
277+
278+
.. image:: https://odoo-community.org/logo.png
279+
:alt: Odoo Community Association
280+
:target: https://odoo-community.org
281+
282+
OCA, or the Odoo Community Association, is a nonprofit organization whose
283+
mission is to support the collaborative development of Odoo features and
284+
promote its widespread use.
285+
286+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/base_custom_info>`_ project on GitHub.
287+
288+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

base_custom_info/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2015 Antiun Ingeniería S.L. - Sergio Teruel
2+
# Copyright 2015 Antiun Ingeniería S.L. - Carlos Dauden
3+
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
4+
5+
from . import models, wizard

base_custom_info/__manifest__.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2015 Antiun Ingeniería S.L. - Sergio Teruel
2+
# Copyright 2015 Antiun Ingeniería S.L. - Carlos Dauden
3+
# Copyright 2015-2016 Jairo Llopis <jairo.llopis@tecnativa.com>
4+
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
5+
6+
{
7+
"name": "Base Custom Info",
8+
"summary": "Add custom field in models",
9+
"category": "Tools",
10+
"version": "15.0.1.0.1",
11+
"depends": ["base_setup"],
12+
"data": [
13+
"security/ir.model.access.csv",
14+
"security/res_groups_security.xml",
15+
"views/custom_info_category_view.xml",
16+
"views/custom_info_option_view.xml",
17+
"views/custom_info_template_view.xml",
18+
"views/custom_info_property_view.xml",
19+
"views/custom_info_value_view.xml",
20+
"views/menu.xml",
21+
"views/res_partner_view.xml",
22+
"wizard/res_config_settings_view.xml",
23+
],
24+
"assets": {
25+
"web.assets_qweb": ["base_custom_info/static/src/xml/custom_info_item.xml"],
26+
"web.assets_backend": [
27+
"base_custom_info/static/src/js/custom_info_renderer.js",
28+
"base_custom_info/static/src/js/custom_info_view.js",
29+
"base_custom_info/static/src/js/relational_fields.js",
30+
"base_custom_info/static/src/scss/custom_info.scss",
31+
],
32+
},
33+
"demo": [
34+
"demo/custom.info.category.csv",
35+
"demo/custom.info.template.csv",
36+
"demo/custom.info.property.csv",
37+
"demo/custom.info.option.csv",
38+
"demo/res_groups.xml",
39+
"demo/defaults.xml",
40+
],
41+
"images": [
42+
"images/menu.png",
43+
"images/properties.png",
44+
"images/templates.png",
45+
"images/values.png",
46+
],
47+
"author": "Tecnativa,Odoo Community Association (OCA)",
48+
"website": "https://github.com/OCA/server-tools",
49+
"license": "LGPL-3",
50+
"application": True,
51+
"installable": True,
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,sequence
2+
cat_statics,Statistics,50
3+
cat_gaming,Gaming,100
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id,name,property_ids:id,template_id:id
2+
opt_food,Loves junk food,prop_weaknesses,
3+
opt_videogames,Needs videogames,prop_weaknesses,tpl_gamer
4+
opt_glasses,Huge glasses,prop_weaknesses,
5+
opt_shooter,Shooter,prop_fav_genre,
6+
opt_platforms,Platforms,prop_fav_genre,
7+
opt_cars,Cars,prop_fav_genre,
8+
opt_rpg,RPG,prop_fav_genre,
9+
opt_strategy,Strategy,prop_fav_genre,
10+
opt_graphical_adventure,Graphical adventure,prop_fav_genre,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id,name,template_id:id,widget,required,minimum,maximum,category_id:id,sequence
2+
prop_teacher,Name of his/her teacher,tpl_smart,char,,1,30,,100
3+
prop_haters,Amount of people that hates him/her for being so smart,tpl_smart,integer,,0,99999,cat_statics,200
4+
prop_avg_note,Average note on all subjects,tpl_smart,float,True,0,10,cat_statics,300
5+
prop_smartypants,Does he/she believe he/she is the smartest person on earth?,tpl_smart,boolean,,0,-1,,400
6+
prop_weaknesses,What weaknesses does he/she have?,tpl_smart,many2one,,0,-1,,500
7+
prop_fav_genre,Favourite videogames genre,tpl_gamer,many2one,,0,-1,cat_gaming,600
8+
prop_fav_game,Favourite videogame,tpl_gamer,char,,0,-1,cat_gaming,700
9+
prop_buy_fav_game,When Favourite videogame was bought?,tpl_gamer,date,,0,-1,cat_gaming,700
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model,model_id:id
2+
tpl_smart,Smart partners,res.partner,base.model_res_partner
3+
tpl_gamer,Gamers,res.partner,base.model_res_partner

base_custom_info/demo/defaults.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
3+
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
4+
<odoo>
5+
<record id="prop_weaknesses" model="custom.info.property">
6+
<field name="default_value">Huge glasses</field>
7+
</record>
8+
</odoo>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
3+
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
4+
<odoo>
5+
<!-- Enable custom info for partners in demo instances by default -->
6+
<record id="base.group_user" model="res.groups">
7+
<field name="implied_ids" eval="[(4, ref('group_partner'))]" />
8+
</record>
9+
</odoo>

0 commit comments

Comments
 (0)