mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Add support for PG interval field in DirectoInvoice sending
This commit is contained in:
parent
838522b81a
commit
4554975fad
2 changed files with 7 additions and 7 deletions
|
@ -40,8 +40,8 @@ module Registrar::BookKeeping
|
||||||
|
|
||||||
def fetch_invoice_lines(activity, lines)
|
def fetch_invoice_lines(activity, lines)
|
||||||
price = load_price(activity)
|
price = load_price(activity)
|
||||||
if price.duration.include? 'year'
|
if price.duration.in_years.to_i >= 1
|
||||||
price.duration.to_i.times do |duration|
|
price.duration.in_years.to_i.times do |duration|
|
||||||
lines << new_monthly_invoice_line(activity: activity, duration: duration + 1).as_json
|
lines << new_monthly_invoice_line(activity: activity, duration: duration + 1).as_json
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -67,9 +67,9 @@ module Registrar::BookKeeping
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize_invoice_line(line, price:, activity:, duration:)
|
def finalize_invoice_line(line, price:, activity:, duration:)
|
||||||
yearly = price.duration.include?('year')
|
yearly = price.duration.in_years.to_i >= 1
|
||||||
|
|
||||||
line['price'] = yearly ? (price.price.amount / price.duration.to_i) : price.price.amount
|
line['price'] = yearly ? (price.price.amount / price.duration.in_years.to_i) : price.price.amount
|
||||||
line['description'] = description_in_language(price: price, yearly: yearly)
|
line['description'] = description_in_language(price: price, yearly: yearly)
|
||||||
|
|
||||||
if duration.present?
|
if duration.present?
|
||||||
|
@ -90,7 +90,7 @@ module Registrar::BookKeeping
|
||||||
locale_string = "registrar.invoice_#{timeframe_string}_product_description"
|
locale_string = "registrar.invoice_#{timeframe_string}_product_description"
|
||||||
|
|
||||||
I18n.with_locale(language == 'en' ? 'en' : 'et') do
|
I18n.with_locale(language == 'en' ? 'en' : 'et') do
|
||||||
I18n.t(locale_string, tld: ".#{price.zone_name}", length: price.duration.to_i)
|
I18n.t(locale_string, tld: ".#{price.zone_name}", length: price.duration.in_years.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
def test_multi_year_purchases_have_duration_assigned
|
def test_multi_year_purchases_have_duration_assigned
|
||||||
activity = account_activities(:one)
|
activity = account_activities(:one)
|
||||||
price = billing_prices(:create_one_year)
|
price = billing_prices(:create_one_year)
|
||||||
price.update(duration: '3 years')
|
price.update(duration: 3.years)
|
||||||
activity.update(activity_type: 'create', price: price)
|
activity.update(activity_type: 'create', price: price)
|
||||||
|
|
||||||
response = <<-XML
|
response = <<-XML
|
||||||
|
@ -157,7 +157,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
activity = account_activities(:one)
|
activity = account_activities(:one)
|
||||||
price = billing_prices(:create_one_year)
|
price = billing_prices(:create_one_year)
|
||||||
price.update(duration: '3 years')
|
price.update(duration: 3.years)
|
||||||
activity.update(activity_type: 'create', price: price)
|
activity.update(activity_type: 'create', price: price)
|
||||||
|
|
||||||
# Creating account activity for second action
|
# Creating account activity for second action
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue