Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4139 Ansichten

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
Verwerfen

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

Autor

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?

Autor

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

Autor

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

Autor

Hm,

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

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

Can I still use this?

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Dez. 18
4090
1
Feb. 21
3843
0
März 15
3191
2
Okt. 22
26011
0
Aug. 21
1973