from odoo import api, fields, models


class HrLeaveAllocation(models.Model):
    _inherit = "hr.leave.allocation"

    xeno_used_days = fields.Float(
        string="Used", default=0.0,
        help="Days used against this allocation. Kept in sync automatically "
             "whenever a matching leave request is validated/unvalidated "
             "(see hr.leave._xeno_sync_allocation_used_days), but can also "
             "be corrected here directly by HR -- mirrors XENHR's "
             "leave_balances.used_days and its 'Revise Balance' action.",
    )
    xeno_remaining_days = fields.Float(
        string="Remaining", compute="_compute_xeno_remaining_days",
        store=True,
        help="number_of_days minus Used. Mirrors XENHR's "
             "allocated_days - used_days shown on the Leave Balance grid.",
    )

    @api.depends("number_of_days", "xeno_used_days")
    def _compute_xeno_remaining_days(self):
        for alloc in self:
            alloc.xeno_remaining_days = (alloc.number_of_days or 0.0) - (alloc.xeno_used_days or 0.0)
