mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user