Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2510 Представления

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!

Related Posts Ответы Просмотры Активность
1
янв. 25
1864
0
авг. 24
1341
1
июл. 24
2231
2
сент. 22
9610
2
апр. 22
4658