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