Skip to Content
Menu
This question has been flagged

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

Avatar
Discard
Best Answer

'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), }

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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')

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 15
8976
2
May 25
3256
1
Oct 22
4058
1
Aug 21
3372
1
Mar 15
3060