comee_core 0.3.44 → 0.3.46

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: 90b9fd38243f244ee92d50b0f697840aa98dca81e68255ec87553f711436d462
4
- data.tar.gz: 8301b49b91fadb81b7b47136ca8293e8427768952a0e2ffca87cab96f8bb8ecf
3
+ metadata.gz: ba758dcd6e3e198f9bce176c3068a6c551b3268be25f8d02f6f07dfae89d2338
4
+ data.tar.gz: c52bebae8f6f5ba36544242c6988a796fd84909fbadc568f669926e11dbd944a
5
5
  SHA512:
6
- metadata.gz: aeb36d887f7074afc497dc4a8e1e5567a008d35aba4046aea6b9de14beee1771786221aec51ea4045dd927c7719cf7fccbbed8768932a9c2fd5f5888feb4437d
7
- data.tar.gz: 1d39c2bc2298531800e5183aa745ddbaf959f92e00a2a223e2d9b770e114b31adca2e9bb40b1f0649f180de68d31cecb906608b6a36768e7dcbdb8ed26e552e6
6
+ metadata.gz: 3bbce625a264c90c8fedafdb4a7fd6528ff89e3a63b78a0321a7d0ef53e77227142bb6a50f03b7357ceddfd0eead9e3736ae364f672e28313e63b57ab719d935
7
+ data.tar.gz: 16eaadf9d4e751ed618e9eca798593d70c8474b16caf36cfd3972b8dfe70abdc1366cc2af458c59e8a775c5073e74a65ccdcb24482b9ca6ecc5f826bc1b31c29
@@ -2,6 +2,7 @@ module Comee
2
2
  module Core
3
3
  class CreditNote < ApplicationRecord
4
4
  before_validation :generate_credit_note_no, if: proc { |note| note.credit_note_no.nil? }
5
+ after_save :update_amount_credited, if: proc { |note| note.approved? }
5
6
 
6
7
  belongs_to :invoice
7
8
  has_many :credit_note_items
@@ -29,6 +30,11 @@ module Comee
29
30
  self.credit_note_no = Util.generate_number("CreditNote", "credit_note_no", year, "-", 100001)
30
31
  end
31
32
 
33
+ def update_amount_credited
34
+ invoice.amount_credited = invoice.calculate_amount_credited
35
+ invoice.save!
36
+ end
37
+
32
38
  def validate_total_price
33
39
  return unless total_price && invoice
34
40
 
@@ -28,6 +28,7 @@ module Comee
28
28
  validates :status, :payment_status, presence: true
29
29
  validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
30
30
  validates :amount_paid, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
31
+ validates :amount_credited, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
31
32
 
32
33
  validates :pct_advanced,
33
34
  presence: true,
@@ -85,6 +86,12 @@ module Comee
85
86
  payments.sum(:amount)
86
87
  end
87
88
 
89
+ def calculate_amount_credited
90
+ credited = CreditNote.where(invoice_id: id, status: CreditNote.statuses[:approved])
91
+ total = credited.sum(:total_price) + credited.sum(:vat)
92
+ total.round(2)
93
+ end
94
+
88
95
  def self.ransackable_attributes(_auth_object = nil)
89
96
  %w[
90
97
  id
@@ -71,7 +71,10 @@ module Comee
71
71
 
72
72
  return nil if period1 > period2 || period1.contains?(period2)
73
73
 
74
- Period.new(period1.finish.advance(days: 1), period2.finish)
74
+ period = Period.new(period1.finish.advance(days: 1), period2.finish)
75
+ return nil unless period.valid?
76
+
77
+ period
75
78
  end
76
79
  end
77
80
  end
@@ -0,0 +1,5 @@
1
+ class AddAmountCreditedToInvoice < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :comee_core_invoices, :amount_credited, :float, default: 0
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.44".freeze
3
+ VERSION = "0.3.46".freeze
4
4
  end
5
5
  end
@@ -8,6 +8,7 @@ FactoryBot.define do
8
8
  due_date { Date.current.advance(days: 10) }
9
9
  total_price { 0 }
10
10
  amount_paid { 0 }
11
+ amount_credited { 0 }
11
12
  payment_term { Faker::Lorem.sentence }
12
13
  pct_advanced { nil }
13
14
  notifications_sent { 0 }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.44
4
+ version: 0.3.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -538,6 +538,7 @@ files:
538
538
  - db/migrate/20240803231700_update_invoice_fields.rb
539
539
  - db/migrate/20240805085256_add_details_to_shipment_instruction_item.rb
540
540
  - db/migrate/20240805093326_update_details_column_in_shipment_instruction_items.rb
541
+ - db/migrate/20240807050230_add_amount_credited_to_invoice.rb
541
542
  - lib/comee/core.rb
542
543
  - lib/comee/core/engine.rb
543
544
  - lib/comee/core/version.rb