comee_core 0.3.41 → 0.3.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/comee/core/invoice.rb +37 -2
- data/app/models/comee/core/shipment_instruction_item.rb +11 -0
- data/app/serializers/comee/core/shipment_instruction_item_serializer.rb +1 -1
- data/db/migrate/20240803231700_update_invoice_fields.rb +7 -0
- data/db/migrate/20240805085256_add_details_to_shipment_instruction_item.rb +5 -0
- data/db/migrate/20240805093326_update_details_column_in_shipment_instruction_items.rb +14 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/invoices.rb +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff7350423a4f7d4bfbab481f69a78c1526754c515c6f58ccfd31f5e77b4eb60
|
4
|
+
data.tar.gz: 15b0575c52dcc8994efdba583b2455fa2375f1b87612e5fab71c765bdfe0f376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85e67b19d45298a5da7fce3a0337516242fb073b05255836b313d9bacad96909b72582485b91f57d471de60e7756952cc025f22a95b77b599954215b185c08dc
|
7
|
+
data.tar.gz: a7b7c841130e5760d30b44ee997f4a275e1e28504cc84733b9c4fa228b2c905705e820fda9785c50ff67f99c88044026ecb68d9dcb5a61d93d66e91b1e858f15
|
@@ -1,11 +1,17 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class Invoice < ApplicationRecord
|
4
|
+
ADVANCE = "Advance".freeze
|
5
|
+
DELIVERY = "Delivery".freeze
|
6
|
+
DIRECT = "Direct".freeze
|
7
|
+
|
8
|
+
INVOICE_TYPES = [ADVANCE, DELIVERY, DIRECT].freeze
|
9
|
+
|
4
10
|
before_validation :generate_invoice_no, if: proc { |inv| inv.invoice_no.nil? }
|
5
11
|
before_save :calculate_due_date, unless: proc { |inv| inv.date_issued.nil? }
|
6
12
|
|
7
13
|
belongs_to :sales_order
|
8
|
-
belongs_to :pod
|
14
|
+
belongs_to :pod, optional: true
|
9
15
|
belongs_to :invoice_address,
|
10
16
|
-> { where(address_type: ClientAddress::INVOICING_ADDRESS) },
|
11
17
|
class_name: "Comee::Core::ClientAddress"
|
@@ -23,9 +29,35 @@ module Comee
|
|
23
29
|
validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
|
24
30
|
validates :amount_paid, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
|
25
31
|
|
32
|
+
validates :pct_advanced,
|
33
|
+
presence: true,
|
34
|
+
numericality: {greater_than: 0, less_than_or_equal_to: 100},
|
35
|
+
if: -> { advance? }
|
36
|
+
validates :pct_advanced,
|
37
|
+
absence: true,
|
38
|
+
if: -> { delivery? || direct? }
|
39
|
+
validates :pod_id,
|
40
|
+
presence: true,
|
41
|
+
if: -> { delivery? }
|
42
|
+
validates :pod_id,
|
43
|
+
absence: true,
|
44
|
+
if: -> { advance? }
|
45
|
+
|
26
46
|
delegate(:order_number, to: :sales_order, prefix: false)
|
27
47
|
delegate(:reference_no, to: :pod, prefix: true)
|
28
48
|
|
49
|
+
def delivery?
|
50
|
+
invoice_type == DELIVERY
|
51
|
+
end
|
52
|
+
|
53
|
+
def advance?
|
54
|
+
invoice_type == ADVANCE
|
55
|
+
end
|
56
|
+
|
57
|
+
def direct?
|
58
|
+
invoice_type == DIRECT
|
59
|
+
end
|
60
|
+
|
29
61
|
def calculate_total_price
|
30
62
|
self.total_price = calculate_total
|
31
63
|
end
|
@@ -43,7 +75,9 @@ module Comee
|
|
43
75
|
def calculate_total
|
44
76
|
items = InvoiceItem.where(invoice_id: id)
|
45
77
|
additionals = AdditionalItem.where(invoice_id: id)
|
46
|
-
(items.sum(:total_price) + additionals.sum(:total_price))
|
78
|
+
total = (items.sum(:total_price) + additionals.sum(:total_price))
|
79
|
+
total *= (pct_advanced / 100) if advance?
|
80
|
+
total.round(2)
|
47
81
|
end
|
48
82
|
|
49
83
|
def calculate_amount_paid
|
@@ -56,6 +90,7 @@ module Comee
|
|
56
90
|
id
|
57
91
|
sales_order_id
|
58
92
|
invoice_no
|
93
|
+
invoice_type
|
59
94
|
date_issued
|
60
95
|
ship_name
|
61
96
|
delivery_date
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class ShipmentInstructionItem < ApplicationRecord
|
4
|
+
before_save :set_details, if: proc { |item| item.details.empty? }
|
5
|
+
|
4
6
|
belongs_to :shipment_instruction
|
5
7
|
belongs_to :shipment_item
|
6
8
|
belongs_to :unit
|
@@ -9,6 +11,15 @@ module Comee
|
|
9
11
|
|
10
12
|
validates :pallet_no, presence: true
|
11
13
|
validates :length, :width, :height, :weight, :quantity, :price, presence: true, numericality: {greater_than: 0}
|
14
|
+
|
15
|
+
def set_details
|
16
|
+
self.details = {
|
17
|
+
customer_item_no: shipment_item.sales_order_item.customer_item_no,
|
18
|
+
customer_item_description: shipment_item.sales_order_item.customer_item_description,
|
19
|
+
customer_item_alias: shipment_item.sales_order_item.customer_item_alias,
|
20
|
+
use_alias: shipment_item.sales_order_item.use_alias
|
21
|
+
}
|
22
|
+
end
|
12
23
|
end
|
13
24
|
end
|
14
25
|
end
|
@@ -2,7 +2,7 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class ShipmentInstructionItemSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :delivery_note_no, :pallet_no, :goods_issue_date, :length, :width, :height, :weight, :quantity, :price,
|
5
|
-
:pod_id
|
5
|
+
:pod_id, :details
|
6
6
|
belongs_to :unit
|
7
7
|
belongs_to :shipment_item
|
8
8
|
belongs_to :pod
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class UpdateInvoiceFields < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
change_column_null :comee_core_invoices, :pod_id, true
|
4
|
+
add_column :comee_core_invoices, :invoice_type, :string, default: "Delivery"
|
5
|
+
add_column :comee_core_invoices, :pct_advanced, :float, null: true
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class UpdateDetailsColumnInShipmentInstructionItems < ActiveRecord::Migration[7.1]
|
2
|
+
def up
|
3
|
+
Comee::Core::ShipmentInstructionItem.reset_column_information
|
4
|
+
Comee::Core::ShipmentInstructionItem.find_each do |item|
|
5
|
+
details = {
|
6
|
+
customer_item_no: item.shipment_item.sales_order_item.customer_item_no,
|
7
|
+
customer_item_description: item.shipment_item.sales_order_item.customer_item_description,
|
8
|
+
customer_item_alias: item.shipment_item.sales_order_item.customer_item_alias,
|
9
|
+
use_alias: item.shipment_item.sales_order_item.use_alias
|
10
|
+
}
|
11
|
+
item.update_column(:details, details)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/comee/core/version.rb
CHANGED
@@ -2,12 +2,14 @@ FactoryBot.define do
|
|
2
2
|
factory :invoice, class: "Comee::Core::Invoice" do
|
3
3
|
invoice_no { nil }
|
4
4
|
sales_order
|
5
|
+
invoice_type { Comee::Core::Invoice::DELIVERY }
|
5
6
|
pod
|
6
7
|
date_issued { Date.current }
|
7
8
|
due_date { Date.current.advance(days: 10) }
|
8
9
|
total_price { 0 }
|
9
10
|
amount_paid { 0 }
|
10
11
|
payment_term { Faker::Lorem.sentence }
|
12
|
+
pct_advanced { nil }
|
11
13
|
notifications_sent { 0 }
|
12
14
|
status { Comee::Core::Invoice.statuses[:draft] }
|
13
15
|
payment_status { Comee::Core::Invoice.payment_statuses[:not_paid] }
|
@@ -20,5 +22,16 @@ FactoryBot.define do
|
|
20
22
|
trait :issued do
|
21
23
|
status { Comee::Core::Invoice.statuses[:issued] }
|
22
24
|
end
|
25
|
+
|
26
|
+
trait :advance do
|
27
|
+
invoice_type { Comee::Core::Invoice::ADVANCE }
|
28
|
+
pod { nil }
|
29
|
+
pct_advanced { 25 }
|
30
|
+
end
|
31
|
+
|
32
|
+
trait :direct do
|
33
|
+
invoice_type { Comee::Core::Invoice::DIRECT }
|
34
|
+
pct_advanced { nil }
|
35
|
+
end
|
23
36
|
end
|
24
37
|
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.3.
|
4
|
+
version: 0.3.43
|
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-
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -535,6 +535,9 @@ files:
|
|
535
535
|
- db/migrate/20240731080746_create_comee_core_credit_note_items.rb
|
536
536
|
- db/migrate/20240731081502_create_comee_core_credit_note_additional_items.rb
|
537
537
|
- db/migrate/20240803194006_change_reference_in_invoice_to_polymorphic.rb
|
538
|
+
- db/migrate/20240803231700_update_invoice_fields.rb
|
539
|
+
- db/migrate/20240805085256_add_details_to_shipment_instruction_item.rb
|
540
|
+
- db/migrate/20240805093326_update_details_column_in_shipment_instruction_items.rb
|
538
541
|
- lib/comee/core.rb
|
539
542
|
- lib/comee/core/engine.rb
|
540
543
|
- lib/comee/core/version.rb
|