comee_core 0.3.50 → 0.3.53

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: ca617ef814088107f21ec7f2a8d541db9a58f2f8d60576aea6ef20370328a820
4
- data.tar.gz: db91bf688f9d5a3479934a0839a3843e927a6b4a2b34e21ce11df5489478af37
3
+ metadata.gz: 04b56b87b13f305eab4e2d8b0747853c6301acba79bb249273fa032bf544f368
4
+ data.tar.gz: 076f1e7b830e3fd60d63107d0dfac8be2ef837e833c3bf188711bce066ce0b98
5
5
  SHA512:
6
- metadata.gz: 60df1dd5ca85c8ae6b27e75d1aa5d3e30327b7366ad925a7c1443bc54e6e017064a88372d599e2d3b300c1cb17f10a8415c20dcbdb9823cb5e423792f2cda8c3
7
- data.tar.gz: 8e696cdba2b0ead77fc9ecbb74c3bd1acf118b0221eee54cb047adbb4f272fbef6708857e8268c5dd5b83d1b501c3f5873bb8f3a5607f7efa90f24f69841a01c
6
+ metadata.gz: c54cc734056203efc08a6a9fc1eada602cf6afc8738022728ee695054b68f705ac883c9192e66e4bfcdb2c3d447df7b0fe4381350f731d7779677cbe0b9f0505
7
+ data.tar.gz: 10fa973af666aaed4ad2980d619773e227f7a895a01fc0b5a5c9f62baea28cfbb49ebed5152ce61968a566515af4ff37713e27b13ce4faeb438b891041cfddbf
@@ -104,6 +104,7 @@ module Comee
104
104
  voyage_no
105
105
  status
106
106
  payment_status
107
+ created_at
107
108
  ]
108
109
  end
109
110
 
@@ -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
- items = PurchaseOrderItem.where(purchase_order_id: id)
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
- items = PurchaseOrderItem.where(purchase_order_id: id)
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
- items = PurchaseOrderItem.where(purchase_order_id: id)
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
- confirmed_total_price = items.sum(&:confirmed_total_price)
44
- self.confirmed_vat = (confirmed_total_price * 0.19).round(2)
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)
@@ -1,7 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class PurchaseOrderItemSerializer < ActiveModel::Serializer
4
- attributes :id, :serial_no, :quantity, :confirmed_quantity, :price, :details, :remark
4
+ attributes :id, :serial_no, :purchase_order_id, :unit_id, :quantity, :confirmed_quantity, :price, :confirmed_price,
5
+ :total_price, :delivery_date, :confirmed_total_price, :confirmed_delivery_date, :status, :details, :remark
5
6
 
6
7
  belongs_to :purchase_order
7
8
  end
@@ -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
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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.50".freeze
3
+ VERSION = "0.3.53".freeze
4
4
  end
5
5
  end
@@ -8,5 +8,7 @@ FactoryBot.define do
8
8
  delivery_address { "Korsu warehouse address" }
9
9
  delivery_date { Date.current.advance(days: 10) }
10
10
  terms { Faker::Lorem.sentence }
11
+ discount { 0 }
12
+ confirmed_discount { 0 }
11
13
  end
12
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.50
4
+ version: 0.3.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.