diff --git a/lib/concierge/suppliers/kigo/mappers/pricing_setup.rb b/lib/concierge/suppliers/kigo/mappers/pricing_setup.rb index ae3358850..0a6ed7635 100644 --- a/lib/concierge/suppliers/kigo/mappers/pricing_setup.rb +++ b/lib/concierge/suppliers/kigo/mappers/pricing_setup.rb @@ -38,6 +38,19 @@ def currency periodical_rate['CURRENCY'] end + def minimum_stay + min = periodical_rate['MIN_STAY']['DEFAULT_VALUE'] + rules = periodical_rate['MIN_STAY']['MIN_STAY_RULES'] + rules.each do |rule| + before_to = rule['DATE_TO'].nil? || DateTime.parse(rule['DATE_TO']) < DateTime.now + after_from = rule['DATE_FROM'].nil? || DateTime.parse(rule['DATE_FROM']) > DateTime.now + if before_to && after_from + min = rule['MIN_STAY_VALUE'] + end + end + min.to_i + end + private def base_nightly_rate @@ -59,4 +72,4 @@ def minimum_periodical_nightly_rate end -end \ No newline at end of file +end diff --git a/lib/concierge/suppliers/kigo/mappers/property.rb b/lib/concierge/suppliers/kigo/mappers/property.rb index 5f055eb7b..192425a1c 100644 --- a/lib/concierge/suppliers/kigo/mappers/property.rb +++ b/lib/concierge/suppliers/kigo/mappers/property.rb @@ -72,12 +72,14 @@ def set_base_info property.check_in_time = info['PROP_CIN_TIME'] property.check_out_time = info['PROP_COUT_TIME'] property.check_in_instructions = info['PROP_ARRIVAL_SHEET'] - property.minimum_stay = stay_length(info['PROP_STAYTIME_MIN']) + + # min_stay is set here, but maybe overided with a stricter minimum from pricingSetup + property.minimum_stay = stay_length(info['PROP_STAYTIME_MIN']) # Kigo properties are available by default, but most of them has a periodical rate # which covers almost all days. The days which not in periodical rates # have unavailable availabilities for these days - property.default_to_available = true + property.default_to_available = true property.country_code = info['PROP_COUNTRY'] property.city = info['PROP_CITY'] @@ -196,6 +198,11 @@ def set_price property.nightly_rate = pricing_mapper.nightly_rate property.weekly_rate = pricing_mapper.weekly_rate property.monthly_rate = pricing_mapper.monthly_rate + property.minimum_stay = [ + property.minimum_stay.to_i, + pricing_mapper.minimum_stay + ].max + end def code_for(item) diff --git a/spec/fixtures/kigo/pricing_setup.json b/spec/fixtures/kigo/pricing_setup.json index 235fb39c0..f6916f290 100644 --- a/spec/fixtures/kigo/pricing_setup.json +++ b/spec/fixtures/kigo/pricing_setup.json @@ -236,8 +236,7 @@ "MIN_STAY": { "DEFAULT_VALUE": 0, "MIN_STAY_RULES": [ - ] } } -} \ No newline at end of file +} diff --git a/spec/lib/concierge/suppliers/kigo/mappers/property_spec.rb b/spec/lib/concierge/suppliers/kigo/mappers/property_spec.rb index 77db4028b..181471495 100644 --- a/spec/lib/concierge/suppliers/kigo/mappers/property_spec.rb +++ b/spec/lib/concierge/suppliers/kigo/mappers/property_spec.rb @@ -20,6 +20,7 @@ let(:expected_nightly_rate) { 151.98 } context 'stay length' do + context 'unit is month' do let(:minimum_stay) { { @@ -34,6 +35,7 @@ expect(property.minimum_stay).to eq 30 end end + context 'number is zero' do let(:minimum_stay) { { @@ -48,6 +50,51 @@ expect(property.minimum_stay).to eq 1 end end + + context 'pricing_setup has a stricter rule' do + it 'uses the stricter rule' do + pricing['MIN_STAY'] = { + "DEFAULT_VALUE" => 0, + "MIN_STAY_RULES": [ + { + "LABEL" => "Monthly Short term", + "MIN_STAY_VALUE" => 32, + "DATE_FROM" => nil, + "DATE_TO" => nil + } + ] + } + property_data['PROP_INFO']['PROP_STAYTIME_MIN'] = { + 'UNIT' => 'MONTH', + 'NUMBER' => 1 + } + + property = subject.prepare(property_data, pricing).value + expect(property.minimum_stay).to eq 32 + end + end + + context 'pricing_setup has a more lenient rule' do + it 'uses the stricter rule' do + pricing['MIN_STAY'] = { + "DEFAULT_VALUE": 0, "MIN_STAY_RULES": [ + { + "LABEL": "Monthly Short term", + "MIN_STAY_VALUE": 25, + "DATE_FROM": nil, + "DATE_TO": nil + } + ] + } + property_data['PROP_INFO']['PROP_STAYTIME_MIN'] = { + 'UNIT' => 'MONTH', + 'NUMBER' => 1 + } + + property = subject.prepare(property_data, pricing).value + expect(property.minimum_stay).to eq 30 + end + end end context 'description' do