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
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Sep 23
|
1849 | ||
|
1
Aug 23
|
1250 | ||
|
1
Jan 23
|
1268 | ||
|
1
Jul 22
|
1652 | ||
|
0
May 22
|
1898 |