I have a model in which I created all the data types of Odoo, char, float, many2many…. etc, I show this model in a view where, depending on the type of data selected by the user, “only one” of these types of data will be shown to enter a value. I am showing the type of data selected by this domain in the view -> attrs = "{'invisible': [('fields_type', '! =', 'Char')]}"
In addition, when “only one” of the fields is saved in the database, the other values in the line are in <null>.
My questions are:
Will there be any “dynamic” way to show only the selected field, without having to load all fields in the view and hide them with attrs?
What would be an "optimal" way to store these values in a database? Do all fields in a single model or should I separate the different fields using some kind of inheritance?
Thank you !
Hello Manuel Alejandro Bouza Lavoy,
Yes, you can do it in a dynamic way with fields_view_get method. Where you can check your condition and based on that you can add on your view.
2nd thing you can use with one model to store the value in the database.no need the separate models.
Thanks
Related
I'm creating an ASP.NET web application which allows users to digitize paper forms. The user will import their own forms which will be converted into HTML with placeholders inserted to accept values from an input form.
Using the fields on this imported paper form, the website will create an input form based on what information is required. "Templates" can also be created for a specific form which allows a user to auto-fill any data that doesn't normally change with each form fill. A user can also save a form they haven't finished for completing/reviewing later.
My question is: how do I store this data? I can't really use a traditional database table because Form X could look nothing like Form Y and require completely different data. I have a SQL database to store the data in (I need this for other aspects of the site too), but I can't simply store all form data in one table or even have separate tables for each form as this will be impractical on a larger scale.
My initial thoughts were using JSON but I have absolutely no idea where to start with this. Can I put JSON data into a regular SQL database column? Can this be used to generate code to build a web form to allow a user to easily fill out their forms using any device (as per my design requirements)?
I think your problem would be very well served using a document DB like mongoDB or Arangodb. Reality nowadays is that applications can , and sometimes should, use more than one DB.
Having said that, if I had to use a relational DB, I would convert your forms into 3 tables. The first top level form would just store something like:
form name ,
form id ,
etc...
The second table would capture the form fields and would look be something like:
FormID
field Id
field name
fiel type (int, varchar, etc...)
sort no.
etc ...
The third table would capture the information entered by the user:
user id
form id
field id
value
creation date time
last modification date time
etc...
Note that by storing the fields in rows instead of columns, it does not matter that you have different types of forms.
I should mention that the above table definitions are not meant to be complete by any means, they are there to give you an idea on how to get started.
Finally, note that many relational DB allow you to store JSON nowadays directly in the DB as you suggested, but that may not be a very good option depending on which DB you are using. Here is an example of storing JSON in mysql just for your reference.
i would like to ask u if there is a way to navigate through sql data with combobox. I want to "download" data form DB to standard item model, choose one column and use it in combobox. When user chose one name it will give me proper id in model->DB id and allow me to chose data to show.
for ex. row with bike name, built_year, wheel size etc and show only its name in combobox, when it get chosen then show rest data in table
i'm just asking is this a good way or just dead end.
Yes, you can.
You can use QSqlQueryModel or QSqlTableModel to get the database data into a item model.
Than you can set the model to the combobox using QComboBox::setModel().
You can choose which column display in the combobox using QComboBox::setModelColumn()
See QComboBox documentation
In Odoo v8 there are many API decorators used. But I don't understand the main difference between #api.depends and #api.onchange.
Can anyone help me out from this one?
Thank You.
#api.depends
This decorator is specifically used for "fields.function" in odoo. For a "field.function", you can calculate the value and store it in a field, where it may possible that the calculation depends on some other field(s) of same table or some other table, in that case you can use '#api.depends' to keep a 'watch' on a field of some table.
So, this will trigger the call to the decorated function if any of the fields in the decorator is 'altered by ORM or changed in the form'.
Let's say there is a table 'A' with fields "x,y & z" and table 'B' with fields "p", where 'p' is a field.function depending upon the field 'x' from table 'A', so if any of the change is made in the field 'x', it will trigger the decorated function for calculating the field 'p' in table 'B'.
Make sure table "A" and "B" are related in some way.
#api.onchange
This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is changed in the form. Here scope is limited to the same screen / model.
Let's say on form we have fields "DOB" and "Age", so we can have #api.onchange decorator for "DOB", where as soon as you change the value of "DOB", you can calculate the "age" field.
You may field similarities in #api.depends and #api.onchange, but the some differences are that scope of onchange is limited to the same screen / model while #api.depends works other related screen / model also.
For more info, Here is the link that describe all API of Odoo v8.
#api.onchange works in virtual records assignment on these records is not written to the database, just used to know which value to send back to the client.
Fields can be computed (instead of read from the database) using the compute parameter, it must assign the computed value to the field, it uses the values of other fields from the same model or others model (unlike #api.onchange which work only with the fields in the same view), it should specify fields using api.depends().
For more information. Please check out our blog :
https://odooforbeginnersblog.wordpress.com/2017/03/01/how-to-override-an-api-depends-decorated-method/
#api.depends
The function defined with this decorator will be called if any change happens in the fields specified. Moreover, the change to the field can be from ORM or changes in the form. Furthermore, if a compute function value depends on another field, then it must be specified using depends.
#api.onchange
The function of this decorator will be called when the field value changes. Moreover, it supports only single field names; on the contrary, dotted names such as parent_id.field_name will not be considered. Furthermore, onchange methods are invoked on pseudo-records that contain values of the form. The following is an example of the same:
Reference for better understanding with example : https://www.cybrosys.com/blog/method-decorators-odoo-13
I have just started implementing search module in a project, where I have a form with fixed fields consisting of combo box, text box, radio button etc (around 200 fields in multiple tabs), and later client should be able to add extra fields too. Once user fills the fields which he wants to search, that search criteria also he should be able to save. For all these reasons, for each field I am associating metadata in the following format.
"EntityName.attributeName": attributeValue
Once the user fills the form fields to search, I will validate form data and and only non empty fields metadata I am sending to server in JSON format. Everything is fine till now. But I am facing an issues now.
Using the metadata of each field I will create a new criteria for each field. but if there are fields where one field metadata depends on other field metadata I am struck.
In the form I have few special category fields in following format : for example DOB,
FROM DATE (meta data: entity1.dob)
TO DATE (meta data: entity1.dob)
both fields belongs to same entity and same column only field name in the UI is different
Like this I have around 20 fields which asks for FROM and TO to query the range (it need not be on date, for example no of bed rooms..it can be on integer, string etc)
My query formation should be in the following way depending on user search criteria. If user entered only FROM field of number of bed rooms then I have to query using EQUAL to operator in sql and if both mentioned then MORETHANEQUAL to for FROM field and LESSTHANEQUAL to for to field. So how I can handle this special case ?
like if he entered number of fields as 4 in TO field of number of bed rooms, then I have to query for houses having number of bed rooms equal to 4. but if in FROM he entered 3 and in To if he entered 7 then I have to query for houses having greater than or equal to 3 bed rooms and less than or equal to 7 bed rooms.
Since I have same metadata for these category fields also I am unable to proceed, to achieve this, what kind of metadata I need to prepare ?
How I can generalize this process to handle all the cases ?
my technology stack: ExtJs, Eclipse Link, spring.
and what are the best practices to follow to support custom fields adding feature in Forms in enterprise applications ?
Off of the top of my head, I would create wizards for these particular cases. So for example, have a custom wizard that allows the user to define a "from" field, a "to" field, and then the comparison operator in one action. This wizard could also be responsible for adding custom properties to the generated fields that could be used by your validation routine. So based on the combo of from, to, and operator, you could create a flexible validation mechanism for ensuring that correct values are entered, ranges are correct, whatever.
You might consider this "wizard" approach for all custom fields, in fact. I could see you predefining all the possible custom field types that could be used and create classes that can be used for those. The classes could be responsible not only for the field creation, but also for providing any custom validation, pre-submit transformation, etc. This approach would make adding new custom field types incredibly simple since all you'd have to do is follow the same implementation as the others that already exist, extend an existing one, etc.
I want to sort information in a dojo EnhancedGrid (connected to database through JsonRestStore). I know dojo grids provide functionality to sort based on a single column. However, in my grid, one column contains combined information from multiple fields (e.g., last name, first name, email, age) of database table. Is there a simple way to sort the grid or the data in the store based on a single filed in database table (e.g., last name)?
It seems I can use "query" to change the view of the store (grid is a view of the store if I understand correctly), but I don't understand how to write a query to do that. Can anyone give me more information about the syntax of using query or how to solve this issue?
Thank you!
It looks like you have to use what is called a comparatorMap for customized grid sorting.
here's one example :
http://www.ibm.com/developerworks/web/library/wa-aj-dojogrid/index.html
(look for the section 'Listing 15. Customize the sort function of Dojo
Grid')
inside the comparator map function is where you would convert the strings to
numbers and make the numeric comparison.