comee_core 0.3.15 → 0.3.17

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: e4b933796931ae7b24c03d2e6901df6b6f4c1b27f314b1b967eabb13da3654fd
4
- data.tar.gz: f257c672d231e620f292d3ca60aadc72620ef4f5fbaa68a7dc0076cc3ddf4542
3
+ metadata.gz: 31d273c0f307b780445d84f77724d21676a90ecb97923b6e57452f011a31ede1
4
+ data.tar.gz: 8e5b700c41f8dcd22bccf746756bfdcc6669a1774622cf9f4dd03c1383a7b6a4
5
5
  SHA512:
6
- metadata.gz: 24013af0d8419d7d880de21c574cfa21b39c9d70cf67dda64ed2f32a8b1b78dc90b6622c8e25fa638b7db6821e46ad43a880ab1bfabb6ef8b34b914bb0ff233d
7
- data.tar.gz: 1c9e73ac25c7f40809265ba6a844f458ba51a6e0e0daadaa67c09643b9964a9f4b2ac7a8bd1c6d665a28d1a602726338d62d24ba639b50bc03d5ae90ac750d41
6
+ metadata.gz: d8b7269868908faea7b9fce4be61b9a9d0302a29854d29ea37948afd9c0a6ba77949aa5e241bb24ad63cd7b50faad5c2650d57d7311272c131c609511f4c0169
7
+ data.tar.gz: a11db8aeef2a636b16b5723c41bd8385107cf8554ddb87ddc98f1173d36fa2611619cce558194059d30e225f38b5596c704fc2f5abb5c6f5a934bdfe6c87a804
@@ -20,7 +20,7 @@ module Comee
20
20
  end
21
21
 
22
22
  def filter
23
- data = ProductLookup.includes(:product).ransack(params[:q]).result
23
+ data = ProductLookup.includes(:product, :itemable).ransack(params[:q]).result
24
24
  render_content(data)
25
25
  end
26
26
 
@@ -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
@@ -2,7 +2,7 @@ module Comee
2
2
  module Core
3
3
  class PurchaseOrder < ApplicationRecord
4
4
  before_validation :generate_po_number, if: proc { |po| po.po_number.nil? }
5
- before_save :total_price, :set_terms
5
+ before_save :set_terms
6
6
 
7
7
  belongs_to :supplier
8
8
  has_many :purchase_order_items
@@ -18,11 +18,19 @@ module Comee
18
18
  canceled: 5
19
19
  }
20
20
 
21
- def total_price
21
+ def calculate_total_price
22
22
  items = PurchaseOrderItem.where(purchase_order_id: id)
23
23
  self.total_price = items.sum(&:total_price)
24
24
  end
25
25
 
26
+ def calculate_vat
27
+ return unless supplier.tax_code == "Inland"
28
+
29
+ items = PurchaseOrderItem.where(purchase_order_id: id)
30
+ total_price = items.sum(&:total_price)
31
+ self.vat = (total_price * 0.19).round(2)
32
+ end
33
+
26
34
  def self.ransackable_attributes(_auth_object = nil)
27
35
  %w[
28
36
  id
@@ -2,6 +2,8 @@ module Comee
2
2
  module Core
3
3
  class PurchaseOrderItem < ApplicationRecord
4
4
  before_save :calculate_total_price, :calculate_confirmation_values
5
+ after_save :update_purchase_order
6
+ after_destroy :update_purchase_order
5
7
 
6
8
  has_one :purchase_order_item_diff
7
9
 
@@ -32,6 +34,12 @@ module Comee
32
34
  self.confirmed_total_price = (confirmed_price * confirmed_quantity).round(2)
33
35
  end
34
36
 
37
+ def update_purchase_order
38
+ purchase_order.calculate_total_price
39
+ purchase_order.calculate_vat
40
+ purchase_order.save!
41
+ end
42
+
35
43
  def self.ransackable_attributes(_auth_object = nil)
36
44
  %w[
37
45
  id
@@ -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
@@ -3,6 +3,7 @@ module Comee
3
3
  class ProductLookupSerializer < ActiveModel::Serializer
4
4
  attributes :id, :code, :itemable_id, :itemable_type, :item_description, :aliases
5
5
  belongs_to :product
6
+ belongs_to :itemable
6
7
  end
7
8
  end
8
9
  end
@@ -0,0 +1,5 @@
1
+ class AddVatToPurchaseOrder < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :comee_core_purchase_orders, :vat, :float, default: 0
4
+ end
5
+ end
@@ -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.15".freeze
3
+ VERSION = "0.3.17".freeze
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ FactoryBot.define do
5
5
  locale { "en" }
6
6
  payment_terms { Faker::Lorem.word }
7
7
  vat_number { Faker::Alphanumeric.alpha(number: 8) }
8
- tax_code { Faker::Alphanumeric.alpha(number: 8) }
8
+ tax_code { "Inland" }
9
9
  user
10
10
  currency
11
11
  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.15
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -532,6 +532,8 @@ files:
532
532
  - db/migrate/20240630063656_add_aliases_field_to_product_lookup.rb
533
533
  - db/migrate/20240630083042_add_agent_to_pickup_schedule.rb
534
534
  - db/migrate/20240630122016_create_comee_core_additional_services.rb
535
+ - db/migrate/20240702151519_add_vat_to_purchase_order.rb
536
+ - db/migrate/20240702181613_add_vat_to_invoice.rb
535
537
  - lib/comee/core.rb
536
538
  - lib/comee/core/engine.rb
537
539
  - lib/comee/core/version.rb