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

how to add field related?

By
Qamar Soft
on 2/11/15, 6:23 AM 1,637 views

how to add a field related on odoo
I would like to add a text field on stock.move related to stock.picking origin field
I tried this :

_columns={ 'sourcebl': fields.related('picking_id', 'origin', type='char', relation='stock.picking', string='Class Description', store=True, readonly=True), }

do you have any Idea

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 2/11/15, 6:38 AM

'origin', AFAIK, is a char field, so you do not need relation.  I'm not really sure but the store and readonly maybe conflicting as well.  I don't think you really need to store this field.  So:

_columns={ 'sourcebl': fields.related('picking_id', 'origin', type='char', string='Class Description', readonly=True), }

2

aneesh ATEES Infomedia Pvt Ltd

--aneesh ATEES Infomedia Pvt Ltd--
765
| 5 1 6
Thrissur, India
--aneesh ATEES Infomedia Pvt Ltd--

9995074692

aneesh ATEES Infomedia Pvt Ltd
On 2/11/15, 6:34 AM

Type of Fields

Basic Types

boolean:

A boolean (true, false).

Syntax:

fields.boolean('Field Name' [, Optional Parameters]),

integer:

An integer.

Syntax:

fields.integer('Field Name' [, Optional Parameters]),

float:

A floating point number.

Syntax:

fields.float('Field Name' [, Optional Parameters]),

Note

The optional parameter digits defines the precision and scale of the number. The scale being the number of digits after the decimal point whereas the precision is the total number of significant digits in the number (before and after the decimal point). If the parameter digits is not present, the number will be a double precision floating point number. Warning: these floating-point numbers are inexact (not any value can be converted to its binary representation) and this can lead to rounding errors. You should always use the digits parameter for monetary amounts.

Example:

'rate': fields.float( 'Relative Change rate', digits=(12,6) [, Optional Parameters]),

char:

A string of limited length. The required size parameter determines its size.

Syntax:

fields.char( 'Field Name', size=n [, Optional Parameters]), # where ''n'' is an integer.

Example:

'city' : fields.char('City Name', size=30, required=True),

text:

A text field with no limit in length.

Syntax:

fields.text('Field Name' [, Optional Parameters]),

date:

A date.

Syntax:

fields.date('Field Name' [, Optional Parameters]),

datetime:

Allows to store a date and the time of day in the same field.

Syntax:

fields.datetime('Field Name' [, Optional Parameters]),

binary:

A binary chain

selection:

A field which allows the user to make a selection between various predefined values.

Syntax:

fields.selection((('n','Unconfirmed'), ('c','Confirmed')), 'Field Name' [, Optional Parameters]),

Note

Format of the selection parameter: tuple of tuples of strings of the form:

(('key_or_value', 'string_to_display'), ... )

Note

You can specify a function that will return the tuple. Example

def _get_selection(self, cursor, user_id, context=None): return ( ('choice1', 'This is the choice 1'), ('choice2', 'This is the choice 2')) _columns = { 'sel' : fields.selection( _get_selection, 'What do you want ?') }

Example

Using relation fields many2one with selection. In fields definitions add:

..., 'my_field': fields.many2one( 'mymodule.relation.model', 'Title', selection=_sel_func), ...,

And then define the _sel_func like this (but before the fields definitions):

def _sel_func(self, cr, uid, context=None): obj = self.pool.get('mymodule.relation.model') ids = obj.search(cr, uid, []) res = obj.read(cr, uid, ids, ['name', 'id'], context) res = [(r['id'], r['name']) for r in res] return res

1
Quentin THEURET
On 2/11/15, 7:41 AM

You can find more information here : http://odoo-new-api-guide-line.readthedocs.org/en/latest/fields.html#related-field

In the new API, there is not anymore fields.related. You should define your related field like this :

       sourcebl = fields.Char(string='Class Description', related='picking_id.origin')

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

1 follower(s)

Stats

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