comee_core 0.1.99 → 0.2.1

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: f3b5b69ffae3e2702ed23106fbc360890ec375ae49c97a136b98baad2fec89d8
4
- data.tar.gz: 5fc14c0bac612232d3d32bf4c2f1f0e98e75773adb2aa343d1b73387f8b92bac
3
+ metadata.gz: 2d7cf157e4f4751fc575616de0c6828c89b2fff51cf7dcd28347feb7f668ad6b
4
+ data.tar.gz: 1dac2167d8e7419c2312ec89cf8e8276f56ed1ca6ef0ac6a71e24ec432cec1bf
5
5
  SHA512:
6
- metadata.gz: 986aff6f5d73b35a540a16fbbdafc62a2c03911a6cd06430de431fa30f547994ec3038d90d38e37a8504f36547cb3f519f9804cc8828a54942b08b49752d2884
7
- data.tar.gz: c4add758cc2d3c861a10b0c584f96abac453928bacd0ad5375150bc56233323d4c95a0aa5f617cfe036884efad323b900c39dc6579ae4baaa6fa7d4c0c3fd3a4
6
+ metadata.gz: 88c434b7eb17e6dba7c24911369d03128f0eaeed66409a5e6c1bce86b1648948ce07d6e4472c12c2bc3ada0aad59c79c8a9644921cb977c873c48b8aaab2bbec
7
+ data.tar.gz: 6307f0083025d5473b9a7bf14a1f43070bf4590e8a2c890070e203cc64842fc8c692dc721ea248aed3c606321962df6bf372269aabbf4e9bb6a7a8adcdca1367
@@ -9,6 +9,52 @@ module Comee
9
9
  end
10
10
  end
11
11
 
12
+ def create
13
+ super do
14
+ price = ClientPrice.new(model_params)
15
+ master_price = MasterPrice.find_by(product_id: price.product_id, primary: true)
16
+ price.price = master_price&.selling_price
17
+ if price.price
18
+ price.price = price.margin_increase? ? price.price * (1 + price.margin / 100) : price.price * (1 - price.margin / 100)
19
+ end
20
+ price
21
+ end
22
+ end
23
+
24
+ def update
25
+ if @obj.draft?
26
+ product_id = model_params[:product_id] || @obj.product_id
27
+ master_price = MasterPrice.find_by(product_id: product_id, primary: true)
28
+ @obj.price = master_price&.selling_price
29
+ if @obj.price
30
+ @obj.price = @obj.margin_increase? ? @obj.price * (1 + @obj.margin / 100) : @obj.price * (1 - @obj.margin / 100)
31
+ end
32
+ if @obj.update(model_params)
33
+ render_content(@obj)
34
+ else
35
+ render json: {success: false, error: @obj.errors.full_messages[0]}, status: :unprocessable_entity
36
+ end
37
+ else
38
+ error = "Client price should be in draft state to edit."
39
+ render json: {success: false, error: error}, status: :unprocessable_entity
40
+ end
41
+ rescue StandardError => e
42
+ render json: {success: false, error: e.message}
43
+ end
44
+
45
+ def extend_validity
46
+ price = ClientPrice.find(params[:id])
47
+ if price.draft?
48
+ render json: {success: false, error: "Price must be an approved price for validity extension."}
49
+ else
50
+ price.valid_to = extend_params[:valid_to]
51
+ price.save!
52
+ render_content(price)
53
+ end
54
+ rescue StandardError => e
55
+ render json: {success: false, error: e.message}
56
+ end
57
+
12
58
  def fetch_for_client
13
59
  client = Client.find(params[:id])
14
60
  client_id = client.parent_id || client.id
@@ -17,6 +63,14 @@ module Comee
17
63
  render_content(prices)
18
64
  end
19
65
 
66
+ def approve
67
+ price = ClientPrice.find(params[:id])
68
+ price = price.approve
69
+ render_content(price)
70
+ rescue StandardError => e
71
+ render json: {success: false, error: e.message}, status: :unprocessable_entity
72
+ end
73
+
20
74
  def filter
21
75
  prices = ClientPrice.includes(:client, :product, :unit, :product_lookup)
22
76
  .ransack(params[:q]).result
@@ -26,9 +80,13 @@ module Comee
26
80
  private
27
81
 
28
82
  def model_params
29
- params.require(:payload).permit(:valid_from, :valid_to, :price, :product_id, :margin, :margin_type, :client_id, :previous_price,
83
+ params.require(:payload).permit(:valid_from, :valid_to, :product_id, :margin, :margin_type, :client_id, :previous_price,
30
84
  :unit_id)
31
85
  end
86
+
87
+ def extend_params
88
+ params.require(:payload).permit(:valid_to)
89
+ end
32
90
  end
33
91
  end
34
92
  end
@@ -60,7 +60,7 @@ module Comee
60
60
  def model_params
61
61
  params.require(:payload).permit(:order_number, :customer_order_id, :payment_penalty, :payment_term, :delivery_term, :status,
62
62
  :fulfillment_center_id, :total_price, :amount_paid, :pallete_note, :handover_date, :remark,
63
- :client_id, files: [])
63
+ :consignee, :client_id, files: [])
64
64
  end
65
65
 
66
66
  def back_order_params
@@ -61,7 +61,7 @@ module Comee
61
61
 
62
62
  def model_params
63
63
  params.require(:payload).permit(:sales_order_item_id, :quantity, :shipment_status, :status, :handover_date, :delivery_date,
64
- :pallet_no)
64
+ :pallet_no, :consignee, :order_number)
65
65
  end
66
66
  end
67
67
  end
@@ -5,6 +5,10 @@ module Comee
5
5
  belongs_to :client
6
6
 
7
7
  validates :url, :processed, presence: true
8
+
9
+ def self.ransackable_attributes(_auth_object = nil)
10
+ %w[client_id id order_source_id processed]
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -23,6 +23,14 @@ module Comee
23
23
  end
24
24
  end
25
25
 
26
+ def margin_increase?
27
+ ClientPrice.margin_types[margin_type] == ClientPrice.margin_types[:increase]
28
+ end
29
+
30
+ def margin_discount?
31
+ ClientPrice.margin_types[margin_type] == ClientPrice.margin_types[:discount]
32
+ end
33
+
26
34
  def self.ransackable_attributes(_auth_object = nil)
27
35
  %w[
28
36
  id
@@ -2,7 +2,7 @@ module Comee
2
2
  module Core
3
3
  class ItemStatus < ApplicationRecord
4
4
  INITIALIZED = "Initialized".freeze
5
- DELIVERY_NOTE_CREATED = "Delivery note created".freeze
5
+ DELIVERY_NOTE_CREATED = "Delivery Note Created".freeze
6
6
  COMPLETELY_PICKED_AND_PACKED = "Completely Picked & Packed".freeze
7
7
  PARTIALLY_PICKED_AND_PACKED = "Partially Picked & Packed".freeze
8
8
 
@@ -23,6 +23,14 @@ module Comee
23
23
  errors.add(:base, "Price validity date range is not correct.") unless period.valid?
24
24
  end
25
25
 
26
+ def draft?
27
+ Price.price_statuses[price_status] == Price.price_statuses[:draft]
28
+ end
29
+
30
+ def approved?
31
+ Price.price_statuses[price_status] == Price.price_statuses[:approved]
32
+ end
33
+
26
34
  def compute_status
27
35
  period = Period.new(valid_from, valid_to)
28
36
  if period.past?
@@ -34,6 +42,16 @@ module Comee
34
42
  end
35
43
  end
36
44
 
45
+ def approve
46
+ if Price.price_statuses[price_status] == Price.price_statuses[:approved]
47
+ raise(StandardError, "Price status is already in approved state.")
48
+ end
49
+
50
+ self.price_status = Price.price_statuses[:approved]
51
+ save!
52
+ self
53
+ end
54
+
37
55
  def past?
38
56
  Price.statuses[status] == Price.statuses[:past]
39
57
  end
@@ -6,7 +6,7 @@ module Comee
6
6
  belongs_to :sales_order_item
7
7
  has_many :item_statuses
8
8
 
9
- validates :handover_date, :delivery_date, :shipment_status, :status, presence: true
9
+ validates :handover_date, :delivery_date, :shipment_status, :status, :order_number, presence: true
10
10
  validates :quantity, presence: true, numericality: {greater_than: 0}
11
11
 
12
12
  def self.ransackable_attributes(_auth_object = nil)
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class ClientPriceSerializer < ActiveModel::Serializer
4
- attributes :id, :valid_from, :valid_to, :price, :status, :previous_price, :margin, :margin_type
4
+ attributes :id, :valid_from, :valid_to, :price, :status, :price_status, :previous_price, :margin, :margin_type
5
5
  belongs_to :product
6
6
  belongs_to :client
7
7
  belongs_to :unit
@@ -1,7 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class MasterPriceSerializer < ActiveModel::Serializer
4
- attributes :id, :purchase_price, :selling_price, :valid_from, :valid_to, :primary, :margin, :lead_time, :status
4
+ attributes :id, :purchase_price, :selling_price, :valid_from, :valid_to, :primary, :margin, :lead_time, :status,
5
+ :price_status
5
6
  belongs_to :product
6
7
  belongs_to :supplier
7
8
  belongs_to :product_lookup
@@ -2,7 +2,7 @@ module Comee
2
2
  module Core
3
3
  class SalesOrderSerializer < ActiveModel::Serializer
4
4
  attributes :id, :order_number, :payment_penalty, :status, :total_price, :payment_term, :delivery_term, :amount_paid,
5
- :pallete_note, :handover_date, :remark, :parent_client_name, :created_by, :files_url, :customs_detail
5
+ :pallete_note, :handover_date, :remark, :parent_client_name, :created_by, :files_url, :customs_detail, :consignee
6
6
  belongs_to :customer_order
7
7
  belongs_to :client
8
8
  belongs_to :fulfillment_center
@@ -1,7 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class ShipmentItemSerializer < ActiveModel::Serializer
4
- attributes :id, :quantity, :shipment_status, :status, :handover_date, :delivery_date, :pallet_no
4
+ attributes :id, :quantity, :shipment_status, :status, :handover_date, :delivery_date, :pallet_no, :consignee,
5
+ :order_number
5
6
  belongs_to :sales_order_item
6
7
  end
7
8
  end
@@ -141,6 +141,7 @@ module Comee
141
141
  customer_order: order,
142
142
  status: SalesOrder.statuses[:draft],
143
143
  client: order.client,
144
+ consignee: order.consignee,
144
145
  created_by: accepted_by || ""
145
146
  )
146
147
  order_items = order.customer_order_items.includes(:product, :unit)
data/config/routes.rb CHANGED
@@ -93,8 +93,15 @@ Comee::Core::Engine.routes.draw do
93
93
  end
94
94
  end
95
95
  resources :agents
96
- post "/client_prices/filter", controller: :client_prices, action: :filter
97
- resources :client_prices
96
+ resources :client_prices do
97
+ member do
98
+ post "extend_validity"
99
+ post "approve"
100
+ end
101
+ collection do
102
+ post "filter"
103
+ end
104
+ end
98
105
  post "/back_orders/filter", controller: :back_orders, action: :filter
99
106
  resources :back_orders do
100
107
  member do
@@ -14,6 +14,7 @@ class CreateComeeCoreSalesOrders < ActiveRecord::Migration[7.0]
14
14
  null: false,
15
15
  index: {name: "client_on_ccso_indx"},
16
16
  foreign_key: {to_table: :comee_core_clients}
17
+ t.string :consignee
17
18
  t.string :parent_client_name
18
19
  t.string :payment_term
19
20
  t.string :delivery_term
@@ -11,6 +11,8 @@ class CreateComeeCoreShipmentItems < ActiveRecord::Migration[7.1]
11
11
  t.date :handover_date, null: false
12
12
  t.date :delivery_date, null: false
13
13
  t.string :pallet_no
14
+ t.string :consignee
15
+ t.string :order_number, null: false
14
16
 
15
17
  t.timestamps
16
18
  end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.99".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
@@ -22,5 +22,9 @@ FactoryBot.define do
22
22
  valid_from { Date.current.advance(months: 1) }
23
23
  valid_to { Date.current.advance(months: 2) }
24
24
  end
25
+
26
+ trait :approved do
27
+ price_status { Comee::Core::Price.price_statuses[:approved] }
28
+ end
25
29
  end
26
30
  end
@@ -11,6 +11,7 @@ FactoryBot.define do
11
11
  amount_paid { 0 }
12
12
  status { Comee::Core::SalesOrder.statuses[:draft] }
13
13
  pallete_note { Faker::Lorem.sentence }
14
+ consignee { Faker::Name.name }
14
15
  remark { Faker::Lorem.sentence }
15
16
  parent_client_name { Faker::Name.name }
16
17
  created_by { Faker::Name.name }
@@ -7,5 +7,7 @@ FactoryBot.define do
7
7
  handover_date { Date.current.advance(days: 3) }
8
8
  delivery_date { Date.current.advance(days: 6) }
9
9
  pallet_no { Faker::Alphanumeric.alpha(number: 10) }
10
+ consignee { Faker::Name.name }
11
+ order_number { sales_order_item.sales_order.order_number }
10
12
  end
11
13
  end
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.1.99
4
+ version: 0.2.1
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-01-21 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers