comee_core 0.3.16 → 0.3.17

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: b3fd565d7b087866c90b6e231dbf65f6bf1e36b4c951290541c083cc0ec0b26b
4
- data.tar.gz: 9eb535c0bc7026c7b411593eeb2a41d98f4ff82cdeb59dd343bf41fee3d0b302
3
+ metadata.gz: 31d273c0f307b780445d84f77724d21676a90ecb97923b6e57452f011a31ede1
4
+ data.tar.gz: 8e5b700c41f8dcd22bccf746756bfdcc6669a1774622cf9f4dd03c1383a7b6a4
5
5
  SHA512:
6
- metadata.gz: bd271add8709246848ba0b1d469596f4cedd58bd041f94ac83f174ffa88243d8420257471cdb5c137cb2c60ba7e2887d052cd30dd8aa637bebfbd24b92377038
7
- data.tar.gz: b0b8e23964ecf2dd275cb9b8d71302f11783703d33be52efceb5c6193bece0cefaf58c91ec0929dfe2ded532cde2857d15aafb1ca3a863d0e43885774c0091a6
6
+ metadata.gz: d8b7269868908faea7b9fce4be61b9a9d0302a29854d29ea37948afd9c0a6ba77949aa5e241bb24ad63cd7b50faad5c2650d57d7311272c131c609511f4c0169
7
+ data.tar.gz: a11db8aeef2a636b16b5723c41bd8385107cf8554ddb87ddc98f1173d36fa2611619cce558194059d30e225f38b5596c704fc2f5abb5c6f5a934bdfe6c87a804
@@ -2,14 +2,16 @@ module Comee
2
2
  module Core
3
3
  class AdditionalItem < ApplicationRecord
4
4
  before_save { self.total_price = unit_price * quantity }
5
- after_save { invoice.update_total_price }
5
+ after_save :update_invoice
6
+ after_destroy :update_invoice
6
7
  belongs_to :invoice
7
8
 
8
9
  validates :description, presence: true
9
10
  validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0}
10
11
 
11
- def update_invoice_price
12
- invoice.total_price = invoice.invoice_items.sum(:total_price) + invoice.additional_items.sum(:total_price)
12
+ def update_invoice
13
+ invoice.calculate_total_price
14
+ invoice.calculate_vat
13
15
  invoice.save!
14
16
  end
15
17
  end
@@ -22,9 +22,20 @@ module Comee
22
22
  delegate(:order_number, to: :sales_order, prefix: false)
23
23
  delegate(:reference_no, to: :pod, prefix: true)
24
24
 
25
- def update_total_price
26
- self.total_price = invoice_items.sum(:total_price) + additional_items.sum(:total_price)
27
- save!
25
+ def calculate_total_price
26
+ self.total_price = calculate_total
27
+ end
28
+
29
+ def calculate_vat
30
+ return unless sales_order.client.tax_code == "Inland"
31
+
32
+ self.vat = (calculate_total * 0.19).round(2)
33
+ end
34
+
35
+ def calculate_total
36
+ items = InvoiceItem.where(invoice_id: id)
37
+ additionals = AdditionalItem.where(invoice_id: id)
38
+ items.sum(:total_price) + additionals.sum(:total_price)
28
39
  end
29
40
 
30
41
  def self.ransackable_attributes(_auth_object = nil)
@@ -2,7 +2,8 @@ module Comee
2
2
  module Core
3
3
  class InvoiceItem < ApplicationRecord
4
4
  before_save { self.total_price = unit_price * quantity }
5
- after_save { invoice.update_total_price }
5
+ after_save :update_invoice
6
+ after_destroy :update_invoice
6
7
 
7
8
  belongs_to :shipment_instruction_item
8
9
  belongs_to :invoice
@@ -11,10 +12,11 @@ module Comee
11
12
  validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0}
12
13
  validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
13
14
 
14
- # def update_invoice_price
15
- # invoice.total_price = invoice.invoice_items.sum(:total_price) + invoice.additional_items.sum(:total_price)
16
- # invoice.save!
17
- # end
15
+ def update_invoice
16
+ invoice.calculate_total_price
17
+ invoice.calculate_vat
18
+ invoice.save!
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -30,18 +30,19 @@ module Comee
30
30
  allow_nil: true
31
31
 
32
32
  def calculate_total_price
33
- sales_order_items = SalesOrderItem.where(sales_order_id: id)
34
- additional_services = AdditionalService.where(sales_order_id: id)
35
- self.total_price = sales_order_items.sum(&:total_price) + additional_services.sum(&:total_price)
33
+ self.total_price = calculate_total
36
34
  end
37
35
 
38
36
  def calculate_vat
39
37
  return unless client.tax_code == "Inland"
40
38
 
41
- sales_order_items = SalesOrderItem.where(sales_order_id: id)
42
- additional_services = AdditionalService.where(sales_order_id: id)
43
- total_price = sales_order_items.sum(&:total_price) + additional_services.sum(&:total_price)
44
- self.vat = (total_price * 0.19).round(2)
39
+ self.vat = (calculate_total * 0.19).round(2)
40
+ end
41
+
42
+ def calculate_total
43
+ order_items = SalesOrderItem.where(sales_order_id: id)
44
+ services = AdditionalService.where(sales_order_id: id)
45
+ order_items.sum(&:total_price) + services.sum(&:total_price)
45
46
  end
46
47
 
47
48
  def set_parent_client_name
@@ -0,0 +1,5 @@
1
+ class AddVatToInvoice < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :comee_core_invoices, :vat, :float, default: 0
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.16".freeze
3
+ VERSION = "0.3.17".freeze
4
4
  end
5
5
  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.16
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -533,6 +533,7 @@ files:
533
533
  - db/migrate/20240630083042_add_agent_to_pickup_schedule.rb
534
534
  - db/migrate/20240630122016_create_comee_core_additional_services.rb
535
535
  - db/migrate/20240702151519_add_vat_to_purchase_order.rb
536
+ - db/migrate/20240702181613_add_vat_to_invoice.rb
536
537
  - lib/comee/core.rb
537
538
  - lib/comee/core/engine.rb
538
539
  - lib/comee/core/version.rb