comee_core 0.3.51 → 0.3.53
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 +4 -4
- data/app/models/comee/core/invoice.rb +1 -0
- data/app/models/comee/core/purchase_order.rb +19 -9
- data/app/serializers/comee/core/purchase_order_serializer.rb +2 -1
- data/db/migrate/20240815080137_add_confirmed_field_values_to_purchase_order.rb +2 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/purchase_orders.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b56b87b13f305eab4e2d8b0747853c6301acba79bb249273fa032bf544f368
|
4
|
+
data.tar.gz: 076f1e7b830e3fd60d63107d0dfac8be2ef837e833c3bf188711bce066ce0b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c54cc734056203efc08a6a9fc1eada602cf6afc8738022728ee695054b68f705ac883c9192e66e4bfcdb2c3d447df7b0fe4381350f731d7779677cbe0b9f0505
|
7
|
+
data.tar.gz: 10fa973af666aaed4ad2980d619773e227f7a895a01fc0b5a5c9f62baea28cfbb49ebed5152ce61968a566515af4ff37713e27b13ce4faeb438b891041cfddbf
|
@@ -9,6 +9,8 @@ module Comee
|
|
9
9
|
|
10
10
|
validates :po_number, uniqueness: true
|
11
11
|
validates :order_date, :delivery_address, :status, :delivery_date, presence: true
|
12
|
+
validates :discount, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: true}
|
13
|
+
validates :confirmed_discount, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: true}
|
12
14
|
enum status: {
|
13
15
|
draft: 0,
|
14
16
|
submitted: 1,
|
@@ -19,29 +21,37 @@ module Comee
|
|
19
21
|
}
|
20
22
|
|
21
23
|
def calculate_total_price
|
22
|
-
|
23
|
-
self.total_price = items.sum(&:total_price).round(2)
|
24
|
+
self.total_price = calculate_total
|
24
25
|
end
|
25
26
|
|
26
27
|
def calculate_confirmed_total_price
|
27
|
-
|
28
|
-
self.confirmed_total_price = items.sum(&:confirmed_total_price).round(2)
|
28
|
+
self.confirmed_total_price = calculate_confirmed_total
|
29
29
|
end
|
30
30
|
|
31
31
|
def calculate_vat
|
32
32
|
return unless supplier.tax_code == "Inland"
|
33
33
|
|
34
|
-
|
35
|
-
total_price = items.sum(&:total_price)
|
36
|
-
self.vat = (total_price * 0.19).round(2)
|
34
|
+
self.vat = (calculate_total * 0.19).round(2)
|
37
35
|
end
|
38
36
|
|
39
37
|
def calculate_confirmed_vat
|
40
38
|
return unless supplier.tax_code == "Inland"
|
41
39
|
|
40
|
+
self.confirmed_vat = (calculate_confirmed_total * 0.19).round(2)
|
41
|
+
end
|
42
|
+
|
43
|
+
def calculate_total
|
44
|
+
items = PurchaseOrderItem.where(purchase_order_id: id)
|
45
|
+
total = items.sum(&:total_price).round(2)
|
46
|
+
total = (total * (1 - discount / 100.0)).round(2) if discount&.positive?
|
47
|
+
total
|
48
|
+
end
|
49
|
+
|
50
|
+
def calculate_confirmed_total
|
42
51
|
items = PurchaseOrderItem.where(purchase_order_id: id)
|
43
|
-
|
44
|
-
|
52
|
+
confirmed_total = items.sum(&:confirmed_total_price).round(2)
|
53
|
+
confirmed_total = (confirmed_total * (1 - confirmed_discount / 100.0)).round(2) if confirmed_discount&.positive?
|
54
|
+
confirmed_total
|
45
55
|
end
|
46
56
|
|
47
57
|
def self.ransackable_attributes(_auth_object = nil)
|
@@ -2,7 +2,8 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class PurchaseOrderSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :po_number, :supplier_id, :order_date, :status, :delivery_address, :delivery_date, :terms, :total_price,
|
5
|
-
:vat, :order_reference, :created_at, :updated_at, :confirmed_total_price, :confirmed_vat
|
5
|
+
:vat, :order_reference, :created_at, :updated_at, :confirmed_total_price, :confirmed_vat, :discount,
|
6
|
+
:confirmed_discount
|
6
7
|
belongs_to :supplier
|
7
8
|
end
|
8
9
|
end
|
@@ -2,5 +2,7 @@ class AddConfirmedFieldValuesToPurchaseOrder < ActiveRecord::Migration[7.1]
|
|
2
2
|
def change
|
3
3
|
add_column :comee_core_purchase_orders, :confirmed_total_price, :float, default: 0
|
4
4
|
add_column :comee_core_purchase_orders, :confirmed_vat, :float, default: 0
|
5
|
+
add_column :comee_core_purchase_orders, :discount, :float, default: 0
|
6
|
+
add_column :comee_core_purchase_orders, :confirmed_discount, :float, default: 0
|
5
7
|
end
|
6
8
|
end
|
data/lib/comee/core/version.rb
CHANGED