Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Lead each exported purchase order row with the order, then the line
Damian Legawieceddf41036b17
diff --git a/spree/core/app/presenters/spree/csv/purchase_order_item_presenter.rb b/spree/core/app/presenters/spree/csv/purchase_order_item_presenter.rbindex 03ac0cc288..d017dd6bcf 100644--- a/spree/core/app/presenters/spree/csv/purchase_order_item_presenter.rb+++ b/spree/core/app/presenters/spree/csv/purchase_order_item_presenter.rb@@ -1,11 +1,13 @@module Spreemodule CSV- # One purchase order line as a CSV row, with its order's header alongside.- # The first columns match the import schema, so an exported file re-imports.+ # One purchase order line as a CSV row: the order it belongs to, then the+ # line, then what has happened to it. Every import-schema column is here+ # under its own name, so an exported file re-imports as it stands.class PurchaseOrderItemPresenterHEADERS = %w[- reference supplier destination sku quantity unit_cost currency expected_at cancel_by notes- number status product_name received rejected+ number status reference supplier destination+ sku product_name quantity received rejected unit_cost currency+ expected_at cancel_by notes].freezedef initialize(item)@@ -18,21 +20,21 @@ module Spreeorder = item.purchase_order[+ order.number,+ order.status,order.reference,order.supplier&.name,order.destination_location&.name,item.variant&.sku,+ item.variant&.product&.name,item.quantity_ordered,+ item.quantity_received,+ item.quantity_rejected,amount_string(item.unit_cost, order.currency),order.currency,order.expected_at&.iso8601,order.cancel_by&.iso8601,- order.notes,- order.number,- order.status,- item.variant&.product&.name,- item.quantity_received,- item.quantity_rejected+ order.notes]enddiff --git a/spree/core/spec/models/spree/exports/purchase_orders_spec.rb b/spree/core/spec/models/spree/exports/purchase_orders_spec.rbindex 69662073b8..08d7056568 100644--- a/spree/core/spec/models/spree/exports/purchase_orders_spec.rb+++ b/spree/core/spec/models/spree/exports/purchase_orders_spec.rb@@ -27,9 +27,7 @@ RSpec.describe Spree::Exports::PurchaseOrders, type: :model dorows = CSV.parse(export.attachment.download, headers: true)expect(rows.headers).to eq(Spree::CSV::PurchaseOrderItemPresenter::HEADERS)- expect(rows.headers.first(Spree::ImportSchemas::PurchaseOrders.new.headers.size)).to eq(- Spree::ImportSchemas::PurchaseOrders.new.headers- )+ expect(rows.headers).to include(*Spree::ImportSchemas::PurchaseOrders.new.headers)row = rows.sole.to_hexpect(row).to include(@@ -41,6 +39,21 @@ RSpec.describe Spree::Exports::PurchaseOrders, type: :model do)end+ it 'writes every line of an order as its own row, under the same number' do+ other_variant = create(:variant, product: product, sku: 'DENIM-L')+ purchase_order.items.create!(variant: other_variant, quantity_ordered: 6, unit_cost: 13)++ export = build_export+ export.save!+ export.generate++ rows = CSV.parse(export.attachment.download, headers: true)+ expect(rows.map { |row| row.values_at('number', 'sku', 'quantity') }).to contain_exactly(+ [purchase_order.number, 'DENIM-M', '24'],+ [purchase_order.number, 'DENIM-L', '6']+ )+ end+it 'narrows to the orders a filter names' doother = create(:purchase_order, store: store)