from odoo import models, fields


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    driver_id = fields.Many2one(comodel_name='res.users', string='Driver')

    def action_confirm(self):
        """ Updates the Driver details to the delivery order """
        res = super(SaleOrder, self).action_confirm()
        if self.driver_id:
            for picking in self.picking_ids:
                if picking.state not in ['done', 'cancel']:
                    picking.user_id = self.driver_id
        return res
