{
  "fieldia": "0.1",
  "id": "leave-request",
  "title": "Time-off request",
  "description": "Days away from work, counted from the dates, sent to a manager to approve.",
  "data": {
    "kind": "record",
    "model": "leave"
  },
  "maxWidth": "medium",
  "look": {
    "theme": "bootstrap"
  },
  "fields": {
    "name": {
      "type": "char",
      "label": "Description"
    },
    "employee_id": {
      "type": "many2one",
      "label": "Employee",
      "relation": "employee",
      "required": true
    },
    "state": {
      "type": "selection",
      "label": "Status",
      "options": [
        {
          "value": "draft",
          "label": "To submit"
        },
        {
          "value": "confirm",
          "label": "To approve"
        },
        {
          "value": "validate",
          "label": "Approved"
        },
        {
          "value": "refuse",
          "label": "Refused"
        }
      ],
      "default": "draft"
    },
    "leave_type": {
      "type": "selection",
      "label": "Kind of leave",
      "required": true,
      "options": [
        {
          "value": "annual",
          "label": "Annual leave"
        },
        {
          "value": "sick",
          "label": "Sick leave"
        },
        {
          "value": "unpaid",
          "label": "Unpaid leave"
        },
        {
          "value": "other",
          "label": "Other"
        }
      ]
    },
    "date_from": {
      "type": "date",
      "label": "From",
      "required": true
    },
    "date_to": {
      "type": "date",
      "label": "To",
      "required": true
    },
    "half_day": {
      "type": "boolean",
      "label": "Half a day"
    },
    "days": {
      "type": "float",
      "label": "Days",
      "digits": [
        4,
        1
      ],
      "compute": "if(half_day, 0.5, if(date_from and date_to, days(date_from, date_to) + 1, 0))"
    },
    "reason": {
      "type": "text",
      "label": "Reason"
    },
    "certificate": {
      "type": "binary",
      "label": "Medical certificate"
    }
  },
  "layout": {
    "type": "sheet",
    "id": "sheet",
    "title": {
      "field": "name",
      "label": "Time off",
      "placeholder": "e.g. Summer holiday"
    },
    "statusbar": {
      "field": "state",
      "visibleStates": [
        "draft",
        "confirm",
        "validate"
      ]
    },
    "buttons": [
      {
        "type": "button",
        "id": "b-submit",
        "label": "Submit",
        "style": "primary",
        "steps": [
          {
            "do": "set",
            "field": "state",
            "value": "'confirm'"
          },
          {
            "do": "save"
          }
        ],
        "invisible": "state != 'draft'"
      },
      {
        "type": "button",
        "id": "b-approve",
        "label": "Approve",
        "style": "primary",
        "steps": [
          {
            "do": "set",
            "field": "state",
            "value": "'validate'"
          },
          {
            "do": "save"
          }
        ],
        "invisible": "state != 'confirm'"
      },
      {
        "type": "button",
        "id": "b-refuse",
        "label": "Refuse",
        "steps": [
          {
            "do": "set",
            "field": "state",
            "value": "'refuse'"
          },
          {
            "do": "save"
          }
        ],
        "invisible": "state != 'confirm'"
      }
    ],
    "children": [
      {
        "type": "section",
        "id": "leave",
        "columns": {
          "wide": 2,
          "medium": 1
        },
        "children": [
          {
            "type": "field",
            "id": "f-employee",
            "field": "employee_id"
          },
          {
            "type": "field",
            "id": "f-type",
            "field": "leave_type"
          },
          {
            "type": "field",
            "id": "f-half",
            "field": "half_day",
            "widget": "toggle"
          },
          {
            "type": "field",
            "id": "f-from",
            "field": "date_from",
            "widget": "daterange",
            "options": {
              "endField": "date_to"
            }
          },
          {
            "type": "field",
            "id": "f-days",
            "field": "days"
          },
          {
            "type": "field",
            "id": "f-reason",
            "field": "reason",
            "colspan": 2
          },
          {
            "type": "field",
            "id": "f-certificate",
            "field": "certificate",
            "invisible": "leave_type != 'sick'",
            "colspan": 2
          }
        ]
      }
    ]
  }
}
