تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2542 أدوات العرض

In a One2many field that is computed (and not stored) I am trying to assign records to it, some of which are archived and some which are not. The field quietly drops the archived records.

	​also_on_product_tmpl_ids = fields.One2many(
'product.template',
string='Also on Products',
compute='_compute_also_on_product_tmpl_ids')

@api.depends('attachment')
def _compute_also_on_product_tmpl_ids(self):
for record in self:
​ related_products = self.env['product.template'].browse([21904, 21978, 21919, 21905, 21981, 21913, 21979, 21909, 21920, 21908, 21917])
​ record.also_on_product_tmpl_ids = related_products

All of the above ids exist, I have just removed some irrelevant code for conciseness here.

I have also tried:

    related_products = self.env['product.template'].with_context(active_test=False).browse([21904, 21978, 21919, 21905, 21981, 21913, 21979, 21909, 21920, 21908, 21917])
record.with_context(active_test=False).also_on_product_tmpl_ids = related_products

This has not yielded a change.


I am viewing this field in a field defined as:

    

Is this a view issue or an ORM issue? How can I override this behaviour?


EDIT:


I have solved this by adding "context" to my field definition:

    also_on_product_tmpl_ids = fields.One2many(
'product.template',
string='Also on Products',
compute='_compute_also_on_product_tmpl_ids',
context={
'active_test': False,
})
الصورة الرمزية
إهمال

Very nice, thank you!

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يناير 25
1883
0
أغسطس 24
1352
1
يوليو 24
2244
2
سبتمبر 22
9625
2
أبريل 22
4676