comee_core 0.2.25 → 0.2.27

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: 1349e288ad5c494bb02eacc26f9ae41d34803dba3691efd4ee17fc9f205d270e
4
- data.tar.gz: 8058d4750f90ebe16eb96aa9116ec18373008988c573e5224fca9a3799e78c70
3
+ metadata.gz: 554e23beac0f968e8aa1572e65e59a91bcec42638cf9eaab1745ecaff39dfd05
4
+ data.tar.gz: 25fc62b8e0ed99fcef2234904bb81dc98a1b871d8edfd272967de6e2847d7027
5
5
  SHA512:
6
- metadata.gz: 16502279c6b4150241e2fcb5efaf2c3f60f6ee8ffa3103c8621b35905eecb1d72269db19a1d02d97bbfab56d9d1f91974fd662745f69bf40a4c7122290282c91
7
- data.tar.gz: 36b57583bcc494a3a0c404336cf87259508fed69ad749646333ef8c5b53c084a3f9cd3163fce940436a567879880c04e69f23dc6b9899ffb9202de9f29582261
6
+ metadata.gz: c0a23a96da3cbb4b7fe77668e5bcec37b62530a82f1a93cebb82d0fc12d3725b4b8bd01e1dd3460ec6e3caef3dbedf3b1de58d5785a2ae9c19cb3f93c2325b38
7
+ data.tar.gz: 2e443a00fbed3aea1f5bd1f7327dc7e21f79ed697e62c07a8892a63de50a0c5bdd17c2a947cb6c28ae0a63e4c7a5b492f24e6e68ffe54afc998e1a64a892e8e8
@@ -15,6 +15,7 @@ module Comee
15
15
  validates :invoice_no, presence: true, uniqueness: true
16
16
  validates :status, :payment_status, presence: true
17
17
  validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
18
+ validates :amount_paid, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
18
19
 
19
20
  delegate(:order_number, to: :sales_order, prefix: false)
20
21
  delegate(:reference_no, to: :pod, prefix: true)
@@ -2,6 +2,7 @@ module Comee
2
2
  module Core
3
3
  class InvoiceItem < ApplicationRecord
4
4
  before_save { self.total_price = unit_price * quantity }
5
+ after_save :update_invoice_price
5
6
 
6
7
  belongs_to :shipment_instruction_item
7
8
  belongs_to :invoice
@@ -9,6 +10,11 @@ module Comee
9
10
 
10
11
  validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0}
11
12
  validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
13
+
14
+ def update_invoice_price
15
+ invoice.total_price = invoice.invoice_items.sum(:total_price)
16
+ invoice.save!
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -5,6 +5,7 @@ module Comee
5
5
  belongs_to :payment_deposit
6
6
 
7
7
  validates :amount, presence: true, numericality: {greater_than: 0}
8
+ validate :validate_amount
8
9
 
9
10
  def self.ransackable_attributes(_auth_object = nil)
10
11
  %w[id created_at updated_at]
@@ -13,6 +14,16 @@ module Comee
13
14
  def self.ransackable_associations(_auth_object = nil)
14
15
  %w[payment_deposit invoice]
15
16
  end
17
+
18
+ def validate_amount
19
+ return unless amount && payment_deposit
20
+
21
+ running_total = payment_deposit.payments.sum(:amount)
22
+ running_total -= amount_was if id
23
+ remaining = payment_deposit.amount - running_total
24
+ error = "Amount exceeded. The maximum amount you can set is #{remaining}"
25
+ errors.add(:base, error) if amount > remaining
26
+ end
16
27
  end
17
28
  end
18
29
  end
@@ -5,11 +5,12 @@ module Comee
5
5
  belongs_to :currency
6
6
  has_many :payments
7
7
 
8
- validates :reference_no, :date_issued, presence: true
8
+ enum :status, {pending: 0, processed: 1}
9
+ validates :reference_no, :date_issued, :status, presence: true
9
10
  validates :amount, presence: true, numericality: {greater_than: 0}
10
11
 
11
12
  def self.ransackable_attributes(_auth_object = nil)
12
- %w[id reference_no bank_reference date_issued]
13
+ %w[id reference_no bank_reference date_issued status]
13
14
  end
14
15
 
15
16
  def self.ransackable_associations(_auth_object = nil)
@@ -2,11 +2,15 @@ module Comee
2
2
  module Core
3
3
  class TokenService
4
4
  def self.issue(payload)
5
- JWT.encode(payload, ENV["SECRET_KEY"], "HS256")
5
+ JWT.encode(payload, key, "HS256")
6
6
  end
7
7
 
8
8
  def self.decode(token)
9
- JWT.decode(token, ENV["SECRET_KEY"], true, algorithm: "HS256").first
9
+ JWT.decode(token, key, true, algorithm: "HS256").first
10
+ end
11
+
12
+ def self.key
13
+ ENV["SECRET_KEY"] || Rails.application.credentials.secret_key_base
10
14
  end
11
15
  end
12
16
  end
@@ -13,6 +13,7 @@ class CreateComeeCorePaymentDeposits < ActiveRecord::Migration[7.1]
13
13
  foreign_key: {to_table: :comee_core_currencies}
14
14
  t.date :date_issued, null: false
15
15
  t.float :amount, null: false
16
+ t.integer :status, null: false, default: 0
16
17
 
17
18
  t.timestamps
18
19
  end
@@ -0,0 +1,5 @@
1
+ class AddAmountPaidFieldToInvoice < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :comee_core_invoices, :amount_paid, :integer, default: 0
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.25".freeze
3
+ VERSION = "0.2.27".freeze
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  date_issued { Date.current }
7
7
  due_date { Date.current.advance(days: 10) }
8
8
  total_price { 0 }
9
+ amount_paid { 0 }
9
10
  payment_term { Faker::Lorem.sentence }
10
11
  notifications_sent { 0 }
11
12
  status { Comee::Core::Invoice.statuses[:draft] }
@@ -5,6 +5,7 @@ FactoryBot.define do
5
5
  bank_reference { Faker::Alphanumeric.alpha(number: 10) }
6
6
  currency
7
7
  date_issued { Date.current }
8
- amount { 100.5 }
8
+ amount { 100 }
9
+ status { Comee::Core::PaymentDeposit.statuses[:pending] }
9
10
  end
10
11
  end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :payment, class: "Comee::Core::Payment" do
3
3
  payment_deposit
4
4
  invoice
5
- amount { 100 }
5
+ amount { 30 }
6
6
  remark { Faker::Lorem.sentence }
7
7
  end
8
8
  end
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.2.25
4
+ version: 0.2.27
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-02-28 00:00:00.000000000 Z
11
+ date: 2024-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -437,6 +437,7 @@ files:
437
437
  - db/migrate/20240124161320_create_comee_core_additional_items.rb
438
438
  - db/migrate/20240125003634_create_comee_core_payment_deposits.rb
439
439
  - db/migrate/20240125044630_create_comee_core_payments.rb
440
+ - db/migrate/20240303191625_add_amount_paid_field_to_invoice.rb
440
441
  - lib/comee/core.rb
441
442
  - lib/comee/core/engine.rb
442
443
  - lib/comee/core/version.rb