Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Beginner question about functional fields and property fields?

By
odooopenerp
on 2/23/15, 11:28 AM 2,665 views

Anyone tell me what is fnct_search, fnct_inv in fucntion field and what is prorperty field? 

5

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 2/23/15, 11:37 AM

Property Fields:
A property is a special field declared as fields.property. It is also called as multi-company field. In database it will not be stored as normal field in respective object table. It will be stored in separate special table called ir_property table.

The fields.property class inherits from fields.function and overrides the read and write method.

When to use it?
Consider 2 companies Company A and Company B.

Company A (US chart of account) - User1
Company B (Indian chart of account) - User2

Each company has its own chart of account. In this case we will use AR and AP as property fields in partner object.

When user1 login and create a customer, he will have AR (Account receivable) and AP (Account payable) as default based on Company A chart of account.

When user2 login and create a customer, he will have AR (Deptors) and AP (Creditors) as default based on Company B chart of account.

The same field acts as different based on the users company. If no value is specified it will return the default value if specified.

The same partner may have different account receivable values depending on the company the user belongs to. When you read a property, the program gives you the property attached to the instance of object you are reading. If this object has no value, the system will give you the default property.

You can ask we can use many2one field. But many2one field values are static and it will not change based on user company.

One interesting thing is:
Properties avoid "spaghetti" code. That means the account module depends on the partner (base) module. But you can install the partner (base) module without the accounting module. If you add a normal field that points to an account in the partner object, both objects will depend on each other. It's much more difficult to maintain and code (for instance, try to remove a table when both tables are pointing to each others.)

One more thing:
In v8, property fields has been deprecated. It was no more called fields.property. Now we can pass it as a boolean parameter for all the fields. company_dependent – whether the field is company-dependent (boolean)

Important columns in db:
name: By convention fields are named as property_field_name. Eg. "property_account_receivable",
type: Eg. "many2one",
company_id: company id,
fields_id: id of field from ir_model_fields,
value_reference: Eg. "account.account,72" (Object relation with id. Stores reference, Different from usual many2one which saves the id only)
res_id: Eg. "res.partner,86" (Object where the field is declared with id). If it is not set, this property will be used as default for all.

For Detailed description link.

Functional Fields:

A functional field is a field whose value is calculated by a function (rather than being stored in the database).

Parameters:

fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type="float", fnct_search=None, obj=None, method=False, store=False, multi=False

where

  • fnct is the function or method that will compute the field value. It must have been declared before declaring the functional field.

  • fnct_inv is the function or method that will allow writing values in that field.

  • type is the field type name returned by the function. It can be any field type name except function.

  • fnct_search allows you to define the searching behaviour on that field.

  • method whether the field is computed by a method (of an object) or a global function

  • store If you want to store field in database or not. Default is False.

  • multi is a group name. All fields with the same multi parameter will be calculated in a single function call.

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/23/15, 11:36 AM

The best answer can be found in the documentation.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 2/23/15, 11:28 AM
Seen: 2665 times
Last updated: 3/16/15, 8:10 AM