Hi,
You can try this code
Let us assume the field property is the given format
x_so_dispatch_date = fields.Date(string="Dispatch Date")
x_status = fields.Selection([('on_time', 'On Time'), ('late', 'Late')], string="Status")
then add the method like
@api.model
def update_move_status(self):
# Find moves that are not done and have a dispatch date after the current date
late_moves = self.env['stock.move'].search([
('state', '!=', 'done'),
('x_so_dispatch_date', '>', fields.Date.today())
])
# Update the status for late moves
for move in late_moves:
move.x_status = 'late'
# Update the status for on-time moves
on_time_moves = self.env['stock.move'].search([
('state', '!=', 'done'),
('x_so_dispatch_date', ' ])
for move in on_time_moves:
move.x_status = 'on_time'
Hope it helps