跳至內容
選單
此問題已被標幟
1 回覆
2874 瀏覽次數

How do I do this?

Cheers,

Rob

頭像
捨棄
作者

I know how to create fields related to fields that I can edit. What I want to do is pick up description_picking from the products on the BOMS. I'm not sure how to use the suggested answer.

Hi, you can override the attribute you need :

Class the_old_you_need_to_change

_inherit=the_old_class

description_picking = fields.One2many('model', 'the attribute you want to link', [...] )

Class you_class

your_attribute_to_link = [...]

I hope this help !

作者

I get an error when I try to do this (help please? Thanks for the help so far):

class sms(models.Model):

_inherit = 'mrp.bom.line'

sms_location = fields.One2many(string='StockLoc', related='product_id.description_picking', readonly='True')

If I understand well, you have :

class ProductTemplate(models.Model):

[...]

description_picking = fields.Text('Description on Picking', translate=True)

[...]

this already exist and you are creating this

class sms(models.Model):

_inherit = 'mrp.bom.line'

sms_location = fields.One2many(string='StockLoc', related='product_id.description_picking', readonly='True')

where you want sms_location to be equal to the "description_picking" field of the product linked to you class (by product_id).

So your sms_location is also a String ?

If it is, try this

sms_location =fields.Text(string='StockLoc', related='product_id.description_picking', readonly='True')

If it don't work or don't do what you want, can you give more details about the error you get ?

作者

That makes perfect sense. Will try it in a minute. Thanks,

Now I just need to add it to the BOM lines. Do you know how to add it to the BOM reports? Or should I start a new question for that?

Rob

Sorry I don't know anything about report. Good luck with you project !

最佳答案

Hi Robert Price,

you can using related="..." for new api:

ex:

product_tmpl_id = fields.Many2one( 'product.template', 'Product Template', related='product_id.product_tmpl_id', help="Technical: used in views")

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 24
20736
1
9月 23
3507
3
5月 23
6127
7
4月 23
49515
1
12月 22
8246