comee_core 0.2.24 → 0.2.26

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0808a830ec2c6e06def05ff3e9cefce6723564ea3f0e66c41076e2f87dbf689f'
4
- data.tar.gz: 8a7effb277abed7b985e574315d81dbb3ba45d528e91d4fd3d8fc7a6fba1e94e
3
+ metadata.gz: 8cab65061584474d2bff1d09b4615f74c6755284c5870b624fa06407660f9816
4
+ data.tar.gz: 9572b9050b8d0d0df0116c57e70f0804244592c0ea3b88d8cbc2185390c6a164
5
5
  SHA512:
6
- metadata.gz: 9c0443e3fe4a09e0da5744254449606a0788dfe971424221c2e7b0a773a3da589523b9ccfb24ee00d877316a51cf5a41030a07478965bc679f4af5d452eb2b37
7
- data.tar.gz: 3b1f0680b99e0228494eca14c604484b510955242795dce718e98dec3d21a2a221e6886925df3a33c56f8c49defa50bc34dcf9ec58bde8fa730385403ab6f297
6
+ metadata.gz: 16fa96b65ac32cbcad028f5cc489c3f607507bfe9fdeee2c036bc824dac5df46e8b6754d058439f8e510a9e56545a5cad63f54ac65ccbb063b691c49cecefd70
7
+ data.tar.gz: 1a041a308a441889bb5360f36b36fa6991d47032bea60960f19b26320511b0c17f73daa8a091ffd0df3b55a26081d3aed3cc3232d9bc035b1227a03e9062b6e6
@@ -46,6 +46,7 @@ module Comee
46
46
  if incoming.instance_of?(Array)
47
47
  data, options = incoming
48
48
  elsif incoming.instance_of?(Hash)
49
+ data = @obj
49
50
  options = incoming
50
51
  else
51
52
  data = incoming
@@ -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)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.24".freeze
3
+ VERSION = "0.2.26".freeze
4
4
  end
5
5
  end
@@ -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.24
4
+ version: 0.2.26
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-24 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers