Modifications for monthly invoices

This commit is contained in:
Sergei Tsõganov 2022-08-29 14:06:04 +03:00
parent a21e5c1954
commit 14a9b5b709
5 changed files with 49 additions and 33 deletions

View file

@ -18,10 +18,10 @@ GIT
GIT
remote: https://github.com/internetee/e_invoice.git
revision: 312cac173935f434e449d1714f3497bfee9f8995
revision: da18f3da3219315f732b94fbc165fe83cb828a99
branch: master
specs:
e_invoice (0.1.0)
e_invoice (0.1.1)
builder (~> 3.2)
nokogiri
savon
@ -603,4 +603,4 @@ DEPENDENCIES
wkhtmltopdf-binary (~> 0.12.5.1)
BUNDLED WITH
2.3.16
2.3.21

View file

@ -16,8 +16,9 @@ class SendEInvoiceJob < ApplicationJob
def need_to_process_invoice?(invoice:, 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.do_not_send_e_invoice? && (invoice.monthly_invoice ? true : payable)
return false if unprocessable
true
end

View file

@ -74,7 +74,7 @@ module Registrar::BookKeeping
'product_id': DOMAIN_TO_PRODUCT[price.zone_name.to_sym],
'quantity': 1,
'unit': language == 'en' ? 'pc' : 'tk',
}
}.with_indifferent_access
finalize_invoice_line(line, price: price, duration: duration, activity: activity)
end
@ -98,9 +98,10 @@ module Registrar::BookKeeping
def description_in_language(price:, yearly:)
timeframe_string = yearly ? 'yearly' : 'monthly'
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.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

View file

@ -41,22 +41,10 @@ class Invoice
e_invoice_invoice_items = []
invoice.each do |invoice_item|
e_invoice_invoice_item = EInvoice::InvoiceItem.new.tap do |i|
i.description = invoice_item.description
i.price = invoice_item.price
i.quantity = invoice_item.quantity
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
if invoice.monthly_invoice
e_invoice_invoice_item = generate_monthly_invoice_item(invoice, invoice_item)
else
e_invoice_invoice_item = generate_normal_invoice_item(invoice_item)
end
e_invoice_invoice_items << e_invoice_invoice_item
end
@ -73,21 +61,47 @@ class Invoice
i.beneficiary_name = invoice.seller_name
i.beneficiary_account_number = invoice.seller_iban
i.payer_name = invoice.buyer_name
if invoice.monthly_invoice
i.subtotal = 0
i.vat_amount = 0
i.total = 0
else
i.subtotal = invoice.subtotal
i.vat_amount = invoice.vat_amount
i.total = invoice.total
end
i.subtotal = invoice.subtotal
i.vat_amount = invoice.vat_amount
i.total = invoice.total
i.currency = invoice.currency
i.delivery_channel = %i[internet_bank portal]
i.payable = payable
i.monthly_invoice = invoice.monthly_invoice
end
EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice)
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

View file

@ -110,7 +110,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
def test_monthly_summary_is_delivered_in_estonian
activity = account_activities(:one)
price = billing_prices(:create_one_year)
price = billing_prices(:create_one_month)
activity.update!(activity_type: 'create', price: price)
@user.update(language: 'et')
@ -124,7 +124,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
stub_request(:post, ENV['directo_invoice_url']).with do |request|
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? '309902')
end.to_return(status: 200, body: response)