mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 20:49:36 +02:00
Directo job styling fixes
This commit is contained in:
parent
756a8b0c1c
commit
6302462184
3 changed files with 24 additions and 29 deletions
|
@ -11,11 +11,16 @@ module BookKeeping
|
||||||
inv = {
|
inv = {
|
||||||
'number': 1,
|
'number': 1,
|
||||||
'customer_code': accounting_customer_code,
|
'customer_code': accounting_customer_code,
|
||||||
'language': language,
|
'language': language, 'currency': activities.first.currency,
|
||||||
'currency': activities.first.currency,
|
|
||||||
'date': month.end_of_month.strftime('%Y-%m-%d'),
|
'date': month.end_of_month.strftime('%Y-%m-%d'),
|
||||||
}.as_json
|
}.as_json
|
||||||
|
|
||||||
|
inv['invoice_lines'] = prepare_invoice_lines(month: month, activities: activities)
|
||||||
|
|
||||||
|
inv
|
||||||
|
end
|
||||||
|
|
||||||
|
def prepare_invoice_lines(month:, activities:)
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
lines << { 'description': title_for_summary(month) }
|
lines << { 'description': title_for_summary(month) }
|
||||||
|
@ -24,9 +29,7 @@ module BookKeeping
|
||||||
end
|
end
|
||||||
lines << prepayment_for_all(lines)
|
lines << prepayment_for_all(lines)
|
||||||
|
|
||||||
inv['invoice_lines'] = lines.as_json
|
lines.as_json
|
||||||
|
|
||||||
inv
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def title_for_summary(date)
|
def title_for_summary(date)
|
||||||
|
@ -83,19 +86,15 @@ module BookKeeping
|
||||||
end
|
end
|
||||||
|
|
||||||
def description_in_language(price:, yearly:)
|
def description_in_language(price:, yearly:)
|
||||||
if language == 'en'
|
en = language == 'en'
|
||||||
registration_length = yearly ? 'year' : 'month'
|
registration_length = if yearly
|
||||||
prefix = ".#{price.zone_name} registration: #{price.duration.to_i} #{registration_length}"
|
en ? 'year(s)' : 'aasta(t)'
|
||||||
suffix = 's'
|
else
|
||||||
else
|
en ? 'month(s)' : 'kuu(d)'
|
||||||
registration_length = yearly ? 'aasta' : 'kuu'
|
end
|
||||||
prefix = ".#{price.zone_name} registreerimine: #{price.duration.to_i} #{registration_length}"
|
|
||||||
suffix = yearly ? 't' : 'd'
|
|
||||||
end
|
|
||||||
|
|
||||||
return "#{prefix}#{suffix}" if price.duration.to_i > 1
|
registration = en ? 'registration' : 'registreerimine'
|
||||||
|
".#{price.zone_name} #{registration}: #{price.duration.to_i} #{registration_length}"
|
||||||
prefix
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepayment_for_all(lines)
|
def prepayment_for_all(lines)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class DirectoInvoiceForwardJob < Que::Job
|
class DirectoInvoiceForwardJob < Que::Job
|
||||||
def run(monthly: false, dry: false)
|
def run(monthly: false, dry: false)
|
||||||
@dry = dry
|
@dry = dry
|
||||||
@monthly = monthly
|
(@month = Time.zone.now - 1.month) if monthly
|
||||||
api_url = ENV['directo_invoice_url']
|
api_url = ENV['directo_invoice_url']
|
||||||
sales_agent = Setting.directo_sales_agent
|
sales_agent = Setting.directo_sales_agent
|
||||||
payment_term = Setting.directo_receipt_payment_term
|
payment_term = Setting.directo_receipt_payment_term
|
||||||
|
@ -27,15 +27,11 @@ class DirectoInvoiceForwardJob < Que::Job
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_monthly_invoices
|
def send_monthly_invoices
|
||||||
month = Time.zone.now - 1.month
|
Registrar.where(test_registrar: false).find_each do |registrar|
|
||||||
|
|
||||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
|
||||||
next unless registrar.cash_account
|
next unless registrar.cash_account
|
||||||
|
|
||||||
invoice = registrar.monthly_summary(month: month)
|
invoice = registrar.monthly_summary(month: @month)
|
||||||
next if invoice.nil?
|
@client.invoices.add_with_schema(invoice: invoice, schema: 'summary') unless invoice.nil?
|
||||||
|
|
||||||
@client.invoices.add_with_schema(invoice: invoice, schema: 'summary')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
assign_montly_numbers
|
assign_montly_numbers
|
||||||
|
@ -83,7 +79,7 @@ class DirectoInvoiceForwardJob < Que::Job
|
||||||
def update_invoice_directo_state(xml, req)
|
def update_invoice_directo_state(xml, req)
|
||||||
Rails.logger.info "[Directo] - Responded with body: #{xml}"
|
Rails.logger.info "[Directo] - Responded with body: #{xml}"
|
||||||
Nokogiri::XML(xml).css('Result').each do |res|
|
Nokogiri::XML(xml).css('Result').each do |res|
|
||||||
if @monthly
|
if @month
|
||||||
mark_invoice_as_sent(res: res, req: req)
|
mark_invoice_as_sent(res: res, req: req)
|
||||||
else
|
else
|
||||||
inv = Invoice.find_by(number: res.attributes['docid'].value.to_i)
|
inv = Invoice.find_by(number: res.attributes['docid'].value.to_i)
|
||||||
|
@ -97,7 +93,7 @@ class DirectoInvoiceForwardJob < Que::Job
|
||||||
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
||||||
if invoice
|
if invoice
|
||||||
directo_record.item = invoice
|
directo_record.item = invoice
|
||||||
invoice.update_columns(in_directo: true)
|
invoice.update(in_directo: true)
|
||||||
else
|
else
|
||||||
update_directo_number(num: directo_record.invoice_number)
|
update_directo_number(num: directo_record.invoice_number)
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,7 +61,7 @@ class DirectoInvoiceForwardJobTest < 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') &&
|
(body.include? '.test registreerimine: 1 aasta(t)') &&
|
||||||
(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)
|
||||||
|
@ -133,7 +133,7 @@ class DirectoInvoiceForwardJobTest < 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? 'months')
|
body.include? 'month(s)'
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue