comee_core 0.2.12 → 0.2.14

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: 854004edc559daff1dd6605fc7b95b1f83602629d2e59771a487226c95833350
4
- data.tar.gz: 48fe39dcd8d5867fb4abff691bd615f1eb434b7e01cc31771bb0a1a57765af09
3
+ metadata.gz: dac759817de32ff973fe059159a63dd455821779c29124d8cc40763ee85e37f1
4
+ data.tar.gz: b848191c7faf98be197912ef1709617441aa229e501d09051d2cf05a3255e9a9
5
5
  SHA512:
6
- metadata.gz: d47550e712d840c8b1d62fd3b0a7b5a34b5bd8aaf71e6fbbc48cede293d9192d0a2d6801f9176c5d09d5d42b688c28cbb7b468ea035253131f4bb049d55ffb03
7
- data.tar.gz: 743df5145f4670590dbeeb08c36d32a9fea41a465ae05e8594230c554e76abb9e540122c57455a1744a8f7fd575b08ee93802c695f336188cba9dc1b773d9daf
6
+ metadata.gz: 51f9017b7fe3286c0d6968f6e46c970d7dc4dbcb613ab74abdc14cbd1e4dadd97888a45facfdbb9e9bcdebc5c1c0cb981faf80cb0070a253ba848910582bfb07
7
+ data.tar.gz: b98b538ddb7c0ca35870d1bf03557f035aacc15315cd17ec6814e3082d4f2c37055ebef011286dc66821b1d58e461262bcd7cc630d677d32318ee772ebac54bd
@@ -8,7 +8,16 @@ module Comee
8
8
  def index
9
9
  super do
10
10
  [
11
- CustomerOrder.includes(:client, :customer_order_items).all,
11
+ CustomerOrder.includes(:client, customer_order_items: :unit).order(:created_at),
12
+ fields: ["client", "customer_order_items.unit"]
13
+ ]
14
+ end
15
+ end
16
+
17
+ def show
18
+ super do
19
+ [
20
+ CustomerOrder.includes(:client, customer_order_items: :unit).find(params[:id]),
12
21
  fields: ["client", "customer_order_items.unit"]
13
22
  ]
14
23
  end
@@ -16,10 +16,16 @@ module Comee
16
16
 
17
17
  def suggest_values
18
18
  service = CustomerOrderService.new
19
- result = service.suggest_values(params[:id], params[:unit_id])
19
+ result = service.suggest_values(params[:id], suggest_params[:quantity], suggest_params[:unit_id])
20
20
  render json: {success: true, data: result}
21
21
  end
22
22
 
23
+ def cancel
24
+ item = set_object
25
+ item.update(canceled: true)
26
+ render_content(item)
27
+ end
28
+
23
29
  def destroy
24
30
  Comee::Core::SalesOrderItem.destroy(params[:id])
25
31
  render json: {success: true}
@@ -27,6 +33,10 @@ module Comee
27
33
 
28
34
  private
29
35
 
36
+ def suggest_params
37
+ params.require(:payload).permit(:unit_id, :quantity)
38
+ end
39
+
30
40
  def model_params
31
41
  params.require(:payload).permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
32
42
  :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date,
@@ -60,7 +60,7 @@ module Comee
60
60
  def model_params
61
61
  params.require(:payload).permit(:order_number, :order_date, :customer_order_id, :fulfillment_center_id, :client_id,
62
62
  :order_terms, :shipment_address, :delivery_address, :invoice_address, :destination,
63
- :handover_date, :shipping_date, :delivery_date, :consignee, :payment_term, :deivery_term,
63
+ :handover_date, :shipping_date, :delivery_date, :consignee, :payment_term, :delivery_term,
64
64
  :payment_penalty, :status, :total_price, :amount_paid, :pallete_note, :remark,
65
65
  files: [])
66
66
  end
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class CustomerOrderItem < ApplicationRecord
4
- before_save :calculate_total_price, unless: proc { |item| item.total_price }
4
+ before_save :calculate_total_price
5
5
 
6
6
  belongs_to :customer_order
7
7
  belongs_to :product
@@ -2,7 +2,7 @@ module Comee
2
2
  module Core
3
3
  class SalesOrderItemSerializer < ActiveModel::Serializer
4
4
  attributes :id, :customer_item_no, :customer_item_description, :quantity, :quantity_delivered, :price, :handover_date,
5
- :delivery_date, :eb_number, :lead_time, :comment, :action_note, :po_reference, :total_price
5
+ :delivery_date, :eb_number, :lead_time, :comment, :action_note, :po_reference, :total_price, :canceled
6
6
 
7
7
  belongs_to :sales_order
8
8
  belongs_to :customer_order_item
@@ -71,12 +71,14 @@ module Comee
71
71
  (quantity / conversion.factor).round
72
72
  end
73
73
 
74
- def suggest_values(item_id, new_unit_id)
74
+ def suggest_values(item_id, new_quantity, new_unit_id)
75
75
  item = CustomerOrderItem.includes(:customer_order).find_by(id: item_id)
76
76
  raise(StandardError, "Order item with id `#{item_id}` not found.") unless item
77
77
 
78
- quantity = convert_quantity(item.quantity, item.unit_id, new_unit_id)
79
- client_price = ClientPrice.find_by(product_id: item.product_id, client_id: item.customer_order.client_id)
78
+ quantity = convert_quantity(new_quantity, item.unit_id, new_unit_id)
79
+ client = Client.find(item.customer_order.client_id)
80
+ client_id = client.parent_id || client.id
81
+ client_price = ClientPrice.find_by(product_id: item.product_id, client_id: client_id)
80
82
  if client_price
81
83
  price = convert_price(client_price.price, client_price.unit_id, new_unit_id)
82
84
  else
data/config/routes.rb CHANGED
@@ -112,7 +112,8 @@ Comee::Core::Engine.routes.draw do
112
112
  end
113
113
  resources :sales_order_items, except: [:index] do
114
114
  member do
115
- get "suggest", controller: :sales_order_items, action: :suggest_values
115
+ post "suggest", controller: :sales_order_items, action: :suggest_values
116
+ post "cancel"
116
117
  end
117
118
  end
118
119
  resources :shipment_items do
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.12".freeze
3
+ VERSION = "0.2.14".freeze
4
4
  end
5
5
  end
@@ -18,5 +18,6 @@ FactoryBot.define do
18
18
  comment { Faker::Lorem.sentence }
19
19
  action_note { Faker::Lorem.sentence }
20
20
  po_reference { Faker::Alphanumeric.alpha(number: 10) }
21
+ canceled { false }
21
22
  end
22
23
  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.2.12
4
+ version: 0.2.14
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-02-06 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers