comee_core 0.3.22 → 0.3.24

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: 4ef62a4650cf347d3276dede12a8c429757c5261df0697d3632a73b907c1c27a
4
- data.tar.gz: 30d1511ab8a333c92730ccd98f16ced09d5c29aff58e7692fdbf908475ad2370
3
+ metadata.gz: dc08ad949c9e66f2b2f4026348c29fba65c68e823ec852b02d05e6b45afdaf99
4
+ data.tar.gz: d8571a7b44137ee4f48ed5b08b7d753462428ab80abceca23b36875fcb504e46
5
5
  SHA512:
6
- metadata.gz: e9d3e24823a44a19181692cb570c04bb78e7ff6632022fa1e76fbd5ef330bb06be7770c2589b49d19b6613d406199f81f5e6c4c9359675a18621a719d0b5224e
7
- data.tar.gz: 28e92974cd248a841c25dac76b5dd93f89416159b16dde9778a1d51628daece86eb13d332965816e835ffce6550236bd8fc4bfd76b754ea0af43c4669957c099
6
+ metadata.gz: 5b52af4a6c6203f3e3978c2ce8ab82e5edef410d6d44a3c6bb5d8dfa8fdcfc004164da1ba0947e66ef90ee156e0fabdc2967a05077b3f731126fb9d006a7ecac
7
+ data.tar.gz: dd308ef0b4048733475bd5b1c5f14e6cdfa173ef0eab79c1a2203fa04a37fb2103adbef23dc84638a74959667a136bcbd87e27da59a06c2bc29f4925beeed5eb
@@ -3,8 +3,7 @@ module Comee
3
3
  class SalesOrderItem < ApplicationRecord
4
4
  default_scope { order(serial_no: :asc) }
5
5
 
6
- before_save :calculate_total_price
7
- before_save :calculate_handover_date
6
+ before_save :calculate_total_price, :calculate_handover_date, :calculate_price_change, :calculate_quantity_change
8
7
  after_save :update_sales_order
9
8
  after_save :update_sales_order_purchase_status, if: proc { |item| item.fully_processed? }
10
9
  after_destroy :update_sales_order
@@ -42,6 +41,30 @@ module Comee
42
41
  sales_order.save!
43
42
  end
44
43
 
44
+ def calculate_price_change
45
+ return if customer_order_item.unit_id == unit_id && customer_order_item.price == price
46
+
47
+ if customer_order_item.unit_id == unit_id
48
+ self.price_diff = price - customer_order_item.price
49
+ else
50
+ service = CustomerOrderService.new
51
+ co_price = service.convert_price(customer_order_item.price, customer_order_item.unit_id, unit_id)
52
+ self.price_diff = price - co_price
53
+ end
54
+ end
55
+
56
+ def calculate_quantity_change
57
+ return if customer_order_item.unit_id == unit_id && customer_order_item.quantity == quantity
58
+
59
+ if customer_order_item.unit_id == unit_id
60
+ self.quantity_diff = quantity - customer_order_item.quantity
61
+ else
62
+ service = CustomerOrderService.new
63
+ co_quantity = service.convert_quantity(customer_order_item.quantity, customer_order_item.unit_id, unit_id)
64
+ self.quantity_diff = quantity - co_quantity
65
+ end
66
+ end
67
+
45
68
  def quantity_remaining
46
69
  quantity - (quantity_delivered + quantity_canceled)
47
70
  end
@@ -3,7 +3,7 @@ module Comee
3
3
  class SalesOrderItemSerializer < ActiveModel::Serializer
4
4
  attributes :id, :serial_no, :customer_item_no, :customer_item_description, :quantity, :quantity_delivered, :quantity_canceled,
5
5
  :price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id,
6
- :total_price, :canceled, :processing_status, :additional_details, :created_at
6
+ :price_diff, :quantity_diff, :total_price, :canceled, :processing_status, :additional_details, :created_at
7
7
  belongs_to :sales_order
8
8
  belongs_to :customer_order_item
9
9
  belongs_to :source
@@ -194,6 +194,7 @@ module Comee
194
194
  raise(StandardError, "No primary supplier found for product #{item.customer_item_no}") unless master_price
195
195
 
196
196
  product_lookup = master_price.product_lookup
197
+ order_price = convert_price(item.price, item.unit_id, unit_id)
197
198
  price = if client_price
198
199
  convert_price(client_price.price, client_price.unit_id, unit_id)
199
200
  else
@@ -210,6 +211,7 @@ module Comee
210
211
  customer_item_description: item.customer_item_description,
211
212
  quantity: quantity,
212
213
  price: price,
214
+ price_diff: price - order_price,
213
215
  total_price: quantity * price,
214
216
  delivery_date: item.delivery_date,
215
217
  handover_date: order.handover_date,
@@ -0,0 +1,6 @@
1
+ class AddChangeFieldsToSalesOrderItem < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :comee_core_sales_order_items, :price_diff, :float, null: true, default: 0
4
+ add_column :comee_core_sales_order_items, :quantity_diff, :float, null: true, default: 0
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.22".freeze
3
+ VERSION = "0.3.24".freeze
4
4
  end
5
5
  end
@@ -5,14 +5,16 @@ FactoryBot.define do
5
5
  association :customer_order_item, :with_inventory
6
6
  source factory: :fulfillment_center
7
7
  product
8
- unit
8
+ unit { customer_order_item.unit }
9
9
  purchase_order_item { nil }
10
10
  customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
11
11
  customer_item_description { Faker::Lorem.sentence }
12
- quantity { 100 }
12
+ quantity { customer_order_item.quantity }
13
+ quantity_diff { 0 }
13
14
  quantity_delivered { 0 }
14
15
  quantity_canceled { 0 }
15
- price { 50 }
16
+ price { customer_order_item.price }
17
+ price_diff { 0 }
16
18
  total_price { quantity * price }
17
19
  delivery_date { Date.current.advance(months: 1) }
18
20
  handover_date { Date.current }
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.22
4
+ version: 0.3.24
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-07-06 00:00:00.000000000 Z
11
+ date: 2024-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -535,6 +535,7 @@ files:
535
535
  - db/migrate/20240702151519_add_vat_to_purchase_order.rb
536
536
  - db/migrate/20240702181613_add_vat_to_invoice.rb
537
537
  - db/migrate/20240703204755_add_currency_to_master_price.rb
538
+ - db/migrate/20240706160902_add_change_fields_to_sales_order_item.rb
538
539
  - lib/comee/core.rb
539
540
  - lib/comee/core/engine.rb
540
541
  - lib/comee/core/version.rb