Skip to content

Commit

Permalink
Fixes #381 Parse kigo minimum stay rules
Browse files Browse the repository at this point in the history
  • Loading branch information
keang committed Oct 6, 2016
1 parent 739b623 commit 7f4f161
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
15 changes: 14 additions & 1 deletion lib/concierge/suppliers/kigo/mappers/pricing_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,4 +72,4 @@ def minimum_periodical_nightly_rate

end

end
end
11 changes: 9 additions & 2 deletions lib/concierge/suppliers/kigo/mappers/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/kigo/pricing_setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@
"MIN_STAY": {
"DEFAULT_VALUE": 0,
"MIN_STAY_RULES": [

]
}
}
}
}
47 changes: 47 additions & 0 deletions spec/lib/concierge/suppliers/kigo/mappers/property_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
let(:expected_nightly_rate) { 151.98 }

context 'stay length' do

context 'unit is month' do
let(:minimum_stay) {
{
Expand All @@ -34,6 +35,7 @@
expect(property.minimum_stay).to eq 30
end
end

context 'number is zero' do
let(:minimum_stay) {
{
Expand All @@ -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
Expand Down

0 comments on commit 7f4f161

Please sign in to comment.