mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 07:26:22 +02:00
Modifications for monthly invoices
This commit is contained in:
parent
a21e5c1954
commit
14a9b5b709
5 changed files with 49 additions and 33 deletions
|
@ -18,10 +18,10 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/internetee/e_invoice.git
|
remote: https://github.com/internetee/e_invoice.git
|
||||||
revision: 312cac173935f434e449d1714f3497bfee9f8995
|
revision: da18f3da3219315f732b94fbc165fe83cb828a99
|
||||||
branch: master
|
branch: master
|
||||||
specs:
|
specs:
|
||||||
e_invoice (0.1.0)
|
e_invoice (0.1.1)
|
||||||
builder (~> 3.2)
|
builder (~> 3.2)
|
||||||
nokogiri
|
nokogiri
|
||||||
savon
|
savon
|
||||||
|
@ -603,4 +603,4 @@ DEPENDENCIES
|
||||||
wkhtmltopdf-binary (~> 0.12.5.1)
|
wkhtmltopdf-binary (~> 0.12.5.1)
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.16
|
2.3.21
|
||||||
|
|
|
@ -16,8 +16,9 @@ class SendEInvoiceJob < ApplicationJob
|
||||||
|
|
||||||
def need_to_process_invoice?(invoice:, payable:)
|
def need_to_process_invoice?(invoice:, payable:)
|
||||||
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}"
|
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}"
|
||||||
|
unprocessable = invoice.do_not_send_e_invoice? && (invoice.monthly_invoice ? true : payable)
|
||||||
return false if invoice.blank?
|
return false if invoice.blank?
|
||||||
return false if invoice.do_not_send_e_invoice? && (invoice.monthly_invoice ? true : payable)
|
return false if unprocessable
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,7 +74,7 @@ module Registrar::BookKeeping
|
||||||
'product_id': DOMAIN_TO_PRODUCT[price.zone_name.to_sym],
|
'product_id': DOMAIN_TO_PRODUCT[price.zone_name.to_sym],
|
||||||
'quantity': 1,
|
'quantity': 1,
|
||||||
'unit': language == 'en' ? 'pc' : 'tk',
|
'unit': language == 'en' ? 'pc' : 'tk',
|
||||||
}
|
}.with_indifferent_access
|
||||||
|
|
||||||
finalize_invoice_line(line, price: price, duration: duration, activity: activity)
|
finalize_invoice_line(line, price: price, duration: duration, activity: activity)
|
||||||
end
|
end
|
||||||
|
@ -98,9 +98,10 @@ module Registrar::BookKeeping
|
||||||
def description_in_language(price:, yearly:)
|
def description_in_language(price:, yearly:)
|
||||||
timeframe_string = yearly ? 'yearly' : 'monthly'
|
timeframe_string = yearly ? 'yearly' : 'monthly'
|
||||||
locale_string = "registrar.invoice_#{timeframe_string}_product_description"
|
locale_string = "registrar.invoice_#{timeframe_string}_product_description"
|
||||||
|
length = yearly ? price.duration.in_years.to_i : price.duration.in_months.to_i
|
||||||
|
|
||||||
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.in_years.to_i)
|
I18n.t(locale_string, tld: ".#{price.zone_name}", length: length)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,22 +41,10 @@ class Invoice
|
||||||
|
|
||||||
e_invoice_invoice_items = []
|
e_invoice_invoice_items = []
|
||||||
invoice.each do |invoice_item|
|
invoice.each do |invoice_item|
|
||||||
e_invoice_invoice_item = EInvoice::InvoiceItem.new.tap do |i|
|
if invoice.monthly_invoice
|
||||||
i.description = invoice_item.description
|
e_invoice_invoice_item = generate_monthly_invoice_item(invoice, invoice_item)
|
||||||
i.price = invoice_item.price
|
else
|
||||||
i.quantity = invoice_item.quantity
|
e_invoice_invoice_item = generate_normal_invoice_item(invoice_item)
|
||||||
i.unit = invoice_item.unit
|
|
||||||
if invoice.monthly_invoice
|
|
||||||
i.subtotal = 0
|
|
||||||
i.vat_rate = 0
|
|
||||||
i.vat_amount = 0
|
|
||||||
i.total = 0
|
|
||||||
else
|
|
||||||
i.subtotal = invoice_item.subtotal
|
|
||||||
i.vat_rate = invoice_item.vat_rate
|
|
||||||
i.vat_amount = invoice_item.vat_amount
|
|
||||||
i.total = invoice_item.total
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
e_invoice_invoice_items << e_invoice_invoice_item
|
e_invoice_invoice_items << e_invoice_invoice_item
|
||||||
end
|
end
|
||||||
|
@ -73,21 +61,47 @@ class Invoice
|
||||||
i.beneficiary_name = invoice.seller_name
|
i.beneficiary_name = invoice.seller_name
|
||||||
i.beneficiary_account_number = invoice.seller_iban
|
i.beneficiary_account_number = invoice.seller_iban
|
||||||
i.payer_name = invoice.buyer_name
|
i.payer_name = invoice.buyer_name
|
||||||
if invoice.monthly_invoice
|
i.subtotal = invoice.subtotal
|
||||||
i.subtotal = 0
|
i.vat_amount = invoice.vat_amount
|
||||||
i.vat_amount = 0
|
i.total = invoice.total
|
||||||
i.total = 0
|
|
||||||
else
|
|
||||||
i.subtotal = invoice.subtotal
|
|
||||||
i.vat_amount = invoice.vat_amount
|
|
||||||
i.total = invoice.total
|
|
||||||
end
|
|
||||||
i.currency = invoice.currency
|
i.currency = invoice.currency
|
||||||
i.delivery_channel = %i[internet_bank portal]
|
i.delivery_channel = %i[internet_bank portal]
|
||||||
i.payable = payable
|
i.payable = payable
|
||||||
|
i.monthly_invoice = invoice.monthly_invoice
|
||||||
end
|
end
|
||||||
|
|
||||||
EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice)
|
EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def generate_normal_invoice_item(item)
|
||||||
|
EInvoice::InvoiceItem.new.tap do |i|
|
||||||
|
i.description = item.description
|
||||||
|
i.unit = item.unit
|
||||||
|
i.price = item.price
|
||||||
|
i.quantity = item.quantity
|
||||||
|
i.subtotal = item.subtotal
|
||||||
|
i.vat_rate = item.vat_rate
|
||||||
|
i.vat_amount = item.vat_amount
|
||||||
|
i.total = item.total
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_monthly_invoice_item(invoice, item)
|
||||||
|
EInvoice::InvoiceItem.new.tap do |i|
|
||||||
|
i.description = item.description
|
||||||
|
i.description = "[#{item.product_id}] #{item.description}" if item.product_id
|
||||||
|
i.unit = item.unit
|
||||||
|
i.price = item.price
|
||||||
|
i.quantity = item.quantity
|
||||||
|
if item.price && item.quantity
|
||||||
|
i.subtotal = (item.price * item.quantity).round(3)
|
||||||
|
i.vat_rate = invoice.vat_rate
|
||||||
|
i.vat_amount = i.subtotal * (i.vat_rate / 100)
|
||||||
|
i.total = i.subtotal + i.vat_amount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -110,7 +110,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_monthly_summary_is_delivered_in_estonian
|
def test_monthly_summary_is_delivered_in_estonian
|
||||||
activity = account_activities(:one)
|
activity = account_activities(:one)
|
||||||
price = billing_prices(:create_one_year)
|
price = billing_prices(:create_one_month)
|
||||||
activity.update!(activity_type: 'create', price: price)
|
activity.update!(activity_type: 'create', price: price)
|
||||||
@user.update(language: 'et')
|
@user.update(language: 'et')
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||||
body = CGI.unescape(request.body)
|
body = CGI.unescape(request.body)
|
||||||
|
|
||||||
(body.include? '.test registreerimine: 1 aasta(t)') &&
|
(body.include? '.test registreerimine: 3 kuu(d)') &&
|
||||||
(body.include? 'Domeenide ettemaks') &&
|
(body.include? 'Domeenide ettemaks') &&
|
||||||
(body.include? '309902')
|
(body.include? '309902')
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue