Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
4271 Näkymät

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
Hylkää

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

Tekijä

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?

Tekijä

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

Tekijä

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

Tekijä

Hm,

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

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

Can I still use this?

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
jouluk. 18
4170
1
helmik. 21
3924
0
maalisk. 15
3280
2
lokak. 22
26191
0
elok. 21
2074