comee_core 0.1.96 → 0.1.98
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/agents_controller.rb +13 -0
- data/app/controllers/comee/core/application_controller.rb +15 -2
- data/app/controllers/comee/core/back_orders_controller.rb +2 -2
- data/app/controllers/comee/core/client_prices_controller.rb +3 -10
- data/app/controllers/comee/core/client_warehouses_controller.rb +13 -0
- data/app/controllers/comee/core/clients_controller.rb +42 -9
- data/app/controllers/comee/core/contacts_controller.rb +13 -0
- data/app/controllers/comee/core/customer_order_items_controller.rb +3 -2
- data/app/controllers/comee/core/customer_orders_controller.rb +3 -3
- data/app/controllers/comee/core/item_statuses_controller.rb +2 -2
- data/app/controllers/comee/core/notifications_controller.rb +4 -4
- data/app/controllers/comee/core/product_lookups_controller.rb +2 -2
- data/app/controllers/comee/core/products_controller.rb +7 -9
- data/app/controllers/comee/core/purchase_order_items_controller.rb +2 -2
- data/app/controllers/comee/core/purchase_orders_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_requests_controller.rb +8 -9
- data/app/controllers/comee/core/sales_order_items_controller.rb +1 -1
- data/app/controllers/comee/core/sales_orders_controller.rb +13 -7
- data/app/controllers/comee/core/shipment_items_controller.rb +13 -13
- data/app/controllers/comee/core/suppliers_controller.rb +4 -6
- data/app/controllers/comee/core/unit_conversions_controller.rb +1 -1
- data/app/controllers/comee/core/units_controller.rb +1 -1
- data/app/controllers/concerns/comee/core/common.rb +33 -7
- data/app/models/comee/core/agent.rb +7 -0
- data/app/models/comee/core/client.rb +4 -1
- data/app/models/comee/core/client_warehouse.rb +8 -0
- data/app/models/comee/core/contact.rb +7 -0
- data/app/models/comee/core/customer_order_item.rb +6 -0
- data/app/models/comee/core/master_price.rb +1 -0
- data/app/models/comee/core/price.rb +2 -1
- data/app/models/comee/core/sales_order.rb +1 -2
- data/app/models/comee/core/sales_order_item.rb +6 -1
- data/app/models/comee/core/supplier.rb +2 -0
- data/app/serializers/comee/core/agent_serializer.rb +7 -0
- data/app/serializers/comee/core/client_serializer.rb +4 -1
- data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
- data/app/serializers/comee/core/contact_serializer.rb +7 -0
- data/app/serializers/comee/core/product_serializer.rb +2 -2
- data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
- data/app/serializers/comee/core/supplier_serializer.rb +1 -0
- data/app/services/comee/core/customer_order_service.rb +7 -2
- data/config/routes.rb +7 -1
- data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
- data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
- data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
- data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
- data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
- data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
- data/db/migrate/20230813235946_create_comee_core_master_prices.rb +2 -1
- data/db/migrate/20230814151601_create_comee_core_client_prices.rb +2 -1
- data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/agents.rb +8 -0
- data/spec/factories/comee/core/client_prices.rb +1 -1
- data/spec/factories/comee/core/client_warehouses.rb +8 -0
- data/spec/factories/comee/core/clients.rb +2 -1
- data/spec/factories/comee/core/contacts.rb +8 -0
- data/spec/factories/comee/core/customer_order_items.rb +1 -0
- data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
- data/spec/factories/comee/core/master_prices.rb +1 -0
- data/spec/factories/comee/core/sales_order_items.rb +1 -0
- data/spec/factories/comee/core/suppliers.rb +1 -0
- metadata +35 -12
- data/app/models/comee/core/warehouse_shipment.rb +0 -70
- data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
- data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
- data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
- data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
- data/spec/factories/comee/core/warehouse_shipments.rb +0 -9
@@ -3,7 +3,10 @@ module Comee
|
|
3
3
|
class Client < ApplicationRecord
|
4
4
|
belongs_to :user, optional: true
|
5
5
|
belongs_to :parent, class_name: "Comee::Core::Client", optional: true
|
6
|
-
|
6
|
+
belongs_to :currency, optional: true
|
7
|
+
has_and_belongs_to_many :contacts, join_table: :comee_core_clients_contacts
|
8
|
+
has_and_belongs_to_many :agents, join_table: :comee_core_clients_agents
|
9
|
+
has_many :client_warehouses
|
7
10
|
|
8
11
|
validates :code, :name, :address, :locale, presence: true
|
9
12
|
validates :code, uniqueness: true
|
@@ -1,12 +1,18 @@
|
|
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 }
|
5
|
+
|
4
6
|
belongs_to :customer_order
|
5
7
|
belongs_to :product
|
6
8
|
belongs_to :unit
|
7
9
|
|
8
10
|
validates :customer_item_no, :quantity, :price, :delivery_date, presence: true
|
9
11
|
|
12
|
+
def calculate_total_price
|
13
|
+
self.total_price = price * quantity
|
14
|
+
end
|
15
|
+
|
10
16
|
def self.ransackable_attributes(_auth_object = nil)
|
11
17
|
%w[id customer_order_id product_id unit_id]
|
12
18
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class MasterPrice < Price
|
4
|
+
enum :price_status, {draft: 0, approved: 1}
|
4
5
|
belongs_to :supplier
|
5
6
|
belongs_to :previous_price, class_name: "Comee::Core::MasterPrice", optional: true
|
6
7
|
belongs_to :next_price, class_name: "Comee::Core::MasterPrice", optional: true
|
@@ -5,6 +5,7 @@ module Comee
|
|
5
5
|
before_save :compute_status
|
6
6
|
|
7
7
|
enum :status, {past: 0, current: 1, future: 2}
|
8
|
+
enum :price_status, {draft: 0, approved: 1}
|
8
9
|
|
9
10
|
scope :current, -> { where(status: Price.statuses[:current]) }
|
10
11
|
scope :future, -> { where(status: Price.statuses[:future]) }
|
@@ -12,7 +13,7 @@ module Comee
|
|
12
13
|
belongs_to :product
|
13
14
|
belongs_to :unit
|
14
15
|
|
15
|
-
validates :valid_from, :valid_to, presence: true
|
16
|
+
validates :price_status, :valid_from, :valid_to, presence: true
|
16
17
|
validate :validate_price_validity_dates
|
17
18
|
|
18
19
|
def validate_price_validity_dates
|
@@ -26,8 +26,7 @@ module Comee
|
|
26
26
|
|
27
27
|
def total_price
|
28
28
|
sales_order_items = SalesOrderItem.where(sales_order_id: id)
|
29
|
-
total_price = sales_order_items.sum(&:
|
30
|
-
self.total_price = total_price
|
29
|
+
self.total_price = sales_order_items.sum(&:total_price)
|
31
30
|
end
|
32
31
|
|
33
32
|
def set_parent_client_name
|
@@ -1,18 +1,23 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class SalesOrderItem < ApplicationRecord
|
4
|
+
before_save :calculate_total_price
|
5
|
+
|
4
6
|
belongs_to :sales_order
|
5
7
|
belongs_to :customer_order_item
|
6
8
|
belongs_to :product
|
7
9
|
belongs_to :unit
|
8
10
|
belongs_to :source, class_name: "Comee::Core::FulfillmentCenter", optional: true
|
9
|
-
# has_many :warehouse_shipment_items
|
10
11
|
has_many :shipment_items
|
11
12
|
|
12
13
|
validates :customer_item_no, :delivery_date, presence: true
|
13
14
|
validates :quantity, :price, presence: true, numericality: {greater_than: 0}
|
14
15
|
validates :quantity_delivered, numericality: {greater_than_or_equal_to: 0}
|
15
16
|
|
17
|
+
def calculate_total_price
|
18
|
+
self.total_price = price * quantity
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.ransackable_attributes(_auth_object = nil)
|
17
22
|
%w[
|
18
23
|
id
|
@@ -2,6 +2,8 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class Supplier < ApplicationRecord
|
4
4
|
belongs_to :user, optional: true
|
5
|
+
belongs_to :currency, optional: true
|
6
|
+
has_and_belongs_to_many :contacts, join_table: :comee_core_suppliers_contacts
|
5
7
|
|
6
8
|
validates :code, presence: true, uniqueness: true
|
7
9
|
validates :name, :address, :locale, presence: true
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class ClientSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :code, :name, :address, :locale, :user_id, :user_name, :consignees, :shipment_addresses
|
4
|
+
attributes :id, :code, :name, :address, :locale, :user_id, :user_name, :consignees, :shipment_addresses, :currency
|
5
5
|
belongs_to :parent
|
6
|
+
has_many :agents
|
7
|
+
has_many :contacts
|
8
|
+
has_many :client_warehouses
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class ProductSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :code, :name, :description, :thumbnail_image_url, :images_url, :preferred_units, :weight,
|
5
|
-
:hs_description
|
4
|
+
attributes :id, :code, :name, :description, :thumbnail_image_url, :images_url, :preferred_units, :weight,
|
5
|
+
:dimensions, :hs_code, :hs_description
|
6
6
|
belongs_to :source
|
7
7
|
belongs_to :weight_unit
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class SalesOrderItemSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :customer_item_no, :quantity, :quantity_delivered, :price, :handover_date, :delivery_date, :eb_number,
|
5
|
-
:lead_time, :comment, :action_note, :po_reference
|
5
|
+
:lead_time, :comment, :action_note, :po_reference, :total_price
|
6
6
|
|
7
7
|
belongs_to :sales_order
|
8
8
|
belongs_to :customer_order_item
|
@@ -8,7 +8,11 @@ module Comee
|
|
8
8
|
order_params = params.except(:items)
|
9
9
|
order = Comee::Core::CustomerOrder.create(**order_params)
|
10
10
|
items = params.slice(:items)[:items]
|
11
|
-
items.each
|
11
|
+
items.each do |item|
|
12
|
+
item[:customer_order_id] = order.id
|
13
|
+
item[:total_price] = item[:quantity] * item[:price] unless item.key?(:total_price) && !item[:total_price].nil?
|
14
|
+
end
|
15
|
+
|
12
16
|
Comee::Core::CustomerOrderItem.insert_all!(items)
|
13
17
|
end
|
14
18
|
order
|
@@ -81,7 +85,7 @@ module Comee
|
|
81
85
|
|
82
86
|
price = convert_price(master_price.selling_price, master_price.unit_id, new_unit_id)
|
83
87
|
end
|
84
|
-
{quantity: quantity, price: price}
|
88
|
+
{quantity: quantity, price: price, total_price: quantity * price}
|
85
89
|
end
|
86
90
|
|
87
91
|
def submit(id)
|
@@ -171,6 +175,7 @@ module Comee
|
|
171
175
|
customer_item_no: item.product.code,
|
172
176
|
quantity: quantity,
|
173
177
|
price: price,
|
178
|
+
total_price: quantity * price,
|
174
179
|
delivery_date: item.delivery_date,
|
175
180
|
lead_time: master_price&.lead_time
|
176
181
|
}
|
data/config/routes.rb
CHANGED
@@ -8,6 +8,7 @@ Comee::Core::Engine.routes.draw do
|
|
8
8
|
post "mark_as_unread", controller: :notifications, action: :mark_as_unread
|
9
9
|
end
|
10
10
|
end
|
11
|
+
resources :contacts
|
11
12
|
resources :suppliers do
|
12
13
|
collection do
|
13
14
|
post "filter"
|
@@ -82,13 +83,16 @@ Comee::Core::Engine.routes.draw do
|
|
82
83
|
get "rfq_products", controller: :quotation_requests, action: :rfq_products_for_client
|
83
84
|
get "prices", controller: :client_prices, action: :fetch_for_client
|
84
85
|
get "consignees"
|
85
|
-
get "
|
86
|
+
get "agents"
|
86
87
|
get "shipment_items", controller: :shipment_items, action: :filter_for_client
|
88
|
+
post "create_agent"
|
89
|
+
post "create_contact"
|
87
90
|
end
|
88
91
|
collection do
|
89
92
|
post "filter"
|
90
93
|
end
|
91
94
|
end
|
95
|
+
resources :agents
|
92
96
|
post "/client_prices/filter", controller: :client_prices, action: :filter
|
93
97
|
resources :client_prices
|
94
98
|
post "/back_orders/filter", controller: :back_orders, action: :filter
|
@@ -127,4 +131,6 @@ Comee::Core::Engine.routes.draw do
|
|
127
131
|
end
|
128
132
|
end
|
129
133
|
resources :fulfillment_centers
|
134
|
+
|
135
|
+
resources :client_warehouses
|
130
136
|
end
|
@@ -5,6 +5,10 @@ class CreateComeeCoreSuppliers < ActiveRecord::Migration[7.0]
|
|
5
5
|
t.string :name, null: false
|
6
6
|
t.string :address, null: false
|
7
7
|
t.string :locale, null: false, default: "en"
|
8
|
+
t.references :currency,
|
9
|
+
null: true,
|
10
|
+
index: {name: "currency_on_ccs_indx"},
|
11
|
+
foreign_key: {to_table: :comee_core_currencies}
|
8
12
|
t.references :user,
|
9
13
|
null: true,
|
10
14
|
index: {name: "user_on_ccs_indx"},
|
@@ -15,6 +15,10 @@ class CreateComeeCoreClients < ActiveRecord::Migration[7.0]
|
|
15
15
|
foreign_key: {to_table: :comee_core_clients}
|
16
16
|
t.string :consignees, array: true, default: []
|
17
17
|
t.string :shipment_addresses, array: true, default: []
|
18
|
+
t.references :currency,
|
19
|
+
null: true,
|
20
|
+
index: {name: "currency_on_ccc_indx"},
|
21
|
+
foreign_key: {to_table: :comee_core_currencies}
|
18
22
|
|
19
23
|
t.timestamps
|
20
24
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateComeeCoreAgents < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :comee_core_agents do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :address
|
6
|
+
t.string :email, null: false
|
7
|
+
t.string :telephone, null: false
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :comee_core_clients_agents, id: false do |t|
|
13
|
+
t.references :client,
|
14
|
+
null: false,
|
15
|
+
index: {name: "client_on_ccca_indx"},
|
16
|
+
foreign_key: {to_table: :comee_core_clients}
|
17
|
+
t.references :agent,
|
18
|
+
null: false,
|
19
|
+
index: {name: "agent_on_ccca_indx"},
|
20
|
+
foreign_key: {to_table: :comee_core_agents}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class CreateComeeCoreContacts < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :comee_core_contacts do |t|
|
4
|
+
t.string :first_name, null: false
|
5
|
+
t.string :last_name, null: false
|
6
|
+
t.string :email, null: false
|
7
|
+
t.string :telephone, null: false
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :comee_core_suppliers_contacts, id: false do |t|
|
13
|
+
t.references :supplier,
|
14
|
+
null: false,
|
15
|
+
index: {name: "supplier_on_ccsc_indx"},
|
16
|
+
foreign_key: {to_table: :comee_core_suppliers}
|
17
|
+
t.references :contact,
|
18
|
+
null: false,
|
19
|
+
index: {name: "sc_on_ccsc_indx"},
|
20
|
+
foreign_key: {to_table: :comee_core_contacts}
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table :comee_core_clients_contacts, id: false do |t|
|
24
|
+
t.references :client,
|
25
|
+
null: false,
|
26
|
+
index: {name: "client_on_ccsc_indx"},
|
27
|
+
foreign_key: {to_table: :comee_core_clients}
|
28
|
+
t.references :contact,
|
29
|
+
null: false,
|
30
|
+
index: {name: "cc_on_ccsc_indx"},
|
31
|
+
foreign_key: {to_table: :comee_core_contacts}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -16,6 +16,7 @@ class CreateComeeCoreCustomerOrderItems < ActiveRecord::Migration[7.1]
|
|
16
16
|
t.string :customer_item_no, null: false
|
17
17
|
t.float :quantity, null: false, default: 0
|
18
18
|
t.float :price, null: false, default: 0
|
19
|
+
t.float :total_price, null: false, default: 0
|
19
20
|
t.date :delivery_date, null: false
|
20
21
|
t.boolean :canceled, default: false
|
21
22
|
|
@@ -25,6 +25,7 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
|
|
25
25
|
t.float :quantity, null: false
|
26
26
|
t.float :quantity_delivered, null: false, default: 0
|
27
27
|
t.float :price, null: false
|
28
|
+
t.float :total_price, null: false
|
28
29
|
t.date :delivery_date, null: false
|
29
30
|
t.boolean :canceled, default: false
|
30
31
|
t.date :handover_date
|
@@ -5,7 +5,8 @@ class CreateComeeCoreMasterPrices < ActiveRecord::Migration[7.0]
|
|
5
5
|
t.float :selling_price, null: false
|
6
6
|
t.date :valid_from, null: false
|
7
7
|
t.date :valid_to, null: false
|
8
|
-
t.
|
8
|
+
t.integer :status, null: false, default: 0
|
9
|
+
t.integer :price_status, null: false, default: 0
|
9
10
|
t.boolean :primary, null: false, default: false
|
10
11
|
t.float :margin, null: false, default: 0
|
11
12
|
t.integer :lead_time
|
@@ -4,7 +4,8 @@ class CreateComeeCoreClientPrices < ActiveRecord::Migration[7.0]
|
|
4
4
|
t.date :valid_from, null: false
|
5
5
|
t.date :valid_to, null: false
|
6
6
|
t.float :price, null: false
|
7
|
-
t.
|
7
|
+
t.integer :status, null: false, default: 0
|
8
|
+
t.integer :price_status, null: false, default: 0
|
8
9
|
t.float :margin, null: false, default: 0
|
9
10
|
t.integer :margin_type, null: false, default: 0
|
10
11
|
t.references :product,
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateComeeCoreClientWarehouses < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :comee_core_client_warehouses do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :description
|
6
|
+
t.string :address, null: false
|
7
|
+
t.references :client,
|
8
|
+
null: false,
|
9
|
+
index: {name: "client_on_cccw_indx"},
|
10
|
+
foreign_key: {to_table: :comee_core_clients}
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/comee/core/version.rb
CHANGED
@@ -2,7 +2,7 @@ FactoryBot.define do
|
|
2
2
|
factory :client_price, class: "Comee::Core::ClientPrice" do
|
3
3
|
valid_from { Date.current.advance(months: -1) }
|
4
4
|
valid_to { Date.current.advance(months: 1) }
|
5
|
-
|
5
|
+
price_status { Comee::Core::Price.price_statuses[:draft] }
|
6
6
|
price { 100 }
|
7
7
|
product
|
8
8
|
client
|
@@ -1,12 +1,13 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :client, class: "Comee::Core::Client" do
|
3
3
|
user
|
4
|
-
code { Faker::Alphanumeric.unique.alpha(number: 8) }
|
4
|
+
sequence(:code) { |n| "#{Faker::Alphanumeric.unique.alpha(number: 8)}-#{n}" }
|
5
5
|
name { Faker::Name.name }
|
6
6
|
address { Faker::Address.full_address }
|
7
7
|
locale { "en" }
|
8
8
|
parent { nil }
|
9
9
|
consignees { [] }
|
10
10
|
shipment_addresses { [] }
|
11
|
+
currency
|
11
12
|
end
|
12
13
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :fulfillment_center, class: "Comee::Core::FulfillmentCenter" do
|
3
|
-
code { Faker::Alphanumeric.alpha(number: 10) }
|
3
|
+
sequence(:code) { |n| "#{Faker::Alphanumeric.unique.alpha(number: 10)}-#{n}" }
|
4
4
|
name { Faker::Name.name }
|
5
5
|
address { Faker::Address.street_address }
|
6
6
|
email { Faker::Internet.email }
|