snappler_contable_multicurrency 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +398 -0
- data/Rakefile +39 -0
- data/app/helpers/snappler_contable_helper.rb +42 -0
- data/app/models/ledger_account.rb +217 -0
- data/app/models/ledger_account_activo.rb +8 -0
- data/app/models/ledger_account_pasivo.rb +6 -0
- data/app/models/ledger_account_patrimonio_neto.rb +6 -0
- data/app/models/ledger_account_relation.rb +8 -0
- data/app/models/ledger_account_resultado_negativo.rb +6 -0
- data/app/models/ledger_account_resultado_positivo.rb +6 -0
- data/app/models/ledger_currency.rb +5 -0
- data/app/models/ledger_entry.rb +7 -0
- data/app/models/ledger_move.rb +76 -0
- data/lib/generators/snappler_contable/initializer_generator.rb +11 -0
- data/lib/generators/snappler_contable/migrate_generator.rb +25 -0
- data/lib/generators/snappler_contable/new_currency_generator.rb +23 -0
- data/lib/generators/snappler_contable/templates/snappler_contable_add_currencies.rb +20 -0
- data/lib/generators/snappler_contable/templates/snappler_contable_app_ledger_accounts.rb +48 -0
- data/lib/generators/snappler_contable/templates/snappler_contable_migrate.rb +68 -0
- data/lib/generators/snappler_contable/templates/snappler_contable_new_currency.rb +14 -0
- data/lib/snappler_contable/ext/string.rb +5 -0
- data/lib/snappler_contable/railtie.rb +4 -0
- data/lib/snappler_contable/snappler_contable.rb +154 -0
- data/lib/snappler_contable/version.rb +3 -0
- data/lib/snappler_contable_multicurrency.rb +14 -0
- data/lib/tasks/snappler_contable_tasks.rake +4 -0
- data/spec/internal/config/database_example.yml +8 -0
- data/spec/internal/config/initializers/snappler_contable.rb +8 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +64 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/models/ledger_account_spec.rb +308 -0
- data/spec/spec_helper.rb +75 -0
- metadata +84 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class SnapplerContableAddCurrencies < ActiveRecord::Migration[4.2]
|
3
|
+
|
4
|
+
def self.up
|
5
|
+
add_column :ledger_accounts, :balance_sum_usd, :integer, default: 0, limit: 8
|
6
|
+
add_column :ledger_accounts, :balance_sum_eur, :integer, default: 0, limit: 8
|
7
|
+
add_column :ledger_accounts, :balance_sum_brl, :integer, default: 0, limit: 8
|
8
|
+
|
9
|
+
LedgerCurrency.create(name: 'Dolar', code: 'USD', sym: 'u$s')
|
10
|
+
LedgerCurrency.create(name: 'Euro', code: 'EUR', sym: '€')
|
11
|
+
LedgerCurrency.create(name: 'Real', code: 'BRL', sym: 'R$')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_column :ledger_accounts, :balance_sum_usd
|
16
|
+
remove_column :ledger_accounts, :balance_sum_eur
|
17
|
+
remove_column :ledger_accounts, :balance_sum_brl
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class SnapplerContableAppLedgerAccounts < ActiveRecord::Migration[4.2]
|
2
|
+
def self.up
|
3
|
+
activo = LedgerAccount.get('activo')
|
4
|
+
pasivo = LedgerAccount.get('pasivo')
|
5
|
+
patrimonio_neto = LedgerAccount.get('patrimonio_neto')
|
6
|
+
resultado_positivo = LedgerAccount.get('resultado_positivo')
|
7
|
+
resultado_negativo = LedgerAccount.get('resultado_negativo')
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
#-----------------------------------------------------------------
|
13
|
+
#--------------------------------------------- DUMMY DATA
|
14
|
+
# ------------------------- Activo
|
15
|
+
disponibilidades = activo.add_child("Disponibilidades", "disponibilidades")
|
16
|
+
disponibilidades.add_child("Caja", "caja")
|
17
|
+
disponibilidades.add_child("Tesorería", "tesoreria")
|
18
|
+
bancos = disponibilidades.add_child("Bancos", "bancos")
|
19
|
+
bancos.add_child("Banco 1", "banco_1")
|
20
|
+
bancos.add_child("Banco 2", "banco_2")
|
21
|
+
cxc = activo.add_child("Cuentas por Cobrar", "cuentas_por_cobrar")
|
22
|
+
cxc.add_child("Cliente 1", "cliente_1")
|
23
|
+
cxc.add_child("Cliente 2", "cliente_2")
|
24
|
+
|
25
|
+
# ------------------------- Pasivo
|
26
|
+
cxp = pasivo.add_child("Cuentas por Pagar", "cuentas_por_pagar")
|
27
|
+
cxp.add_child("Proveedor 1", "proveedor_1")
|
28
|
+
cxp.add_child("Proveedor 2", "proveedor_2")
|
29
|
+
|
30
|
+
# ------------------------- Patrimonio Neto
|
31
|
+
ap_ret_de_socios = patrimonio_neto.add_child("Ap/Ret de Socios", "ap_ret_de_socios")
|
32
|
+
|
33
|
+
# ------------------------- Resultado Positivo
|
34
|
+
resultado_positivo.add_child("Ventas", "ventas")
|
35
|
+
|
36
|
+
# ------------------------- Resultado Negativo
|
37
|
+
resultado_negativo.add_child("Compras", "compras")
|
38
|
+
|
39
|
+
#-----------------------------------------------------------------
|
40
|
+
#-----------------------------------------------------------------
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.down
|
46
|
+
LedgerAccount.destroy_all("master_ledger_account_id <> 0")
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class SnapplerContableMigrate < ActiveRecord::Migration[4.2]
|
3
|
+
def self.up
|
4
|
+
create_table :ledger_accounts do |t|
|
5
|
+
t.references :owner, polymorphic: true, index: true
|
6
|
+
t.references :master_ledger_account, index: true
|
7
|
+
t.string :internal_name
|
8
|
+
t.integer :balance_sum_ars, default: 0, limit: 8
|
9
|
+
t.string :code_name
|
10
|
+
t.string :type
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
create_table :ledger_account_relations do |t|
|
16
|
+
t.references :ledger_account_father, index: true
|
17
|
+
t.references :ledger_account_child, index: true
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
#Las primeras 5 deben existir
|
23
|
+
aa = LedgerAccountActivo.create(name: 'Activo')
|
24
|
+
ap = LedgerAccountPasivo.create(name: 'Pasivo')
|
25
|
+
apn = LedgerAccountPatrimonioNeto.create(name: 'Patrimonio Neto')
|
26
|
+
arp = LedgerAccountResultadoPositivo.create(name: 'Resultado Positivo')
|
27
|
+
arn = LedgerAccountResultadoNegativo.create(name: 'Resultado Negativo')
|
28
|
+
|
29
|
+
create_table :ledger_moves do |t|
|
30
|
+
t.references :ledger_entry, index: true
|
31
|
+
t.references :ledger_account, index: true
|
32
|
+
t.references :real_ledger_currency, index: true
|
33
|
+
t.references :represent_ledger_currency, index: true
|
34
|
+
t.string :dh, limit: 1
|
35
|
+
t.integer :real_value, default: 0, limit: 8
|
36
|
+
t.integer :represent_value, default: 0, limit: 8
|
37
|
+
t.integer :currency_change
|
38
|
+
|
39
|
+
t.datetime :datetime
|
40
|
+
|
41
|
+
t.timestamps
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
create_table :ledger_entries do |t|
|
46
|
+
t.references :owner, polymorphic: true, index: true
|
47
|
+
t.string :code_name
|
48
|
+
t.timestamps
|
49
|
+
end
|
50
|
+
|
51
|
+
create_table :ledger_currencies do |t|
|
52
|
+
t.string :name
|
53
|
+
t.string :code
|
54
|
+
t.string :sym
|
55
|
+
t.timestamps
|
56
|
+
end
|
57
|
+
|
58
|
+
LedgerCurrency.create(name: 'Peso', code: 'ARS', sym: '$')
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.down
|
62
|
+
drop_table :ledger_accounts
|
63
|
+
drop_table :ledger_account_relations
|
64
|
+
drop_table :ledger_moves
|
65
|
+
drop_table :ledger_entries
|
66
|
+
drop_table :ledger_currencies
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class SnapplerContableNewCurrency < ActiveRecord::Migration[4.2]
|
3
|
+
|
4
|
+
def self.up
|
5
|
+
add_column :ledger_accounts, :balance_sum_jpy, :integer, default: 0, limit: 8
|
6
|
+
|
7
|
+
LedgerCurrency.create(name: 'Yen', code: 'JPY', sym: '¥')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_column :ledger_accounts, :balance_sum_jpy
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module SnapplerContable
|
2
|
+
class << self
|
3
|
+
|
4
|
+
#-------------------------- Configuraciones
|
5
|
+
|
6
|
+
#Moneda por defecto
|
7
|
+
def default_currency
|
8
|
+
LedgerCurrency.find_by_code(@my_default_currency)
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_currency=(default_currency)
|
12
|
+
@my_default_currency = default_currency
|
13
|
+
end
|
14
|
+
|
15
|
+
#Monedas usadas/configuradas
|
16
|
+
def used_currencies
|
17
|
+
@my_used_currencies
|
18
|
+
end
|
19
|
+
|
20
|
+
def used_currencies=(used_currencies)
|
21
|
+
@my_used_currencies = used_currencies
|
22
|
+
end
|
23
|
+
|
24
|
+
#Divisor por defecto
|
25
|
+
def default_divisor
|
26
|
+
@my_default_divisor
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_divisor=(default_divisor)
|
30
|
+
@my_default_divisor = default_divisor
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def root_accounts
|
35
|
+
LedgerAccount.where(master_ledger_account: nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def op(array_debe, array_haber, params={})
|
41
|
+
|
42
|
+
code_name = params[:code_name] || nil
|
43
|
+
owner = params[:owner] || nil
|
44
|
+
datetime = params[:datetime] || DateTime.now
|
45
|
+
|
46
|
+
debe_accounts = extract_accounts(array_debe, 'D')
|
47
|
+
haber_accounts = extract_accounts(array_haber, 'H')
|
48
|
+
|
49
|
+
|
50
|
+
total_debe = debe_accounts.inject(0){|init, move| init + move[:value] }
|
51
|
+
total_haber = haber_accounts.inject(0){|init, move| init + move[:value] }
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
if total_haber != total_debe
|
57
|
+
raise "Las sumas del DEBE y HABER son diferentes - debe: #{total_debe} haber: #{total_haber}"
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
moves = debe_accounts + haber_accounts
|
62
|
+
|
63
|
+
|
64
|
+
if moves.all?{|move| move.key? :order}
|
65
|
+
moves.sort!{|a, b| a[:order] <=> b[:order]}
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
entry = LedgerEntry.create(code_name: code_name, owner: owner)
|
70
|
+
moves.each do |m|
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
if m.key? :ledger_currency
|
75
|
+
if m[:ledger_currency].is_a? Numeric
|
76
|
+
m[:ledger_currency] = LedgerCurrency.find(m[:ledger_currency])
|
77
|
+
elsif m[:ledger_currency].is_a? String
|
78
|
+
m[:ledger_currency] = LedgerCurrency.find_by_code(m[:ledger_currency])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
m[:ledger_currency] = SnapplerContable.default_currency
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
if m.key? :represent_ledger_currency
|
86
|
+
if m[:represent_ledger_currency].is_a? Numeric
|
87
|
+
m[:represent_ledger_currency] = LedgerCurrency.find(m[:represent_ledger_currency])
|
88
|
+
elsif m[:represent_ledger_currency].is_a? String
|
89
|
+
m[:represent_ledger_currency] = LedgerCurrency.find_by_code(m[:represent_ledger_currency])
|
90
|
+
end
|
91
|
+
else
|
92
|
+
m[:represent_ledger_currency] = m[:ledger_currency]
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
unless m.key? :currency_change
|
97
|
+
if m[:ledger_currency] == m[:represent_ledger_currency]
|
98
|
+
m[:currency_change] = 1
|
99
|
+
else
|
100
|
+
raise "Especificar ratio de cambio entre valor real y representado"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
unless m.key? :represent_value
|
105
|
+
m[:represent_value] = m[:value]
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
entry.ledger_moves.build(ledger_account: m[:account],
|
111
|
+
real_ledger_currency: m[:ledger_currency],
|
112
|
+
real_value: m[:value],
|
113
|
+
represent_ledger_currency: m[:represent_ledger_currency],
|
114
|
+
represent_value: m[:represent_value],
|
115
|
+
currency_change: m[:currency_change],
|
116
|
+
dh: m[:dh],
|
117
|
+
datetime: datetime)
|
118
|
+
end
|
119
|
+
|
120
|
+
if entry.save
|
121
|
+
entry
|
122
|
+
else
|
123
|
+
entry.destroy
|
124
|
+
raise "Fallo la creacion del movimiento: #{moves}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
def extract_accounts(moves_array, debe_haber)
|
131
|
+
res_accounts = []
|
132
|
+
moves_array.each do |move|
|
133
|
+
move[:dh] = debe_haber
|
134
|
+
if move.key? :account
|
135
|
+
acc = move[:account]
|
136
|
+
if (acc.class.to_s == 'LedgerAccount') or (acc.class.superclass.to_s == 'LedgerAccount')
|
137
|
+
res_accounts << move
|
138
|
+
else
|
139
|
+
if acc.nil?
|
140
|
+
raise "Se paso como cuenta un objeto Nil"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
else
|
144
|
+
raise "El hash de movimiento no tiene :account - #{move}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
return res_accounts
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "snappler_contable/ext/string"
|
2
|
+
require "snappler_contable/snappler_contable"
|
3
|
+
|
4
|
+
module SnapplerContable
|
5
|
+
|
6
|
+
# To setup run $ rails generate snappler_contable:install
|
7
|
+
def self.setup
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'snappler_contable/railtie' if defined?(Rails)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
#
|
3
|
+
create_table "ledger_account_relations", force: :true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
4
|
+
t.integer "ledger_account_father_id"
|
5
|
+
t.integer "ledger_account_child_id"
|
6
|
+
t.datetime "created_at"
|
7
|
+
t.datetime "updated_at"
|
8
|
+
t.index ["ledger_account_child_id"], name: "index_ledger_account_relations_on_ledger_account_child_id", using: :btree
|
9
|
+
t.index ["ledger_account_father_id"], name: "index_ledger_account_relations_on_ledger_account_father_id", using: :btree
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table "ledger_accounts", force: :true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
13
|
+
t.string "owner_type"
|
14
|
+
t.integer "owner_id"
|
15
|
+
t.integer "master_ledger_account_id"
|
16
|
+
t.string "internal_name"
|
17
|
+
t.bigint "balance_sum_ars", default: 0
|
18
|
+
t.string "code_name"
|
19
|
+
t.string "type"
|
20
|
+
t.datetime "created_at"
|
21
|
+
t.datetime "updated_at"
|
22
|
+
t.bigint "balance_sum_usd", default: 0
|
23
|
+
t.bigint "balance_sum_eur", default: 0
|
24
|
+
t.bigint "balance_sum_brl", default: 0
|
25
|
+
t.index ["master_ledger_account_id"], name: "index_ledger_accounts_on_master_ledger_account_id", using: :btree
|
26
|
+
t.index ["owner_type", "owner_id"], name: "index_ledger_accounts_on_owner_type_and_owner_id", using: :btree
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "ledger_currencies", force: :true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
30
|
+
t.string "name"
|
31
|
+
t.string "code"
|
32
|
+
t.string "sym"
|
33
|
+
t.datetime "created_at"
|
34
|
+
t.datetime "updated_at"
|
35
|
+
end
|
36
|
+
|
37
|
+
create_table "ledger_entries", force: :true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
38
|
+
t.string "owner_type"
|
39
|
+
t.integer "owner_id"
|
40
|
+
t.string "code_name"
|
41
|
+
t.datetime "created_at"
|
42
|
+
t.datetime "updated_at"
|
43
|
+
t.index ["owner_type", "owner_id"], name: "index_ledger_entries_on_owner_type_and_owner_id", using: :btree
|
44
|
+
end
|
45
|
+
|
46
|
+
create_table "ledger_moves", force: :true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
47
|
+
t.integer "ledger_entry_id"
|
48
|
+
t.integer "ledger_account_id"
|
49
|
+
t.integer "real_ledger_currency_id"
|
50
|
+
t.integer "represent_ledger_currency_id"
|
51
|
+
t.string "dh", limit: 1
|
52
|
+
t.bigint "real_value", default: 0
|
53
|
+
t.bigint "represent_value", default: 0
|
54
|
+
t.integer "currency_change"
|
55
|
+
t.datetime "datetime"
|
56
|
+
t.datetime "created_at"
|
57
|
+
t.datetime "updated_at"
|
58
|
+
t.index ["ledger_account_id"], name: "index_ledger_moves_on_ledger_account_id", using: :btree
|
59
|
+
t.index ["ledger_entry_id"], name: "index_ledger_moves_on_ledger_entry_id", using: :btree
|
60
|
+
t.index ["real_ledger_currency_id"], name: "index_ledger_moves_on_real_ledger_currency_id", using: :btree
|
61
|
+
t.index ["represent_ledger_currency_id"], name: "index_ledger_moves_on_represent_ledger_currency_id", using: :btree
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
File without changes
|
@@ -0,0 +1,308 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "SnapplerContable operations" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
|
7
|
+
# Capital - Patrimonio Neto
|
8
|
+
capital = LedgerAccount.get('capital')
|
9
|
+
|
10
|
+
# Caja - Disponibilidades - Activo
|
11
|
+
caja = LedgerAccount.get('caja')
|
12
|
+
|
13
|
+
# Banco - Disponibilidades - Activo
|
14
|
+
banco = LedgerAccount.get('banco')
|
15
|
+
|
16
|
+
# Mercaderia - Activo
|
17
|
+
mercaderia = LedgerAccount.get('mercaderia')
|
18
|
+
|
19
|
+
# Muebles - Activo
|
20
|
+
muebles = LedgerAccount.get('muebles')
|
21
|
+
|
22
|
+
# Documentos a pagar - Pasivo
|
23
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
24
|
+
|
25
|
+
|
26
|
+
# PESOS PESOS PESOS
|
27
|
+
#INCREMENTO CAPITAL POR $100.000 --> Caja: $50.000, Mercadería: $20.000, Banco: $30.000
|
28
|
+
SnapplerContable.op([{account: caja, value: 10000}, {account: mercaderia, value: 30000}, {account: banco, value: 70000}, {account: muebles, value: 1000, ledger_currency: 'USD'}],
|
29
|
+
[{account: capital, value: 100000}, {account: documentos_a_pagar, value: 10000}, {account: documentos_a_pagar, value: 1000, ledger_currency: 'USD'}])
|
30
|
+
|
31
|
+
|
32
|
+
# USD USD USD
|
33
|
+
#INCREMENTO CAPITAL POR u$s10.000 --> Banco: u$s10.000
|
34
|
+
SnapplerContable.op([{account: banco, value: 10000, ledger_currency: 'USD'}],
|
35
|
+
[{account: capital, value: 10000, ledger_currency: 'USD'}])
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Inicial Fundation Accounts" do
|
40
|
+
|
41
|
+
# ACTIVO ============================================
|
42
|
+
it "should have 'activo' with 110000.0 ars" do
|
43
|
+
activo = LedgerAccount.get('activo')
|
44
|
+
expect(activo.balance_ars).to be == 110000
|
45
|
+
end
|
46
|
+
it "should have 'activo' with 10000.0 usd" do
|
47
|
+
activo = LedgerAccount.get('activo')
|
48
|
+
expect(activo.balance_usd).to be == 11000
|
49
|
+
end
|
50
|
+
|
51
|
+
# PASIVO ============================================
|
52
|
+
it "should have 'pasivo' with 10000.0 ars" do
|
53
|
+
pasivo = LedgerAccount.get('pasivo')
|
54
|
+
expect(pasivo.balance_ars).to be == 10000
|
55
|
+
end
|
56
|
+
it "should have 'pasivo' with 1000.0 usd" do
|
57
|
+
pasivo = LedgerAccount.get('pasivo')
|
58
|
+
expect(pasivo.balance_usd).to be == 1000
|
59
|
+
end
|
60
|
+
|
61
|
+
# PATRIMONIO NETO ===================================
|
62
|
+
it "should have 'patrimonio_neto' with 100000.0 ars" do
|
63
|
+
patrimonio_neto = LedgerAccount.get('patrimonio_neto')
|
64
|
+
expect(patrimonio_neto.balance_ars).to be == 100000
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
describe "'Activo" do
|
69
|
+
|
70
|
+
# DISPONIBILIDADES ==================================
|
71
|
+
it "should have 'disponibilidades' with 10000.0 usd" do
|
72
|
+
disponibilidades = LedgerAccount.get('disponibilidades')
|
73
|
+
expect(disponibilidades.balance_usd).to be == 10000
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have 'disponibilidades' with 80000.0 ars" do
|
77
|
+
disponibilidades = LedgerAccount.get('disponibilidades')
|
78
|
+
expect(disponibilidades.balance_ars).to be == 80000
|
79
|
+
end
|
80
|
+
|
81
|
+
# MERCADERIA ========================================
|
82
|
+
it "should have 'mercaderia' with 20000.0 ars" do
|
83
|
+
mercaderia = LedgerAccount.get('mercaderia')
|
84
|
+
expect(mercaderia.balance_ars).to be == 30000
|
85
|
+
end
|
86
|
+
|
87
|
+
# MUEBLES ===========================================
|
88
|
+
it "should have 'mercaderia' with 1000.0 ars" do
|
89
|
+
muebles = LedgerAccount.get('muebles')
|
90
|
+
expect(muebles.balance_usd).to be == 1000
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "'Disponibilidades'" do
|
94
|
+
|
95
|
+
# CAJA ==============================================
|
96
|
+
it "should have 'caja' with 50000.0 ars" do
|
97
|
+
caja = LedgerAccount.get('caja')
|
98
|
+
expect(caja.balance_ars).to be == 10000
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# BANCO =============================================
|
103
|
+
it "should have 'banco' with 30000.0 ars" do
|
104
|
+
banco = LedgerAccount.get('banco')
|
105
|
+
expect(banco.balance_ars).to be == 70000
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have 'banco' with 10000.0 usd" do
|
109
|
+
banco = LedgerAccount.get('banco')
|
110
|
+
expect(banco.balance_usd).to be == 10000
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "'Pasivo'" do
|
118
|
+
|
119
|
+
# DOCUMENTOS A PAGAR ==================================
|
120
|
+
it "should have 'documentos_a_pagar' with 10000.0 ars" do
|
121
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
122
|
+
expect(documentos_a_pagar.balance_ars).to be == 10000
|
123
|
+
end
|
124
|
+
it "should have 'documentos_a_pagar' with 1000.0 usd" do
|
125
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
126
|
+
expect(documentos_a_pagar.balance_usd).to be == 1000
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "'Patrimonio Neto'" do
|
132
|
+
# CAPITAL ===========================================
|
133
|
+
it "should have 'capital' with 100000.0 ars" do
|
134
|
+
capital = LedgerAccount.get('capital')
|
135
|
+
expect(capital.balance_ars).to be == 100000
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
describe "'Activo' child account operation in ARS" do
|
144
|
+
|
145
|
+
it "should decrement parent ('disponibilidades') when the account is decremented with a non 'disponibilidades' account" do
|
146
|
+
disponibilidades = LedgerAccount.get('disponibilidades')
|
147
|
+
balance_disponibilidades_ars_before_op = disponibilidades.balance_ars
|
148
|
+
|
149
|
+
mercaderia = LedgerAccount.get('mercaderia')
|
150
|
+
caja = LedgerAccount.get('caja')
|
151
|
+
|
152
|
+
#Decrementa caja por $1.000 -- Aumenta mercaderia por $1.000
|
153
|
+
SnapplerContable.op([{account: mercaderia, value: 1000}],
|
154
|
+
[{account: caja, value: 1000}])
|
155
|
+
|
156
|
+
#Disponibilidades debería haber decrementado por $1.000
|
157
|
+
expect(disponibilidades.balance_ars).to be == balance_disponibilidades_ars_before_op - 1000
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should decrement parent ('activo') when is decremented with a non 'activo' account" do
|
161
|
+
activo = LedgerAccount.get('activo')
|
162
|
+
balance_activo_ars_before_op = activo.balance_ars
|
163
|
+
|
164
|
+
caja = LedgerAccount.get('caja')
|
165
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
166
|
+
|
167
|
+
#Decrementa caja por $1.000 -- Decrementa documentos_a_pagar por $1.000
|
168
|
+
SnapplerContable.op([{account: documentos_a_pagar, value: 1000}],
|
169
|
+
[{account: caja, value: 1000}])
|
170
|
+
|
171
|
+
#Activo debería haber decrementado por $1.000
|
172
|
+
expect(activo.balance_ars).to be == balance_activo_ars_before_op - 1000
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "'Activo' child account operation in USD" do
|
178
|
+
|
179
|
+
it "should decrement parent 'disponibilidades' when is decremented with a non 'disponibilidades' account" do
|
180
|
+
disponibilidades = LedgerAccount.get('disponibilidades')
|
181
|
+
balance_disponibilidades_usd_before_op = disponibilidades.balance_usd
|
182
|
+
|
183
|
+
banco = LedgerAccount.get('banco')
|
184
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
185
|
+
|
186
|
+
#Decrementa banco por u$s1.000 -- Decrementa documentos_a_pagar por u$s1.000
|
187
|
+
SnapplerContable.op([{account: documentos_a_pagar, value: 1000, ledger_currency: 'USD'}],
|
188
|
+
[{account: banco, value: 1000, ledger_currency: 'USD'}])
|
189
|
+
|
190
|
+
#Disponibilidades debería haber decrementado por u$s1.000
|
191
|
+
expect(disponibilidades.balance_usd).to be == balance_disponibilidades_usd_before_op - 1000
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should decrement parent 'activo' when is decremented with a non 'activo' account" do
|
195
|
+
activo = LedgerAccount.get('activo')
|
196
|
+
balance_activo_usd_before_op = activo.balance_usd
|
197
|
+
|
198
|
+
banco = LedgerAccount.get('banco')
|
199
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
200
|
+
|
201
|
+
#Decrementa banco por u$s1.000 -- Decrementa documentos_a_pagar por u$s1.000
|
202
|
+
SnapplerContable.op([{account: documentos_a_pagar, value: 1000, ledger_currency: 'USD'}],
|
203
|
+
[{account: banco, value: 1000, ledger_currency: 'USD'}])
|
204
|
+
|
205
|
+
#Disponibilidades debería haber decrementado por u$s1.000
|
206
|
+
expect(activo.balance_usd).to be == balance_activo_usd_before_op - 1000
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "Movements with more than one currency" do
|
212
|
+
|
213
|
+
describe "Operation between 'Banco ARS' and 'Documentos a pagar USD'" do
|
214
|
+
|
215
|
+
it "should decrement 'Banco ARS' by currency_change*represent_value" do
|
216
|
+
banco = LedgerAccount.get('banco')
|
217
|
+
balance_banco_ars_before_op = banco.balance_ars
|
218
|
+
|
219
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
220
|
+
|
221
|
+
currency_change = 15.2
|
222
|
+
represent_value = 1000
|
223
|
+
|
224
|
+
#Decrementa banco por $15.000 -- Decrementa documentos_a_pagar por u$s1.000 (u$s1 == $15)
|
225
|
+
SnapplerContable.op([{account: documentos_a_pagar, value: currency_change*represent_value, ledger_currency: 'ARS', represent_value: represent_value, represent_ledger_currency: 'USD', currency_change: currency_change}],
|
226
|
+
[{account: banco, value: currency_change*represent_value, ledger_currency: 'ARS'}])
|
227
|
+
|
228
|
+
expect(banco.balance_ars).to be == balance_banco_ars_before_op - (currency_change*represent_value)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should decrement 'Documentos a pagar USD' by represent_value" do
|
232
|
+
banco = LedgerAccount.get('banco')
|
233
|
+
|
234
|
+
documentos_a_pagar = LedgerAccount.get('documentos_a_pagar')
|
235
|
+
balance_documentos_a_pagar_usd_before_op = documentos_a_pagar.balance_usd
|
236
|
+
|
237
|
+
currency_change = 15.2
|
238
|
+
represent_value = 1000
|
239
|
+
|
240
|
+
#Decrementa banco por $15.000 -- Decrementa documentos_a_pagar por u$s1.000 (u$s1 == $15)
|
241
|
+
SnapplerContable.op([{account: documentos_a_pagar, value: currency_change*represent_value, ledger_currency: 'ARS', represent_value: represent_value, represent_ledger_currency: 'USD', currency_change: currency_change}],
|
242
|
+
[{account: banco, value: currency_change*represent_value, ledger_currency: 'ARS'}])
|
243
|
+
|
244
|
+
expect(documentos_a_pagar.balance_usd).to be == balance_documentos_a_pagar_usd_before_op - represent_value
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
describe "Balance between two dates" do
|
253
|
+
|
254
|
+
from = "20/10/2016"
|
255
|
+
to = "20/11/2016"
|
256
|
+
|
257
|
+
it "should return balance between #{from} and #{to}" do
|
258
|
+
caja = LedgerAccount.get('caja')
|
259
|
+
mercaderia = LedgerAccount.get('mercaderia')
|
260
|
+
ventas = LedgerAccount.get('ventas')
|
261
|
+
cmv = LedgerAccount.get('cmv')
|
262
|
+
|
263
|
+
sale_value = 2500
|
264
|
+
|
265
|
+
# Dos ventas el 25/10/2016 por un total de 5000 ###################
|
266
|
+
sales_date = "25/10/2016".to_datetime
|
267
|
+
2.times do
|
268
|
+
SnapplerContable.op([{account: caja, value: sale_value, ledger_currency: 'ARS'}],
|
269
|
+
[{account: ventas, value: sale_value, ledger_currency: 'ARS'}],
|
270
|
+
{ datetime: sales_date })
|
271
|
+
SnapplerContable.op([{account: cmv, value: 1800, ledger_currency: 'ARS'}],
|
272
|
+
[{account: mercaderia, value: 1800, ledger_currency: 'ARS'}],
|
273
|
+
{ datetime: sales_date })
|
274
|
+
end
|
275
|
+
|
276
|
+
# Una venta el 25/11/2016 por un total de 2500 ####################
|
277
|
+
sale_date = "25/11/2016".to_datetime
|
278
|
+
SnapplerContable.op([{account: caja, value: sale_value, ledger_currency: 'ARS'}],
|
279
|
+
[{account: ventas, value: sale_value, ledger_currency: 'ARS'}],
|
280
|
+
{ datetime: sale_date })
|
281
|
+
SnapplerContable.op([{account: cmv, value: 900, ledger_currency: 'ARS'}],
|
282
|
+
[{account: mercaderia, value: 900, ledger_currency: 'ARS'}],
|
283
|
+
{ datetime: sale_date })
|
284
|
+
|
285
|
+
# Balance de ventas entre las 20/10/2016 y 20/11/2016 debe ser de (sale_value*2)
|
286
|
+
|
287
|
+
expect(ventas.balance_ars({from: from, to: to})).to be == sale_value*2
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "SnapplerContable op" do
|
293
|
+
|
294
|
+
it "should raise error when 'DEBE' amount is not equal to 'HABER' amount" do
|
295
|
+
caja = LedgerAccount.get('caja')
|
296
|
+
banco = LedgerAccount.get('banco')
|
297
|
+
expect { SnapplerContable.op([{account: caja, value: 100}], [{account: banco, value: 150}]) }.to raise_error /\ALas sumas del DEBE y HABER son diferentes/
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should raise error when 'DEBE' or 'HABER' array is missing" do
|
301
|
+
caja = LedgerAccount.get('caja')
|
302
|
+
expect { SnapplerContable.op([{account: caja, value: 100}]) }. to raise_error ArgumentError, /\Awrong number of arguments/
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
end
|