Merge pull request #1648 from internetee/1647-invoices-arrive-at-directo-with-0-vat

Pass additional fields of Customer to Directo
This commit is contained in:
Timo Võhmar 2020-08-03 16:17:43 +03:00 committed by GitHub
commit d9e795284c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View file

@ -5,7 +5,7 @@ module Concerns
def as_directo_json
invoice = ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(self))
invoice['customer_code'] = buyer.accounting_customer_code
invoice['customer'] = compose_directo_customer
invoice['issue_date'] = issue_date.strftime('%Y-%m-%d')
invoice['transaction_date'] = account_activity
.bank_transaction&.paid_at&.strftime('%Y-%m-%d')
@ -21,6 +21,14 @@ module Concerns
subtotal, precision: 2, separator: '.'
) }].as_json
end
def compose_directo_customer
{
'code': buyer.accounting_customer_code,
'destination': buyer_country_code,
'vat_reg_no': buyer_vat_no,
}.as_json
end
end
end
end

View file

@ -12,7 +12,7 @@ module Concerns
invoice = {
'number': 1,
'customer_code': accounting_customer_code,
'customer': compose_directo_customer,
'language': language == 'en' ? 'ENG' : '', 'currency': activities.first.currency,
'date': month.end_of_month.strftime('%Y-%m-%d')
}.as_json
@ -109,6 +109,14 @@ module Concerns
}
end
def compose_directo_customer
{
'code': accounting_customer_code,
'destination': address_country_code,
'vat_reg_no': vat_no,
}.as_json
end
def load_price(account_activity)
@pricelists ||= {}
return @pricelists[account_activity.price_id] if @pricelists.key? account_activity.price_id

View file

@ -14,6 +14,15 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
Setting.directo_monthly_number_last = 309901
end
def test_directo_json_sends_customer_as_hash
@invoice.update!(buyer_country_code: @user.address_country_code)
json_output = @invoice.as_directo_json
assert json_output['customer'].is_a? Hash
assert_equal @user.accounting_customer_code, json_output['customer']['code']
assert_equal @user.address_country_code, json_output['customer']['destination']
end
def test_xml_is_include_transaction_date
@invoice.update(total: @invoice.account_activity.bank_transaction.sum)
@invoice.account_activity.bank_transaction.update(paid_at: Time.zone.now)