mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
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:
@@ -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?
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user