Merge pull request #9575 from apricot12/9487-Dimensions-Packing-Reports

Added HEIGHT, WEIGHT, WIDTH, DEPTH columns to packing reports by customer.
This commit is contained in:
Filipe
2022-11-10 09:55:26 +00:00
committed by GitHub
8 changed files with 62 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ module Spree
before_validation :adjust_quantity
before_validation :copy_price
before_validation :copy_tax_category
before_validation :copy_dimensions
validates :variant, presence: true
validates :quantity, numericality: {
@@ -122,6 +123,15 @@ module Spree
self.tax_category = variant.product.tax_category
end
def copy_dimensions
return unless variant
self.weight ||= computed_weight_from_variant
self.height ||= variant.height
self.width ||= variant.width
self.depth ||= variant.depth
end
def amount
price * quantity
end
@@ -226,6 +236,14 @@ module Spree
private
def computed_weight_from_variant
if variant.product.variant_unit == "weight"
variant.unit_value / variant.product.variant_unit_scale
else
variant.weight
end
end
def update_inventory
return unless changed?

View File

@@ -2840,6 +2840,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_delivery_postcode: Delivery Postcode
report_header_bulk_unit_size: Bulk Unit Size
report_header_weight: Weight
report_header_height: Height
report_header_width: Width
report_header_depth: Depth
report_header_sum_total: Sum Total
report_header_date_of_order: Date of Order
report_header_amount_owing: Amount Owing

View File

@@ -0,0 +1,8 @@
class AddDimensionsToLineItems < ActiveRecord::Migration[6.1]
def change
add_column :spree_line_items, :weight, :decimal, precision: 8, scale: 2
add_column :spree_line_items, :height, :decimal, precision: 8, scale: 2
add_column :spree_line_items, :width, :decimal, precision: 8, scale: 2
add_column :spree_line_items, :depth, :decimal, precision: 8, scale: 2
end
end

View File

@@ -523,6 +523,10 @@ ActiveRecord::Schema.define(version: 2022_10_07_105052) do
t.decimal "distribution_fee", precision: 10, scale: 2
t.decimal "final_weight_volume", precision: 10, scale: 2
t.integer "tax_category_id"
t.decimal "weight", precision: 8, scale: 2
t.decimal "height", precision: 8, scale: 2
t.decimal "width", precision: 8, scale: 2
t.decimal "depth", precision: 8, scale: 2
t.index ["order_id"], name: "index_line_items_on_order_id"
t.index ["variant_id"], name: "index_line_items_on_variant_id"
end

View File

@@ -38,7 +38,7 @@ module Reporting
private
def select_fields
def select_fields # rubocop:disable Metrics/AbcSize
lambda do
{
hub: distributor_alias[:name],
@@ -49,6 +49,10 @@ module Reporting
supplier: supplier_alias[:name],
product: product_table[:name],
variant: variant_full_name,
weight: line_item_table[:weight],
height: line_item_table[:height],
width: line_item_table[:width],
depth: line_item_table[:depth],
quantity: line_item_table[:quantity],
price: (line_item_table[:quantity] * line_item_table[:price]),
temp_controlled: shipping_category_table[:temperature_controlled],

View File

@@ -7,7 +7,8 @@ module Reporting
def columns
# Reorder default columns
super.slice(:hub, :customer_code, :first_name, :last_name, :phone,
:supplier, :product, :variant, :quantity, :price, :temp_controlled)
:supplier, :product, :variant, :weight, :height, :width, :depth, :quantity,
:price, :temp_controlled)
end
def rules

View File

@@ -66,16 +66,15 @@ describe Api::V0::ReportsController, type: :controller do
{
"hub" => line_item.order.distributor.name,
"customer_code" => line_item.order.customer&.code,
"first_name" => line_item.order.bill_address.firstname,
"last_name" => line_item.order.bill_address.lastname,
"supplier" => line_item.product.supplier.name,
"product" => line_item.product.name,
"variant" => line_item.full_name,
"quantity" => line_item.quantity,
"price" => (line_item.quantity * line_item.price).to_s,
"phone" => line_item.order.bill_address.phone,
"temp_controlled" => line_item.product.shipping_category&.temperature_controlled
}
}.
merge(dimensions(line_item)).
merge(contacts(line_item.order.bill_address))
end
def supplier_report_row(line_item)
@@ -91,6 +90,23 @@ describe Api::V0::ReportsController, type: :controller do
"quantity" => line_item.quantity,
"price" => (line_item.quantity * line_item.price).to_s,
"temp_controlled" => line_item.product.shipping_category&.temperature_controlled
}.merge(dimensions(line_item))
end
def dimensions(line_item)
{
"weight" => line_item.weight.to_s,
"height" => line_item.height.to_s,
"width" => line_item.width.to_s,
"depth" => line_item.depth.to_s
}
end
def contacts(bill_address)
{
"first_name" => bill_address.firstname,
"last_name" => bill_address.lastname,
"phone" => bill_address.phone,
}
end

View File

@@ -61,7 +61,8 @@ describe "Packing Reports" do
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table).to eq([
["Hub", "Customer Code", "First Name", "Last Name", "Supplier",
"Product", "Variant", "Quantity", "TempControlled?"].map(&:upcase)
"Product", "Variant", "Weight", "Height", "Width", "Depth",
"Quantity", "TempControlled?"].map(&:upcase)
])
expect(page).to have_selector 'table.report__table tbody tr', count: 5 # Totals row per order
end