Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
12852 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
can't transfer product on stock picking? แก้ไขแล้ว
2
มี.ค. 15
9001
2
พ.ค. 25
3339
1
ต.ค. 22
4090
1
ส.ค. 21
3429
how the stock_moves created ? แก้ไขแล้ว
1
มี.ค. 15
3098