跳至内容
菜单
此问题已终结

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
1月 25
1850
0
8月 24
1328
1
7月 24
2225
2
9月 22
9598
2
4月 22
4643