콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I am wondering how I get other fields values of a one2many related model (and field)...?

first LOC (extending Magento Bridge by Webkul in product.template) is - unsing the old API:

'mage_sync_id': fields.one2many('magento.product.template','template_name','Magento Sync Id', readonly=True),
and I thought this might do it, but nothing comes out - maybe only works on many2one field relations, which would make sense:

'update_date': fields.related('mage_sync_id', 'write_date', type="datetime", relation='magento.product.template',readonly=True, store=True, string="Updated Date"),

So I must compute the field and search the many entries behind mage_sync_id for a special field and get out the values?

But how can I do that?

Something like this?

@api.one
def _compute_o2m_field(self):
    related_recordset = self.env["magento.product.template"].search([])   
    self.products = related_recordset.update_date

Messing up with verions?

아바타
취소

You don't need a related field.

@api.one

def _compute_o2m_field(self):

for obj in self.mage_sync_id

obj.update_date # You Can access the related model like this

작성자

Hm,

I get a syntax error in my editor (Komodo Edit) and also when running it in Odoo using your code.

Do I miss something there?

작성자

OK, the ":" was missing after the second line ;)...

작성자

OK I might be able to acces the fields in the one2many records, but how can I get them into any field in this model?

The compute way doesn't really work.

I also added another field and tried that one to be computed by that function using:

return obj.update_date in the loop...

작성자

Hm,

this @api.one thing is the new API, right?

I am using old API in my scripts (unfortunately)...

Can I still use this?

관련 게시물 답글 화면 활동
2
12월 18
4333
1
2월 21
4008
0
3월 15
3380
2
10월 22
26382
0
8월 21
2176