From c4ec4c5cca927110f3fb68152ad2d2aa1f7b4bde Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 1 Apr 2025 15:23:50 +0530 Subject: [PATCH 1/3] PETOSS-712 | NI category update from openAPI --- docs/payroll_uk/Employee.md | 4 + docs/payroll_uk/Employment.md | 6 +- docs/payroll_uk/NICategory.md | 25 ++ docs/payroll_uk/NICategoryLetter.md | 16 + docs/payroll_uk/NICategoryOneOf.md | 17 + docs/payroll_uk/NICategoryOneOf1.md | 17 + docs/payroll_uk/PayrollUkApi.md | 2 +- docs/payroll_uk/index.html | 97 +++++- lib/xero-ruby.rb | 4 + lib/xero-ruby/models/payroll_uk/employee.rb | 24 +- lib/xero-ruby/models/payroll_uk/employment.rb | 69 +--- .../models/payroll_uk/ni_category.rb | 318 ++++++++++++++++++ .../models/payroll_uk/ni_category_letter.rb | 51 +++ .../models/payroll_uk/ni_category_one_of.rb | 264 +++++++++++++++ .../models/payroll_uk/ni_category_one_of1.rb | 257 ++++++++++++++ 15 files changed, 1109 insertions(+), 62 deletions(-) create mode 100644 docs/payroll_uk/NICategory.md create mode 100644 docs/payroll_uk/NICategoryLetter.md create mode 100644 docs/payroll_uk/NICategoryOneOf.md create mode 100644 docs/payroll_uk/NICategoryOneOf1.md create mode 100644 lib/xero-ruby/models/payroll_uk/ni_category.rb create mode 100644 lib/xero-ruby/models/payroll_uk/ni_category_letter.rb create mode 100644 lib/xero-ruby/models/payroll_uk/ni_category_one_of.rb create mode 100644 lib/xero-ruby/models/payroll_uk/ni_category_one_of1.rb diff --git a/docs/payroll_uk/Employee.md b/docs/payroll_uk/Employee.md index 26a67074..27695f5f 100644 --- a/docs/payroll_uk/Employee.md +++ b/docs/payroll_uk/Employee.md @@ -18,6 +18,8 @@ Name | Type | Description | Notes **payroll_calendar_id** | **String** | Xero unique identifier for the payroll calendar of the employee | [optional] **updated_date_utc** | **DateTime** | UTC timestamp of last update to the employee | [optional] **created_date_utc** | **DateTime** | UTC timestamp when the employee was created in Xero | [optional] +**ni_category** | [**NICategoryLetter**](NICategoryLetter.md) | | [optional] +**ni_categories** | [**Array<NICategory>**](NICategory.md) | The employee's NI categories | [optional] **national_insurance_number** | **String** | National insurance number of the employee | [optional] **is_off_payroll_worker** | **Boolean** | Whether the employee is an off payroll worker | [optional] @@ -40,6 +42,8 @@ instance = XeroRuby::PayrollUk::Employee.new(employee_id: d90457c4-f1be-4f2e-b4e payroll_calendar_id: null, updated_date_utc: null, created_date_utc: null, + ni_category: null, + ni_categories: null, national_insurance_number: AB123456C, is_off_payroll_worker: null) ``` diff --git a/docs/payroll_uk/Employment.md b/docs/payroll_uk/Employment.md index a93e69f8..1d4a3fa6 100644 --- a/docs/payroll_uk/Employment.md +++ b/docs/payroll_uk/Employment.md @@ -7,7 +7,8 @@ Name | Type | Description | Notes **payroll_calendar_id** | **String** | Xero unique identifier for the payroll calendar of the employee | [optional] **start_date** | **Date** | Start date of the employment (YYYY-MM-DD) | [optional] **employee_number** | **String** | The employment number of the employee | [optional] -**ni_category** | **String** | The NI Category of the employee | [optional] +**ni_category** | [**NICategoryLetter**](NICategoryLetter.md) | | [optional] +**ni_categories** | [**Array<NICategory>**](NICategory.md) | The employee's NI categories | [optional] ## Code Sample @@ -17,7 +18,8 @@ require 'XeroRuby::PayrollUk' instance = XeroRuby::PayrollUk::Employment.new(payroll_calendar_id: null, start_date: null, employee_number: 7, - ni_category: A) + ni_category: null, + ni_categories: null) ``` diff --git a/docs/payroll_uk/NICategory.md b/docs/payroll_uk/NICategory.md new file mode 100644 index 00000000..3af09e8d --- /dev/null +++ b/docs/payroll_uk/NICategory.md @@ -0,0 +1,25 @@ +# XeroRuby::PayrollUk::NICategory + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**start_date** | **Date** | The start date of the NI category (YYYY-MM-DD) | [optional] +**ni_category** | [**NICategoryLetter**](NICategoryLetter.md) | | +**ni_category_id** | **Float** | Xero unique identifier for the NI category | [optional] +**date_first_employed_as_civilian** | **Date** | The date in which the employee was first employed as a civilian (YYYY-MM-DD) | [optional] +**workplace_postcode** | **String** | The workplace postcode | + +## Code Sample + +```ruby +require 'XeroRuby::PayrollUk' + +instance = XeroRuby::PayrollUk::NICategory.new(start_date: Mon Dec 02 00:00:00 GMT 2024, + ni_category: null, + ni_category_id: 15, + date_first_employed_as_civilian: Mon Dec 02 00:00:00 GMT 2024, + workplace_postcode: SW1A 1AA) +``` + + diff --git a/docs/payroll_uk/NICategoryLetter.md b/docs/payroll_uk/NICategoryLetter.md new file mode 100644 index 00000000..25c26621 --- /dev/null +++ b/docs/payroll_uk/NICategoryLetter.md @@ -0,0 +1,16 @@ +# XeroRuby::PayrollUk::NICategoryLetter + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Code Sample + +```ruby +require 'XeroRuby::PayrollUk' + +instance = XeroRuby::PayrollUk::NICategoryLetter.new() +``` + + diff --git a/docs/payroll_uk/NICategoryOneOf.md b/docs/payroll_uk/NICategoryOneOf.md new file mode 100644 index 00000000..230db138 --- /dev/null +++ b/docs/payroll_uk/NICategoryOneOf.md @@ -0,0 +1,17 @@ +# XeroRuby::PayrollUk::NICategoryOneOf + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ni_category** | **String** | | [optional] + +## Code Sample + +```ruby +require 'XeroRuby::PayrollUk' + +instance = XeroRuby::PayrollUk::NICategoryOneOf.new(ni_category: null) +``` + + diff --git a/docs/payroll_uk/NICategoryOneOf1.md b/docs/payroll_uk/NICategoryOneOf1.md new file mode 100644 index 00000000..4178441b --- /dev/null +++ b/docs/payroll_uk/NICategoryOneOf1.md @@ -0,0 +1,17 @@ +# XeroRuby::PayrollUk::NICategoryOneOf1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ni_category** | **String** | | [optional] + +## Code Sample + +```ruby +require 'XeroRuby::PayrollUk' + +instance = XeroRuby::PayrollUk::NICategoryOneOf1.new(ni_category: null) +``` + + diff --git a/docs/payroll_uk/PayrollUkApi.md b/docs/payroll_uk/PayrollUkApi.md index 9b3b2beb..fd6035d4 100644 --- a/docs/payroll_uk/PayrollUkApi.md +++ b/docs/payroll_uk/PayrollUkApi.md @@ -950,7 +950,7 @@ api_instance = xero_client. xero_tenant_id = 'xero_tenant_id_example' # String | Xero identifier for Tenant employee_id = '4ff1e5cc-9835-40d5-bb18-09fdb118db9c' # String | Employee id for single object -employment = { "PayrollCalendarID": "216d80e6-af55-47b1-b718-9457c3f5d2fe", "StartDate": "2020-04-01", "EmployeeNumber": "123ABC", "NICategory": "A" } # Employment | +employment = { "PayrollCalendarID": "216d80e6-af55-47b1-b718-9457c3f5d2fe", "StartDate": "2020-04-01", "NICategories": [ { "NICategory": "A", "StartDate": "2020-05-01" } ], "EmployeeNumber": "123ABC" } # Employment | opts = { idempotency_key: 'KEY_VALUE' # String | This allows you to safely retry requests without the risk of duplicate processing. 128 character max. } diff --git a/docs/payroll_uk/index.html b/docs/payroll_uk/index.html index 7a4f2b5a..c3cdac23 100644 --- a/docs/payroll_uk/index.html +++ b/docs/payroll_uk/index.html @@ -1595,6 +1595,16 @@ "format" : "date-time", "x-is-datetime" : true }, + "niCategory" : { + "$ref" : "#/components/schemas/NICategoryLetter" + }, + "niCategories" : { + "type" : "array", + "description" : "The employee's NI categories", + "items" : { + "$ref" : "#/components/schemas/NICategory" + } + }, "nationalInsuranceNumber" : { "type" : "string", "description" : "National insurance number of the employee", @@ -2262,7 +2272,7 @@ }; defs["Employment"] = { "title" : "", - "required" : [ "EmployeeNumber", "NICategory", "PayrollCalendarID", "StartDate" ], + "required" : [ "EmployeeNumber", "NICategories", "PayrollCalendarID", "StartDate" ], "type" : "object", "properties" : { "payrollCalendarID" : { @@ -2282,10 +2292,14 @@ "example" : "7" }, "niCategory" : { - "type" : "string", - "description" : "The NI Category of the employee", - "example" : "A", - "enum" : [ "A", "B", "C", "F", "H", "I", "J", "L", "M", "S", "V", "X", "Z" ] + "$ref" : "#/components/schemas/NICategoryLetter" + }, + "niCategories" : { + "type" : "array", + "description" : "The employee's NI categories", + "items" : { + "$ref" : "#/components/schemas/NICategory" + } } }, "description" : "" @@ -2502,6 +2516,75 @@ } }, "description" : "" +}; + defs["NICategory"] = { + "title" : "", + "required" : [ "niCategory", "workplacePostcode" ], + "type" : "object", + "properties" : { + "startDate" : { + "type" : "string", + "description" : "The start date of the NI category (YYYY-MM-DD)", + "format" : "date", + "example" : "2024-12-02", + "x-is-date" : true + }, + "niCategory" : { + "$ref" : "#/components/schemas/NICategoryLetter" + }, + "niCategoryID" : { + "type" : "number", + "description" : "Xero unique identifier for the NI category", + "example" : 15 + }, + "dateFirstEmployedAsCivilian" : { + "type" : "string", + "description" : "The date in which the employee was first employed as a civilian (YYYY-MM-DD)", + "format" : "date", + "example" : "2024-12-02", + "x-is-date" : true + }, + "workplacePostcode" : { + "type" : "string", + "description" : "The workplace postcode", + "example" : "SW1A 1AA" + } + }, + "description" : "", + "oneOf" : [ { + "$ref" : "#/components/schemas/NICategory_oneOf" + }, { + "$ref" : "#/components/schemas/NICategory_oneOf_1" + } ] +}; + defs["NICategoryLetter"] = { + "title" : "", + "type" : "string", + "description" : "The employee's NI Category letter.", + "example" : "I", + "enum" : [ "A", "B", "C", "D", "E", "F", "H", "I", "J", "K", "L", "M", "N", "S", "V", "X", "Z" ] +}; + defs["NICategory_oneOf"] = { + "title" : "", + "required" : [ "workplacePostcode" ], + "properties" : { + "niCategory" : { + "type" : "string", + "enum" : [ "F", "I", "L", "S", "N", "E", "D", "K" ] + } + }, + "description" : "" +}; + defs["NICategory_oneOf_1"] = { + "title" : "", + "required" : [ "dateFirstEmployedAsCivilian" ], + "properties" : { + "niCategory" : { + "type" : "string", + "enum" : [ "V" ] + } + }, + "description" : "" }; defs["Pagination"] = { "title" : "", @@ -5714,6 +5797,8 @@

Usage and SDK Samples

start_date: start_date } +ni_categories = { + begin response = xero_client.accounting_api.create_employment(xero_tenant_id, employee_id, employment, idempotency_key) return response @@ -5845,7 +5930,7 @@

Parameters

"schema" : { "$ref" : "#/components/schemas/Employment" }, - "example" : "{ \"PayrollCalendarID\": \"216d80e6-af55-47b1-b718-9457c3f5d2fe\", \"StartDate\": \"2020-04-01\", \"EmployeeNumber\": \"123ABC\", \"NICategory\": \"A\" }" + "example" : "{ \"PayrollCalendarID\": \"216d80e6-af55-47b1-b718-9457c3f5d2fe\", \"StartDate\": \"2020-04-01\", \"NICategories\": [ { \"NICategory\": \"A\", \"StartDate\": \"2020-05-01\" } ], \"EmployeeNumber\": \"123ABC\" }" } }, "required" : true diff --git a/lib/xero-ruby.rb b/lib/xero-ruby.rb index 353d2883..ff55029a 100644 --- a/lib/xero-ruby.rb +++ b/lib/xero-ruby.rb @@ -139,6 +139,10 @@ require 'xero-ruby/models/payroll_uk/leave_type' require 'xero-ruby/models/payroll_uk/leave_type_object' require 'xero-ruby/models/payroll_uk/leave_types' +require 'xero-ruby/models/payroll_uk/ni_category' +require 'xero-ruby/models/payroll_uk/ni_category_letter' +require 'xero-ruby/models/payroll_uk/ni_category_one_of' +require 'xero-ruby/models/payroll_uk/ni_category_one_of1' require 'xero-ruby/models/payroll_uk/pagination' require 'xero-ruby/models/payroll_uk/pay_run' require 'xero-ruby/models/payroll_uk/pay_run_calendar' diff --git a/lib/xero-ruby/models/payroll_uk/employee.rb b/lib/xero-ruby/models/payroll_uk/employee.rb index 614e9358..dcca7e20 100644 --- a/lib/xero-ruby/models/payroll_uk/employee.rb +++ b/lib/xero-ruby/models/payroll_uk/employee.rb @@ -60,6 +60,12 @@ class Employee # UTC timestamp when the employee was created in Xero attr_accessor :created_date_utc + + attr_accessor :ni_category + + # The employee's NI categories + attr_accessor :ni_categories + # National insurance number of the employee attr_accessor :national_insurance_number @@ -105,6 +111,8 @@ def self.attribute_map :'payroll_calendar_id' => :'payrollCalendarID', :'updated_date_utc' => :'updatedDateUTC', :'created_date_utc' => :'createdDateUTC', + :'ni_category' => :'niCategory', + :'ni_categories' => :'niCategories', :'national_insurance_number' => :'nationalInsuranceNumber', :'is_off_payroll_worker' => :'isOffPayrollWorker' } @@ -127,6 +135,8 @@ def self.openapi_types :'payroll_calendar_id' => :'String', :'updated_date_utc' => :'DateTime', :'created_date_utc' => :'DateTime', + :'ni_category' => :'NICategoryLetter', + :'ni_categories' => :'Array', :'national_insurance_number' => :'String', :'is_off_payroll_worker' => :'Boolean' } @@ -203,6 +213,16 @@ def initialize(attributes = {}) self.created_date_utc = attributes[:'created_date_utc'] end + if attributes.key?(:'ni_category') + self.ni_category = attributes[:'ni_category'] + end + + if attributes.key?(:'ni_categories') + if (value = attributes[:'ni_categories']).is_a?(Array) + self.ni_categories = value + end + end + if attributes.key?(:'national_insurance_number') self.national_insurance_number = attributes[:'national_insurance_number'] end @@ -256,6 +276,8 @@ def ==(o) payroll_calendar_id == o.payroll_calendar_id && updated_date_utc == o.updated_date_utc && created_date_utc == o.created_date_utc && + ni_category == o.ni_category && + ni_categories == o.ni_categories && national_insurance_number == o.national_insurance_number && is_off_payroll_worker == o.is_off_payroll_worker end @@ -269,7 +291,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [employee_id, title, first_name, last_name, date_of_birth, address, email, gender, phone_number, start_date, end_date, payroll_calendar_id, updated_date_utc, created_date_utc, national_insurance_number, is_off_payroll_worker].hash + [employee_id, title, first_name, last_name, date_of_birth, address, email, gender, phone_number, start_date, end_date, payroll_calendar_id, updated_date_utc, created_date_utc, ni_category, ni_categories, national_insurance_number, is_off_payroll_worker].hash end # Builds the object from hash diff --git a/lib/xero-ruby/models/payroll_uk/employment.rb b/lib/xero-ruby/models/payroll_uk/employment.rb index 70ef8c06..edfd99d2 100644 --- a/lib/xero-ruby/models/payroll_uk/employment.rb +++ b/lib/xero-ruby/models/payroll_uk/employment.rb @@ -25,51 +25,20 @@ class Employment # The employment number of the employee attr_accessor :employee_number - # The NI Category of the employee + attr_accessor :ni_category - A ||= "A".freeze - B ||= "B".freeze - C ||= "C".freeze - F ||= "F".freeze - H ||= "H".freeze - I ||= "I".freeze - J ||= "J".freeze - L ||= "L".freeze - M ||= "M".freeze - S ||= "S".freeze - V ||= "V".freeze - X ||= "X".freeze - Z ||= "Z".freeze - class EnumAttributeValidator - attr_reader :datatype - attr_reader :allowable_values - - def initialize(datatype, allowable_values) - @allowable_values = allowable_values.map do |value| - case datatype.to_s - when /Integer/i - value.to_i - when /Float/i - value.to_f - else - value - end - end - end - - def valid?(value) - !value || allowable_values.include?(value) - end - end - + # The employee's NI categories + attr_accessor :ni_categories + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { :'payroll_calendar_id' => :'payrollCalendarID', :'start_date' => :'startDate', :'employee_number' => :'employeeNumber', - :'ni_category' => :'niCategory' + :'ni_category' => :'niCategory', + :'ni_categories' => :'niCategories' } end @@ -79,7 +48,8 @@ def self.openapi_types :'payroll_calendar_id' => :'String', :'start_date' => :'Date', :'employee_number' => :'String', - :'ni_category' => :'String' + :'ni_category' => :'NICategoryLetter', + :'ni_categories' => :'Array' } end @@ -113,6 +83,12 @@ def initialize(attributes = {}) if attributes.key?(:'ni_category') self.ni_category = attributes[:'ni_category'] end + + if attributes.key?(:'ni_categories') + if (value = attributes[:'ni_categories']).is_a?(Array) + self.ni_categories = value + end + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -125,21 +101,9 @@ def list_invalid_properties # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? - ni_category_validator = EnumAttributeValidator.new('String', ["A", "B", "C", "F", "H", "I", "J", "L", "M", "S", "V", "X", "Z"]) - return false unless ni_category_validator.valid?(@ni_category) true end - # Custom attribute writer method checking allowed values (enum). - # @param [Object] ni_category Object to be assigned - def ni_category=(ni_category) - validator = EnumAttributeValidator.new('String', ["A", "B", "C", "F", "H", "I", "J", "L", "M", "S", "V", "X", "Z"]) - unless validator.valid?(ni_category) - fail ArgumentError, "invalid value for \"ni_category\", must be one of #{validator.allowable_values}." - end - @ni_category = ni_category - end - # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) @@ -148,7 +112,8 @@ def ==(o) payroll_calendar_id == o.payroll_calendar_id && start_date == o.start_date && employee_number == o.employee_number && - ni_category == o.ni_category + ni_category == o.ni_category && + ni_categories == o.ni_categories end # @see the `==` method @@ -160,7 +125,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [payroll_calendar_id, start_date, employee_number, ni_category].hash + [payroll_calendar_id, start_date, employee_number, ni_category, ni_categories].hash end # Builds the object from hash diff --git a/lib/xero-ruby/models/payroll_uk/ni_category.rb b/lib/xero-ruby/models/payroll_uk/ni_category.rb new file mode 100644 index 00000000..3437df24 --- /dev/null +++ b/lib/xero-ruby/models/payroll_uk/ni_category.rb @@ -0,0 +1,318 @@ +=begin +#Xero Payroll UK + +#This is the Xero Payroll API for orgs in the UK region. + +Contact: api@xero.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 4.3.1 + +=end + +require 'time' +require 'date' + +module XeroRuby::PayrollUk + require 'bigdecimal' + + class NICategory + # The start date of the NI category (YYYY-MM-DD) + attr_accessor :start_date + + + attr_accessor :ni_category + + # Xero unique identifier for the NI category + attr_accessor :ni_category_id + + # The date in which the employee was first employed as a civilian (YYYY-MM-DD) + attr_accessor :date_first_employed_as_civilian + + # The workplace postcode + attr_accessor :workplace_postcode + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'start_date' => :'startDate', + :'ni_category' => :'niCategory', + :'ni_category_id' => :'niCategoryID', + :'date_first_employed_as_civilian' => :'dateFirstEmployedAsCivilian', + :'workplace_postcode' => :'workplacePostcode' + } + end + + # Attribute type mapping. + def self.openapi_types + { + :'start_date' => :'Date', + :'ni_category' => :'NICategoryLetter', + :'ni_category_id' => :'Float', + :'date_first_employed_as_civilian' => :'Date', + :'workplace_postcode' => :'String' + } + end + + # List of class defined in oneOf (OpenAPI v3) + def self.openapi_one_of + [ + :'NICategoryOneOf', + :'NICategoryOneOf1' + ] + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollUk::NICategory` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollUk::NICategory`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'start_date') + self.start_date = attributes[:'start_date'] + end + + if attributes.key?(:'ni_category') + self.ni_category = attributes[:'ni_category'] + end + + if attributes.key?(:'ni_category_id') + self.ni_category_id = attributes[:'ni_category_id'] + end + + if attributes.key?(:'date_first_employed_as_civilian') + self.date_first_employed_as_civilian = attributes[:'date_first_employed_as_civilian'] + end + + if attributes.key?(:'workplace_postcode') + self.workplace_postcode = attributes[:'workplace_postcode'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + if @ni_category.nil? + invalid_properties.push('invalid value for "ni_category", ni_category cannot be nil.') + end + + if @workplace_postcode.nil? + invalid_properties.push('invalid value for "workplace_postcode", workplace_postcode cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + return false if @ni_category.nil? + return false if @workplace_postcode.nil? + _one_of_found = false + self.class.openapi_one_of.each do |_class| + _one_of = XeroRuby::PayrollUk.const_get(_class).build_from_hash(self.to_hash) + if _one_of.valid? + if _one_of_found + return false + else + _one_of_found = true + end + end + end + + if !_one_of_found + return false + end + + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + start_date == o.start_date && + ni_category == o.ni_category && + ni_category_id == o.ni_category_id && + date_first_employed_as_civilian == o.date_first_employed_as_civilian && + workplace_postcode == o.workplace_postcode + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [start_date, ni_category, ni_category_id, date_first_employed_as_civilian, workplace_postcode].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.parse(parse_date(value)) + when :Date + Date.parse(parse_date(value)) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :BigDecimal + BigDecimal(value.to_s) + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + XeroRuby::PayrollUk.const_get(type).build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash(downcase: false) + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + key = downcase ? attr : param + hash[key] = _to_hash(value, downcase: downcase) + end + hash + end + + # Returns the object in the form of hash with snake_case + def to_attributes + to_hash(downcase: true) + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value, downcase: false) + if value.is_a?(Array) + value.map do |v| + v.to_hash(downcase: downcase) + end + elsif value.is_a?(Hash) + {}.tap do |hash| + value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) } + end + elsif value.respond_to? :to_hash + value.to_hash(downcase: downcase) + else + value + end + end + + def parse_date(datestring) + if datestring.include?('Date') + date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\// + original, date, timezone = *date_pattern.match(datestring) + date = (date.to_i / 1000) + Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s + elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD + Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s + else # handle date 'types' for small subset of payroll API's + Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s + end + end + end +end diff --git a/lib/xero-ruby/models/payroll_uk/ni_category_letter.rb b/lib/xero-ruby/models/payroll_uk/ni_category_letter.rb new file mode 100644 index 00000000..7c4f69b6 --- /dev/null +++ b/lib/xero-ruby/models/payroll_uk/ni_category_letter.rb @@ -0,0 +1,51 @@ +=begin +#Xero Payroll UK + +#This is the Xero Payroll API for orgs in the UK region. + +Contact: api@xero.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 4.3.1 + +=end + +require 'time' +require 'date' + +module XeroRuby::PayrollUk + class NICategoryLetter + A ||= "A".freeze + B ||= "B".freeze + C ||= "C".freeze + D ||= "D".freeze + E ||= "E".freeze + F ||= "F".freeze + H ||= "H".freeze + I ||= "I".freeze + J ||= "J".freeze + K ||= "K".freeze + L ||= "L".freeze + M ||= "M".freeze + N ||= "N".freeze + S ||= "S".freeze + V ||= "V".freeze + X ||= "X".freeze + Z ||= "Z".freeze + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + constantValues = NICategoryLetter.constants.select { |c| NICategoryLetter::const_get(c) == value } + raise "Invalid ENUM value #{value} for class #NICategoryLetter" if constantValues.empty? + value + end + end +end diff --git a/lib/xero-ruby/models/payroll_uk/ni_category_one_of.rb b/lib/xero-ruby/models/payroll_uk/ni_category_one_of.rb new file mode 100644 index 00000000..c023a6a8 --- /dev/null +++ b/lib/xero-ruby/models/payroll_uk/ni_category_one_of.rb @@ -0,0 +1,264 @@ +=begin +#Xero Payroll UK + +#This is the Xero Payroll API for orgs in the UK region. + +Contact: api@xero.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 4.3.1 + +=end + +require 'time' +require 'date' + +module XeroRuby::PayrollUk + require 'bigdecimal' + + class NICategoryOneOf + + attr_accessor :ni_category + F ||= "F".freeze + I ||= "I".freeze + L ||= "L".freeze + S ||= "S".freeze + N ||= "N".freeze + E ||= "E".freeze + D ||= "D".freeze + K ||= "K".freeze + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'ni_category' => :'niCategory' + } + end + + # Attribute type mapping. + def self.openapi_types + { + :'ni_category' => :'String' + } + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollUk::NICategoryOneOf` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollUk::NICategoryOneOf`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'ni_category') + self.ni_category = attributes[:'ni_category'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + ni_category_validator = EnumAttributeValidator.new('String', ["F", "I", "L", "S", "N", "E", "D", "K"]) + return false unless ni_category_validator.valid?(@ni_category) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] ni_category Object to be assigned + def ni_category=(ni_category) + validator = EnumAttributeValidator.new('String', ["F", "I", "L", "S", "N", "E", "D", "K"]) + unless validator.valid?(ni_category) + fail ArgumentError, "invalid value for \"ni_category\", must be one of #{validator.allowable_values}." + end + @ni_category = ni_category + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + ni_category == o.ni_category + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ni_category].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.parse(parse_date(value)) + when :Date + Date.parse(parse_date(value)) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :BigDecimal + BigDecimal(value.to_s) + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + XeroRuby::PayrollUk.const_get(type).build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash(downcase: false) + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + key = downcase ? attr : param + hash[key] = _to_hash(value, downcase: downcase) + end + hash + end + + # Returns the object in the form of hash with snake_case + def to_attributes + to_hash(downcase: true) + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value, downcase: false) + if value.is_a?(Array) + value.map do |v| + v.to_hash(downcase: downcase) + end + elsif value.is_a?(Hash) + {}.tap do |hash| + value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) } + end + elsif value.respond_to? :to_hash + value.to_hash(downcase: downcase) + else + value + end + end + + def parse_date(datestring) + if datestring.include?('Date') + date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\// + original, date, timezone = *date_pattern.match(datestring) + date = (date.to_i / 1000) + Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s + elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD + Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s + else # handle date 'types' for small subset of payroll API's + Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s + end + end + end +end diff --git a/lib/xero-ruby/models/payroll_uk/ni_category_one_of1.rb b/lib/xero-ruby/models/payroll_uk/ni_category_one_of1.rb new file mode 100644 index 00000000..31509381 --- /dev/null +++ b/lib/xero-ruby/models/payroll_uk/ni_category_one_of1.rb @@ -0,0 +1,257 @@ +=begin +#Xero Payroll UK + +#This is the Xero Payroll API for orgs in the UK region. + +Contact: api@xero.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 4.3.1 + +=end + +require 'time' +require 'date' + +module XeroRuby::PayrollUk + require 'bigdecimal' + + class NICategoryOneOf1 + + attr_accessor :ni_category + V ||= "V".freeze + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'ni_category' => :'niCategory' + } + end + + # Attribute type mapping. + def self.openapi_types + { + :'ni_category' => :'String' + } + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollUk::NICategoryOneOf1` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollUk::NICategoryOneOf1`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'ni_category') + self.ni_category = attributes[:'ni_category'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + ni_category_validator = EnumAttributeValidator.new('String', ["V"]) + return false unless ni_category_validator.valid?(@ni_category) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] ni_category Object to be assigned + def ni_category=(ni_category) + validator = EnumAttributeValidator.new('String', ["V"]) + unless validator.valid?(ni_category) + fail ArgumentError, "invalid value for \"ni_category\", must be one of #{validator.allowable_values}." + end + @ni_category = ni_category + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + ni_category == o.ni_category + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ni_category].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.parse(parse_date(value)) + when :Date + Date.parse(parse_date(value)) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :BigDecimal + BigDecimal(value.to_s) + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + XeroRuby::PayrollUk.const_get(type).build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash(downcase: false) + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + key = downcase ? attr : param + hash[key] = _to_hash(value, downcase: downcase) + end + hash + end + + # Returns the object in the form of hash with snake_case + def to_attributes + to_hash(downcase: true) + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value, downcase: false) + if value.is_a?(Array) + value.map do |v| + v.to_hash(downcase: downcase) + end + elsif value.is_a?(Hash) + {}.tap do |hash| + value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) } + end + elsif value.respond_to? :to_hash + value.to_hash(downcase: downcase) + else + value + end + end + + def parse_date(datestring) + if datestring.include?('Date') + date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\// + original, date, timezone = *date_pattern.match(datestring) + date = (date.to_i / 1000) + Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s + elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD + Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s + else # handle date 'types' for small subset of payroll API's + Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s + end + end + end +end From c7e227f06734ae282f69cb7390a19d06c7d8b3e9 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Wed, 9 Apr 2025 16:28:32 +0530 Subject: [PATCH 2/3] chore: OAS version update 8.0.0 --- Gemfile.lock | 2 +- docs/accounting/index.html | 2 +- docs/app_store/index.html | 2 +- docs/assets/index.html | 2 +- docs/files/index.html | 2 +- docs/finance/index.html | 2 +- docs/payroll_au/index.html | 2 +- docs/payroll_nz/index.html | 2 +- docs/payroll_uk/index.html | 2 +- docs/projects/index.html | 2 +- lib/xero-ruby/version.rb | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b10cb9d5..60328110 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - xero-ruby (10.1.0) + xero-ruby (11.0.0) faraday (>= 2.0, < 3.0) json (~> 2.1, >= 2.1.0) json-jwt (~> 1.16, >= 1.16.3) diff --git a/docs/accounting/index.html b/docs/accounting/index.html index b1bf886f..4fe91ec1 100644 --- a/docs/accounting/index.html +++ b/docs/accounting/index.html @@ -6339,7 +6339,7 @@