Currently I'm in need of adding a Float compute or related field (both will give me the same result). But I do need the field to be stored. The problem with storing this field is that the model I am trying to update, the stock.move model, currently has a lot of records. So whenever I push my code with the field the instance fails to build as it runs out of memory trying to update all the records within stock.move. I also don't need to update every single record within stock.move. This field will give me added functionality for the future. Is there anyway to limit which records Odoo is trying to update as part of the storing of the field?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
Hi,
You can add the field to the database table using SQL query, which will skip the computation for the existing records.
See an optimization proposed here: https://github.com/odoo/odoo/pull/120328/files
Sample from odoo source code:
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
l10n_pe_group_id = fields.Many2one("account.group", related="account_id.group_id", store=True)
def _auto_init(self):
"""
Create column to stop ORM from computing it himself (too slow)
"""
if not column_exists(self.env.cr, self._table, 'l10n_pe_group_id'):
create_column(self.env.cr, self._table, 'l10n_pe_group_id', 'int4')
self.env.cr.execute("""
UPDATE account_move_line line
SET l10n_pe_group_id = account.group_id
FROM account_account account
WHERE account.id = line.account_id
""")
return super()._auto_init()
Or you can initially add the field as a non computed field in the module and install in the db and then make it as a computed field, this will also do the trick.
Thanks
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
Odoo 15: Related fields in an inherit module
Rozwiązane
|
|
2
wrz 23
|
2310 | |
|
1
sie 23
|
1852 | ||
Compute if time is Between 00:00 and 07:00.
Rozwiązane
|
|
1
sty 23
|
2026 | |
|
1
lip 22
|
2223 | ||
|
0
maj 22
|
2480 |