Skip to Content
Menu
This question has been flagged

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?

Avatar
Discard

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

Author

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?

Author

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

Author

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...

Author

Hm,

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

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

Can I still use this?

Related Posts Replies Views Activity
2
Dec 18
3302
1
Feb 21
3366
0
Mar 15
2385
2
Oct 22
24347
0
Aug 21
1392