Mohamed Fouad
Mohamed Fouad

Reputation: 526

how to run odoo combuted field on all records?

hello everyone i haved been added an filed called employee_id, it gets the record id as the employee id computed field, it worked well when any of depending fields change but i need to run the function on all old date not while creating a new employee or i change the dependens

here is the method

@api.one
@api.depends('name')
def _compute_employee_id(self):
    for rec in self:
        rec.employee_id = rec.id
    pass

employee_id = fields.Char('Employee ID',compute='_compute_employee_id',store=True)

any help will be appreciated

Upvotes: 0

Views: 1112

Answers (1)

mingtwo_h9
mingtwo_h9

Reputation: 326

You can do this right inside Odoo, no need to touch the server.

Enable the developer mode first, then go to Settings - Technical - Actions - Server Actions.

Create a new record, give it a name and select the model of your code, the Action To Do needs to be Execute Python Code with below code in the code field.

for record in records:
    record._compute_employee_id()

Save and click Create Contextual Action, refresh page, go to your module with list view opened, select all, click action, select the action you just created. When it is done, you can go back to server actions and delete the record.

Upvotes: 3

Related Questions