dolar-bna 1.2.4.1 → 1.2.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92664086c5f075c10681663cb8161c86501cea446de236e0cab2a42b6a726acc
4
- data.tar.gz: a32d122827292a9f0e4159be824a74ca97c9c0a6417fdaf7bc2b2a4697efd259
3
+ metadata.gz: 9b2967be9be678555da83cae839848b941e967b15cec9999e8cc594186fc035a
4
+ data.tar.gz: 55c0a03df7284b7f2179d76fc4f27a04274a5250ee5e329f4a59806126e1051e
5
5
  SHA512:
6
- metadata.gz: 5e50923ac237f37e72175393a92993b4e8259ccc2d2b063b49dc29b5b488ec4c58c5bf2d78af65b66981f280741915e109234bbf2e2238688010141c52d65591
7
- data.tar.gz: 4b0341143e32856b5b5bbbcd9ca54f2dbd5860f28535ec00c7caeed4f7cf8725a6d3a09b320b22b8921a211f283b01810010bc035781964b6e0c7b57d0c74072
6
+ metadata.gz: ac383946adf1a573f3764088dda0347f0eb742aaafcf38d8613418129abdb0dbeb9c18cd23ac387cb67cde61cdbab733b35ac402990ff7363cf0ad1ca34b1a41
7
+ data.tar.gz: 10cbbc2c1fed12b0fc2af7ec2d52a06aa4cecb806b59447e838f51f9a5b2c232f4c8fb7954cb1f8e024abcd7b6f800c0b4f58e1192c82e93a6eea07149f880f6
@@ -9,10 +9,12 @@ module Dolar
9
9
  validates_numericality_of :dolar_buy, greater_than: 0, message: 'La cotizacion debe ser mayor a 0'
10
10
  validates_numericality_of :dolar_sell, greater_than: 0, message: 'La cotizacion debe ser mayor a 0'
11
11
  #validates_uniqueness_of :date, scope: [:dolar_type, :dolar_sell], if: :message: 'Ya existe una cotización de ese tipo para la fecha ingresada'
12
- DOLAR_TYPES = ["Divisa", "Billete", "Blue", "MEP", "CCL", "Tarjeta"]
12
+ DOLAR_TYPES = ["Divisa", "Billete", "Blue", "MEP", "CCL", "Tarjeta", "Agro"]
13
13
 
14
14
  validates_inclusion_of :dolar_type, in: DOLAR_TYPES, message: 'Tipo de cotización inválido'
15
15
 
16
+ after_save :set_dolar_agro, if: :dolar_agro_changer?
17
+
16
18
  def self.search_by_date_range search
17
19
  unless search.blank?
18
20
  # La fecha la pasa un daterangepicker que la envia en este formato '01/01/2023 - 31/12/2023'
@@ -39,7 +41,18 @@ module Dolar
39
41
  end
40
42
  end
41
43
 
42
- end
44
+ def dolar_agro_changer?
45
+ dolar_type == 'MEP' || dolar_type == 'Divisa'
46
+ end
43
47
 
48
+ def set_dolar_agro
49
+ divisa_value = Dolar::Bna::DolarCotization.where(dolar_type: dolar_type == 'MEP' ? 'Divisa' : 'MEP', date: self.date).order(date: :asc, created_at: :asc).last
50
+ if divisa_value
51
+ dolar_buy_average = ((self.dolar_buy.to_f * 0.2) + (divisa_value.dolar_buy.to_f * 0.8)).round(2)
52
+ dolar_sell_average = ((self.dolar_sell.to_f * 0.2) + (divisa_value.dolar_sell.to_f * 0.8)).round(2)
53
+ Dolar::Bna::DolarCotization.create(dolar_type: 'Agro', dolar_buy: dolar_buy_average, dolar_sell: dolar_sell_average, date: self.date)
54
+ end
55
+ end
56
+ end
44
57
  end
45
58
  end
@@ -1,5 +1,5 @@
1
1
  module Dolar
2
2
  module Bna
3
- VERSION = "1.2.4.1"
3
+ VERSION = "1.2.5.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolar-bna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4.1
4
+ version: 1.2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LITECODE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2024-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot