mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
parent
1107dc67b8
commit
169c67839e
5 changed files with 34 additions and 3 deletions
|
@ -29,12 +29,14 @@ class Directo < ActiveRecord::Base
|
|||
"InvoiceDate" => invoice.created_at.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"PaymentTerm" => Setting.directo_receipt_payment_term,
|
||||
"Currency" => invoice.currency,
|
||||
"CustomerCode"=> invoice.buyer.accounting_customer_code
|
||||
"CustomerCode"=> invoice.buyer.accounting_customer_code,
|
||||
'TotalVAT' => ActionController::Base.helpers.number_with_precision(invoice.vat_amount, precision: 2, separator: '.')
|
||||
){
|
||||
xml.line(
|
||||
"ProductID" => Setting.directo_receipt_product_name,
|
||||
"Quantity" => 1,
|
||||
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.subtotal, precision: 2, separator: "."),
|
||||
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.subtotal, precision: 2, separator: '.'),
|
||||
'VATCode' => invoice.buyer_vat_no,
|
||||
"ProductName" => invoice.order
|
||||
)
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ class Invoice < ActiveRecord::Base
|
|||
before_create :set_invoice_number
|
||||
before_create :apply_default_vat_rate, unless: :vat_rate?
|
||||
before_create :calculate_total, unless: :total?
|
||||
before_create :apply_default_buyer_vat_no, unless: :buyer_vat_no?
|
||||
|
||||
attribute :vat_rate, ::Type::VATRate.new
|
||||
attr_readonly :vat_rate
|
||||
|
@ -169,6 +170,10 @@ class Invoice < ActiveRecord::Base
|
|||
self.vat_rate = buyer.effective_vat_rate
|
||||
end
|
||||
|
||||
def apply_default_buyer_vat_no
|
||||
self.buyer_vat_no = buyer.vat_no
|
||||
end
|
||||
|
||||
def calculate_total
|
||||
self.total = subtotal + vat_amount
|
||||
end
|
||||
|
|
5
db/migrate/20180314122722_add_invoices_buyer_vat_no.rb
Normal file
5
db/migrate/20180314122722_add_invoices_buyer_vat_no.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddInvoicesBuyerVatNo < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invoices, :buyer_vat_no, :string
|
||||
end
|
||||
end
|
|
@ -1037,7 +1037,8 @@ CREATE TABLE invoices (
|
|||
number integer,
|
||||
cancelled_at timestamp without time zone,
|
||||
total numeric(10,2) NOT NULL,
|
||||
in_directo boolean DEFAULT false
|
||||
in_directo boolean DEFAULT false,
|
||||
buyer_vat_no character varying
|
||||
);
|
||||
|
||||
|
||||
|
@ -4718,3 +4719,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180313090437');
|
|||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180313124751');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180314122722');
|
||||
|
||||
|
|
|
@ -90,4 +90,20 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
assert_equal BigDecimal('5.50'), invoice.total
|
||||
end
|
||||
end
|
||||
|
||||
def test_valid_without_buyer_vat_no
|
||||
@invoice.buyer_vat_no = ''
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_buyer_vat_no_is_taken_from_registrar_by_default
|
||||
registrar = registrars(:bestnames)
|
||||
registrar.vat_no = 'US1234'
|
||||
invoice = @invoice.dup
|
||||
invoice.buyer_vat_no = nil
|
||||
invoice.buyer = registrar
|
||||
invoice.invoice_items = @invoice.invoice_items
|
||||
invoice.save!
|
||||
assert_equal 'US1234', invoice.buyer_vat_no
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue