comee_core 0.1.40 → 0.1.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/customer_order_items_controller.rb +34 -0
  3. data/app/controllers/comee/core/customer_orders_controller.rb +47 -0
  4. data/app/controllers/comee/core/external_rfqs_controller.rb +13 -0
  5. data/app/controllers/comee/core/products_controller.rb +2 -3
  6. data/app/controllers/comee/core/quotation_request_items_controller.rb +46 -0
  7. data/app/controllers/comee/core/quotation_requests_controller.rb +66 -0
  8. data/app/controllers/comee/core/sales_order_items_controller.rb +25 -0
  9. data/app/controllers/comee/core/sales_orders_controller.rb +45 -0
  10. data/app/models/comee/core/customer_order.rb +10 -1
  11. data/app/models/comee/core/customer_order_item.rb +8 -0
  12. data/app/models/comee/core/external_rfq.rb +8 -0
  13. data/app/models/comee/core/product.rb +6 -34
  14. data/app/models/comee/core/purchase_order.rb +14 -0
  15. data/app/models/comee/core/purchase_order_item.rb +20 -0
  16. data/app/models/comee/core/quotation_request.rb +25 -0
  17. data/app/models/comee/core/quotation_request_item.rb +15 -0
  18. data/app/models/comee/core/sales_order.rb +2 -2
  19. data/app/serializers/comee/core/customer_order_item_serializer.rb +10 -0
  20. data/app/serializers/comee/core/customer_order_serializer.rb +9 -0
  21. data/app/serializers/comee/core/external_rfq_serializer.rb +7 -0
  22. data/app/serializers/comee/core/product_serializer.rb +1 -2
  23. data/app/serializers/comee/core/quotation_request_item_serializer.rb +10 -0
  24. data/app/serializers/comee/core/quotation_request_serializer.rb +8 -0
  25. data/app/serializers/comee/core/sales_order_item_serializer.rb +10 -0
  26. data/app/serializers/comee/core/sales_order_serializer.rb +10 -0
  27. data/app/services/comee/core/customer_order_service.rb +80 -0
  28. data/app/services/comee/core/quotation_request_service.rb +69 -0
  29. data/app/services/comee/core/sales_order_service.rb +141 -0
  30. data/config/routes.rb +57 -3
  31. data/db/migrate/20230728014322_create_comee_core_products.rb +3 -11
  32. data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
  33. data/db/migrate/20230812190652_create_comee_core_sales_orders.rb +4 -4
  34. data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +2 -1
  35. data/db/migrate/20231121094339_create_comee_core_quotation_requests.rb +15 -0
  36. data/db/migrate/20231121132709_create_comee_core_quotation_request_items.rb +27 -0
  37. data/db/migrate/20231122094424_create_comee_core_external_rfqs.rb +10 -0
  38. data/db/migrate/20231125122723_create_comee_core_purchase_orders.rb +15 -0
  39. data/db/migrate/20231126082907_create_comee_core_purchase_order_items.rb +20 -0
  40. data/lib/comee/core/version.rb +1 -1
  41. data/lib/comee_core.rb +1 -0
  42. data/spec/factories/comee/core/customer_order_items.rb +1 -0
  43. data/spec/factories/comee/core/external_rfqs.rb +6 -0
  44. data/spec/factories/comee/core/products.rb +5 -4
  45. data/spec/factories/comee/core/purchase_order_items.rb +9 -0
  46. data/spec/factories/comee/core/purchase_orders.rb +8 -0
  47. data/spec/factories/comee/core/quotation_request_items.rb +14 -0
  48. data/spec/factories/comee/core/quotation_requests.rb +7 -0
  49. data/spec/factories/comee/core/sales_order_items.rb +2 -1
  50. data/spec/factories/comee/core/sales_orders.rb +0 -1
  51. metadata +49 -7
  52. data/app/controllers/comee/core/product_types_controller.rb +0 -18
  53. data/app/models/comee/core/product_type.rb +0 -19
  54. data/db/migrate/20230728012836_create_comee_core_product_types.rb +0 -13
  55. data/spec/factories/comee/core/product_types.rb +0 -8
@@ -0,0 +1,69 @@
1
+ module Comee
2
+ module Core
3
+ class QuotationRequestService
4
+ def create_request_with_items(params)
5
+ request = nil
6
+ QuotationRequest.transaction do
7
+ request = QuotationRequest.create!(client_id: params[:client_id], status: QuotationRequest.statuses[:draft])
8
+ items = params[:items]
9
+ items.each do |item|
10
+ item[:price] = 0
11
+ item[:quotation_request_id] = request.id
12
+ item[:discount] = 0
13
+ end
14
+ QuotationRequestItem.insert_all!(items)
15
+ end
16
+ request
17
+ rescue StandardError
18
+ raise
19
+ end
20
+
21
+ def submit(id)
22
+ rfq = QuotationRequest.find(id)
23
+
24
+ raise(StandardError, "RFQ should be in draft state.") if QuotationRequest.statuses[rfq.status] != QuotationRequest.statuses[:draft]
25
+
26
+ raise(StandardError, "RFQ does not have any items.") if rfq.quotation_request_items.count.zero?
27
+
28
+ raise(StandardError, "RFQ contains only canceled items.") if rfq.quotation_request_items.all?(&:canceled?)
29
+
30
+ QuotationRequest.transaction do
31
+ product_ids = rfq.quotation_request_items.map(&:product_id)
32
+ prices = MasterPrice.where(product_id: product_ids).each_with_object({}) do |price, res|
33
+ res[price.product_id] = [price.selling_price, price.valid_from, price.valid_to]
34
+ end
35
+ items = rfq.quotation_request_items.each_with_object({}) do |item, res|
36
+ price = prices[item.product_id]
37
+ res[item.id] = {price: price[0], valid_from: price[1], valid_to: price[2]} if price
38
+ end
39
+ QuotationRequestItem.update!(items.keys, items.values)
40
+ rfq.status = QuotationRequest.statuses[:submitted]
41
+ rfq.save!
42
+ end
43
+ rfq
44
+ end
45
+
46
+ def submit_for_confirmation(id)
47
+ rfq = QuotationRequest.find(id)
48
+ if QuotationRequest.statuses[rfq.status] != QuotationRequest.statuses[:submitted]
49
+ raise(StandardError, "RFQ should be in submitted state.")
50
+ end
51
+
52
+ rfq.status = QuotationRequest.statuses[:awaiting_confirmation]
53
+ rfq.save!
54
+ rfq
55
+ end
56
+
57
+ def confirm(id)
58
+ rfq = QuotationRequest.find(id)
59
+ if QuotationRequest.statuses[rfq.status] != QuotationRequest.statuses[:awaiting_confirmation]
60
+ raise(StandardError, "RFQ should be in awaiting_confirmation state.")
61
+ end
62
+
63
+ rfq.status = QuotationRequest.statuses[:confirmed]
64
+ rfq.save!
65
+ rfq
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,141 @@
1
+ module Comee
2
+ module Core
3
+ class SalesOrderService
4
+ ##
5
+ # This method returns { success: true} if all back orders in the +params+ created successfully.
6
+ # The +params+ contain array of back orders with the corresponding products.
7
+ # The exact structure of +params+ looks like the following
8
+ # [{supplier_id: '', order_number: '', order_date: '', delivery_date: '', delivery_address: '', invoice_address: '',
9
+ # back_order_items: [{product_id: '', requested_quantity: ''},...] }...]
10
+ def create_back_orders(params)
11
+ check_product_prices(params)
12
+ check_duplicate_order_number(params)
13
+ bulk_create_back_order(params)
14
+ end
15
+
16
+ ##
17
+ # This method returns true if all products under each back order in +params+ have active price in the master price table.
18
+ # The +params+ contain array of back orders with the corresponding products.
19
+ # The exact structure of +params+ looks like the following
20
+ # [{supplier_id: '', order_number: '', order_date: '', delivery_date: '', delivery_address: '', invoice_address: '',
21
+ # back_order_items: [{product_id: '', requested_quantity: ''},...] }...]
22
+ def check_product_prices(params)
23
+ queries = []
24
+ params.each do |param|
25
+ param[:back_order_items].map do |bo_item|
26
+ queries << {supplier_id: param[:supplier_id], product_id: bo_item[:product_id]}
27
+ end
28
+ end
29
+ master_prices = queries.inject(Comee::Core::MasterPrice.none) do |conditions, condition|
30
+ conditions.or(Comee::Core::MasterPrice.where(condition))
31
+ end
32
+
33
+ raise(StandardError, compose_error_messge(queries, master_prices)) unless queries.count == master_prices.count
34
+
35
+ true
36
+ end
37
+
38
+ ##
39
+ # This method composes an error message when called from check_product_prices.
40
+ # It recieves +queries+ and +master_prices+ as a parameter
41
+ # The +queries+ is an array containing list of conditions that will be joined using or connector
42
+ # The +queries+ param looks like [{supplier_id: '', product_id: '', active: true},...]
43
+ # The +master_prices+ param contains master prices fetched by the queries param given above
44
+ # The message is composed by computing difference b/n the queries and master prices params
45
+ def compose_error_messge(queries, master_prices)
46
+ result = master_prices.map { |mp| {supplier_id: mp[:supplier_id], product_id: mp[:product_id]} }
47
+ diff = queries - result
48
+ product_names = Comee::Core::Product.where(id: diff.map { |dif| dif[:product_id] }).pluck("name").join(", ")
49
+ supplier_names = Comee::Core::Supplier.where(id: diff.map { |dif| dif[:supplier_id] }).pluck("name").join(", ")
50
+ "The following products #{product_names} do not have price entry for the following suppliers" \
51
+ " #{supplier_names} in the master price table or the prices are not valid."
52
+ end
53
+
54
+ ##
55
+ # This method returns false if there is no duplicate order number, otherwise it raises an error.
56
+ # The +params+ contain array of back orders with the corresponding products.
57
+ # The exact structure of +params+ looks like the following
58
+ # [{supplier_id: '', order_number: '', order_date: '', delivery_date: '', delivery_address: '', invoice_address: '',
59
+ # back_order_items: [{product_id: '', requested_quantity: ''},...] }...]
60
+ # The method first checks if there is duplicate order number within in the +params+ array, and if not then it checks
61
+ # for duplicate order number from back order table.
62
+ def check_duplicate_order_number(params)
63
+ order_numbers = params.map { |param| param[:order_number] }
64
+ unless order_numbers.uniq.count == order_numbers.count
65
+ raise(StandardError, "Duplicate order number(s) #{order_numbers.select do |e|
66
+ order_numbers.count(e) > 1
67
+ end.uniq.join(', ')} exist in the payload.")
68
+ end
69
+
70
+ duplicate_order_numbers = Comee::Core::BackOrder.where(order_number: order_numbers)
71
+ unless duplicate_order_numbers.count.zero?
72
+ raise(StandardError,
73
+ "Duplicate order number(s) #{duplicate_order_numbers.map(&:order_number).join(', ')} exist in the back order table.")
74
+ end
75
+
76
+ false
77
+ end
78
+
79
+ ##
80
+ # This method returns items aggregated by product for a supplier.
81
+ # It recieves +items+, +supplier_id+ and +back_order_id+ as a parameter
82
+ # The +items+ is an array containing list of back order items
83
+ # The +items+ param looks like [{product_id: '', requested_quantity: ''},...]
84
+ # The +supplier_id+ is the id of the supplier under which the items belong to
85
+ # The +back_order_id+ is the id of the backer order under which the items belong to
86
+ def aggregate_back_order_item(items, supplier_id, back_order_id, delivery_date)
87
+ items.group_by { |item| item[:product_id] }.map do |product_id, aggregated_items|
88
+ total_quantity = aggregated_items.reduce(0) { |sum, agg_item| agg_item[:requested_quantity] + sum }
89
+ {product_id: product_id, requested_quantity: total_quantity, supplier_quantity: total_quantity, supplier_id: supplier_id,
90
+ back_order_id: back_order_id, delivery_date: delivery_date}
91
+ end
92
+ end
93
+
94
+ ##
95
+ # This method assigns current purchase price for a product under a given supplier.
96
+ # It recieves +items+ containing array of products along with the corresponding suppliers
97
+ # The +items+ param looks like [
98
+ # {product_id: '', requested_quantity: '', supplier_quantity: '', supplier_id: '', back_order_id: '' },
99
+ # ...
100
+ # ]
101
+ # It assigns price by first fetching the price of products in the items array and then iterate through the
102
+ # items array and find the corresponding price from the fetched price
103
+ def assign_price_to_items(items)
104
+ queries = []
105
+ items.map { |bo_item| queries << {supplier_id: bo_item[:supplier_id], product_id: bo_item[:product_id]} }
106
+ master_prices = queries.inject(Comee::Core::MasterPrice.none) do |conditions, condition|
107
+ conditions.or(Comee::Core::MasterPrice.where(condition))
108
+ end
109
+ items.each do |item|
110
+ mp = master_prices.find { |price| price.supplier_id == item[:supplier_id] && price.product_id == item[:product_id] }
111
+ item[:requested_unit_price] = mp.purchase_price
112
+ item[:supplier_unit_price] = mp.purchase_price
113
+ item[:from] = mp.valid_from
114
+ item[:to] = mp.valid_from
115
+ item.delete(:supplier_id)
116
+ end
117
+ end
118
+
119
+ ##
120
+ # This method returns { success: true} if all back orders in the +params+ created successfully.
121
+ # The +params+ contain array of back orders with the corresponding products.
122
+ # The exact structure of +params+ looks like the following
123
+ # [{supplier_id: '', order_number: '', order_date: '', delivery_date: '', delivery_address: '', invoice_address: '',
124
+ # back_order_items: [{product_id: '', requested_quantity: ''},...] }...]
125
+ # This method uses insert_all method to create back order and its items in bulk
126
+ def bulk_create_back_order(params)
127
+ back_orders = params.map { |p| {**p.except(:back_order_items), created_at: Time.now, updated_at: Time.now} }
128
+ result = Comee::Core::BackOrder.insert_all!(back_orders, returning: %w[id supplier_id delivery_date])
129
+ aggregated_items = []
130
+ result.pluck("id", "supplier_id", "delivery_date").each do |r|
131
+ supplier_detail = params.find { |p| p[:supplier_id].to_i == r[1] }
132
+ aggregated_items << aggregate_back_order_item(supplier_detail[:back_order_items], r[1], r[0], r[2])
133
+ end
134
+ Comee::Core::BackOrderItem.insert_all!(assign_price_to_items(aggregated_items.flatten))
135
+ {success: true}
136
+ rescue StandardError => e
137
+ {success: false, error: e.message}
138
+ end
139
+ end
140
+ end
141
+ end
data/config/routes.rb CHANGED
@@ -10,15 +10,56 @@ Comee::Core::Engine.routes.draw do
10
10
  end
11
11
  resources :suppliers
12
12
  resources :products
13
- resources :product_types do
13
+ resources :quotation_requests do
14
+ collection do
15
+ post "filter"
16
+ post "create_with_items", controller: :quotation_requests, action: :create_request_with_items
17
+ end
18
+ member do
19
+ post "submit"
20
+ post "submit_for_confirmation"
21
+ post "confirm"
22
+ end
23
+ end
24
+ resources :quotation_request_items do
25
+ collection do
26
+ post "filter"
27
+ post "cancel"
28
+ end
29
+ end
30
+ resources :external_rfqs
31
+ resources :customer_orders do
32
+ member do
33
+ post "submit"
34
+ post "submit_for_confirmation"
35
+ post "accept"
36
+ post "cancel"
37
+ end
38
+ end
39
+ resources :customer_order_items do
40
+ collection do
41
+ post "filter"
42
+ post "cancel"
43
+ end
44
+ end
45
+ resources :customer_orders, only: [] do
14
46
  member do
15
- get "products", controller: :product_types, action: :products
47
+ get "order", controller: :customer_orders, action: :order
48
+ patch "cancel", controller: :customer_orders, action: :cancel
49
+ patch "seek_confirmation", controller: :customer_orders, action: :seek_confirmation
50
+ patch "submit", controller: :customer_orders, action: :submit
51
+ patch "accept", controller: :customer_orders, action: :accept
52
+ patch "bulk_cancel_items", controller: :customer_orders, action: :bulk_cancel_items
16
53
  end
17
54
  end
18
55
  resources :currencies
19
56
  resources :units
20
57
  resources :users
21
- resources :clients
58
+ resources :clients do
59
+ member do
60
+ get "rfq_products", controller: :quotation_requests, action: :rfq_products_for_client
61
+ end
62
+ end
22
63
  post "/client_prices/filter", controller: :client_prices, action: :filter
23
64
  resources :client_prices
24
65
  post "/back_orders/filter", controller: :back_orders, action: :filter
@@ -27,4 +68,17 @@ Comee::Core::Engine.routes.draw do
27
68
  post "submit"
28
69
  end
29
70
  end
71
+ resources :sales_order_items, except: [:index]
72
+ post "/sales_orders/filter", controller: :sales_orders, action: :filter
73
+ resources :sales_orders do
74
+ collection do
75
+ post "create_back_order", action: :create_back_order
76
+ end
77
+ member do
78
+ get "items", controller: :sales_order_items, action: :index
79
+ get "/sales_order/filter/", controller: :sales_orders, action: :filter
80
+ post "confirm"
81
+ post "cancel"
82
+ end
83
+ end
30
84
  end
@@ -4,20 +4,12 @@ class CreateComeeCoreProducts < ActiveRecord::Migration[7.0]
4
4
  t.string :code, null: false
5
5
  t.string :name, null: false
6
6
  t.string :description
7
- t.jsonb :metadata
8
- t.references :product_type,
9
- null: false,
10
- index: {name: "ccpt_on_ccp_indx"},
11
- foreign_key: {to_table: :comee_core_product_types}
12
- t.references :unit,
13
- null: false,
14
- index: {name: "unit_on_ccp_indx"},
15
- foreign_key: {to_table: :comee_core_units}
16
- t.string "ancestry", collation: "C"
17
- t.index "ancestry"
7
+ t.boolean :leaf, null: false, default: true
8
+ t.string :ancestry
18
9
 
19
10
  t.timestamps
20
11
  end
21
12
  add_index :comee_core_products, :code, unique: true
13
+ add_index :comee_core_products, :ancestry
22
14
  end
23
15
  end
@@ -16,6 +16,7 @@ class CreateComeeCoreCustomerOrderItems < ActiveRecord::Migration[7.1]
16
16
  t.float :quantity, null: false, default: 0
17
17
  t.float :price, null: false, default: 0
18
18
  t.date :delivery_date, null: false
19
+ t.boolean :canceled, default: false
19
20
 
20
21
  t.timestamps
21
22
  end
@@ -8,10 +8,10 @@ class CreateComeeCoreSalesOrders < ActiveRecord::Migration[7.0]
8
8
  foreign_key: {to_table: :comee_core_customer_orders}
9
9
  t.float :payment_penalty, null: false, default: 0.0
10
10
  t.integer :status, null: false, default: 0
11
- t.float :total_price, null: true, default: 0
12
- t.float :amount_paid, null: true, default: 0
13
- t.string :pallete_note, null: false
14
- t.date :handover_date, null: false
11
+ t.float :total_price, null: false, default: 0
12
+ t.float :amount_paid, null: false, default: 0
13
+ t.string :pallete_note
14
+ t.date :handover_date
15
15
  t.string :remark
16
16
 
17
17
  t.timestamps
@@ -17,7 +17,8 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
17
17
  t.float :quantity_delivered, null: false, default: 0
18
18
  t.float :price, null: false
19
19
  t.date :delivery_date, null: false
20
- t.integer :eb_number
20
+ t.date :handover_date
21
+ t.string :eb_number
21
22
 
22
23
  t.timestamps
23
24
  end
@@ -0,0 +1,15 @@
1
+ class CreateComeeCoreQuotationRequests < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :comee_core_quotation_requests do |t|
4
+ t.string :reference_no, null: false
5
+ t.references :client,
6
+ null: false,
7
+ index: {name: "client_on_ccrfq_indx"},
8
+ foreign_key: {to_table: :comee_core_clients}
9
+ t.integer :status, null: false, default: 0
10
+
11
+ t.timestamps
12
+ end
13
+ add_index :comee_core_quotation_requests, :reference_no, unique: true
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ class CreateComeeCoreQuotationRequestItems < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :comee_core_quotation_request_items do |t|
4
+ t.references :product,
5
+ null: false,
6
+ index: {name: "product_on_ccrfqi_indx"},
7
+ foreign_key: {to_table: :comee_core_products}
8
+ t.references :quotation_request,
9
+ null: false,
10
+ index: {name: "rfq_on_ccrfqi_indx"},
11
+ foreign_key: {to_table: :comee_core_quotation_requests}
12
+ t.float :quantity, null: false
13
+ t.float :price, null: false, default: 0
14
+ t.float :discount, null: false, default: 0
15
+ t.date :expected_delivery_date, null: false
16
+ t.boolean :canceled, null: false, default: false
17
+ t.references :unit,
18
+ null: false,
19
+ index: {name: "unit_on_ccrfqi_indx"},
20
+ foreign_key: {to_table: :comee_core_units}
21
+ t.date :valid_from, null: true
22
+ t.date :valid_to, null: true
23
+
24
+ t.timestamps
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ class CreateComeeCoreExternalRfqs < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :comee_core_external_rfqs do |t|
4
+ t.integer :status, null: false, default: 0
5
+ t.jsonb :data, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ class CreateComeeCorePurchaseOrders < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :comee_core_purchase_orders do |t|
4
+ t.references :supplier,
5
+ null: false,
6
+ index: {name: "suppliers_on_ccpo_indx"},
7
+ foreign_key: {to_table: :comee_core_suppliers}
8
+ t.date :order_date, default: Date.today
9
+ t.integer :status, default: 0
10
+ t.string :delivery_address, null: false
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ class CreateComeeCorePurchaseOrderItems < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :comee_core_purchase_order_items do |t|
4
+ t.references :purchase_order,
5
+ null: false,
6
+ index: {name: "pos_on_ccpoitm_indx"},
7
+ foreign_key: {to_table: :comee_core_purchase_orders}
8
+
9
+ t.references :sales_order_item,
10
+ null: false,
11
+ index: {name: "soi_on_ccpoitm_indx"},
12
+ foreign_key: {to_table: :comee_core_sales_order_items}
13
+ t.float :quantity, null: false
14
+ t.date :delivery_date, null: false
15
+ t.integer :status, null: false, default: 0
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.40".freeze
3
+ VERSION = "0.1.41".freeze
4
4
  end
5
5
  end
data/lib/comee_core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "comee/core/version"
2
2
  require "comee/core/engine"
3
3
  require "active_model_serializers"
4
+ require "ancestry"
4
5
  require "jwt"
5
6
  require "ransack"
6
7
  require "noticed"
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  quantity { 1 }
7
7
  price { 1.5 }
8
8
  delivery_date { Date.current }
9
+ canceled { false }
9
10
 
10
11
  trait :with_inventory do
11
12
  after(:create) do |item|
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :external_rfq, class: "Comee::Core::ExternalRfq" do
3
+ data { {payload: ""} }
4
+ status { 1 }
5
+ end
6
+ end
@@ -1,11 +1,12 @@
1
1
  FactoryBot.define do
2
2
  factory :product, class: "Comee::Core::Product" do
3
+ transient do
4
+ root { Comee::Core::Product.where(code: "ROOT", name: "Products", leaf: false).first_or_create }
5
+ end
3
6
  sequence(:code) { |n| "#{Faker::Alphanumeric.unique.alpha(number: 6)}-#{n}" }
4
7
  name { Faker::Name.name }
5
8
  description { Faker::Lorem.sentence }
6
- metadata { {} }
7
- product_type
8
- unit
9
- ancestry { nil }
9
+ leaf { true }
10
+ ancestry { root.id.to_s }
10
11
  end
11
12
  end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :purchase_order_item, class: "Comee::Core::PurchaseOrderItem" do
3
+ purchase_order
4
+ sales_order_item
5
+ quantity { 10 }
6
+ delivery_date { Date.current.advance(days: 7) }
7
+ status { 0 }
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :purchase_order, class: "Comee::Core::PurchaseOrder" do
3
+ supplier
4
+ order_date { Date.current }
5
+ status { 0 }
6
+ delivery_address { "Korsu warehouse address" }
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ FactoryBot.define do
2
+ factory :quotation_request_item, class: "Comee::Core::QuotationRequestItem" do
3
+ product
4
+ quotation_request
5
+ unit
6
+ quantity { 10 }
7
+ price { 0 }
8
+ discount { 0 }
9
+ expected_delivery_date { Date.current.advance(days: 15) }
10
+ canceled { false }
11
+ valid_from { nil }
12
+ valid_to { nil }
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :quotation_request, class: "Comee::Core::QuotationRequest" do
3
+ reference_no { "RFQ-#{client.code}-#{DateTime.now.to_i}" }
4
+ client
5
+ status { 0 }
6
+ end
7
+ end
@@ -7,6 +7,7 @@ FactoryBot.define do
7
7
  quantity_delivered { 0 }
8
8
  price { 50 }
9
9
  delivery_date { Date.current.advance(months: 1) }
10
- eb_number { 100 }
10
+ handover_date { Date.current }
11
+ eb_number { Faker::Lorem.word }
11
12
  end
12
13
  end
@@ -7,7 +7,6 @@ FactoryBot.define do
7
7
  amount_paid { 0 }
8
8
  status { Comee::Core::SalesOrder.statuses[:draft] }
9
9
  pallete_note { Faker::Lorem.sentence }
10
- handover_date { Date.current }
11
10
  remark { Faker::Lorem.sentence }
12
11
  end
13
12
  end