From 67cb341768091e9c7d0781fb05a3fdbd82b960b6 Mon Sep 17 00:00:00 2001 From: Erik Huelsmann Date: Tue, 22 Sep 2020 21:09:54 +0200 Subject: [PATCH 1/2] Fix #5107: Searches not limited by serial number Please note that I chose to remove the underscore from the intermediate layers instead of changing the top layer (report filter input) for consistency with the other fields (e.g. 'partnumber' which also does not have an underscore in it). --- lib/LedgerSMB/Report/Inventory/History.pm | 2 +- lib/LedgerSMB/Report/Inventory/Search.pm | 4 ++-- sql/modules/Goods.sql | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/LedgerSMB/Report/Inventory/History.pm b/lib/LedgerSMB/Report/Inventory/History.pm index 059dd68502..e7adccc4b4 100644 --- a/lib/LedgerSMB/Report/Inventory/History.pm +++ b/lib/LedgerSMB/Report/Inventory/History.pm @@ -48,7 +48,7 @@ This is a serial number of the part, for a prefix search =cut -has serial_number => (is => 'ro', isa => 'Str', required => 0); +has serialnumber => (is => 'ro', isa => 'Str', required => 0); =item inc_is bool diff --git a/lib/LedgerSMB/Report/Inventory/Search.pm b/lib/LedgerSMB/Report/Inventory/Search.pm index ff0e670eaa..f2d64c544b 100644 --- a/lib/LedgerSMB/Report/Inventory/Search.pm +++ b/lib/LedgerSMB/Report/Inventory/Search.pm @@ -58,13 +58,13 @@ Limit search to partsgroup specified has partsgroup_id => (is => 'ro', isa => 'Int', required => 0); -=item serial_number text +=item serialnumber text This is a serial number of the part, for a prefix search =cut -has serial_number => (is => 'ro', isa => 'Str', required => 0); +has serialnumber => (is => 'ro', isa => 'Str', required => 0); =item make diff --git a/sql/modules/Goods.sql b/sql/modules/Goods.sql index e04c1e902d..305a88d13c 100644 --- a/sql/modules/Goods.sql +++ b/sql/modules/Goods.sql @@ -133,7 +133,7 @@ DROP FUNCTION IF EXISTS goods__search CREATE OR REPLACE FUNCTION goods__search (in_parttype text, in_partnumber text, in_description text, - in_partsgroup_id int, in_serial_number text, in_make text, + in_partsgroup_id int, in_serialnumber text, in_make text, in_model text, in_drawing text, in_microfiche text, in_status text, in_date_from date, in_date_to date) RETURNS SETOF goods_search_result @@ -160,10 +160,9 @@ LANGUAGE SQL STABLE AS $$ AND (in_drawing IS NULL OR p.drawing ilike in_drawing || '%') AND (in_microfiche IS NULL OR p.microfiche ilike in_microfiche || '%') - AND (in_serial_number IS NULL OR p.id IN + AND (in_serialnumber IS NULL OR p.id IN (select parts_id from invoice - where in_serial_number is not null - and serialnumber = in_serial_number)) + where serialnumber = in_serialnumber)) AND (in_parttype IS NULL OR (in_parttype = 'assemblies' and p.assembly) OR (in_parttype = 'services' @@ -489,12 +488,12 @@ name text, sellprice numeric, qty numeric, discount numeric, -serial_number text +serialnumber text ); CREATE OR REPLACE FUNCTION goods__history( in_date_from date, in_date_to date, - in_partnumber text, in_description text, in_serial_number text, + in_partnumber text, in_description text, in_serialnumber text, in_inc_po bool, in_inc_so bool, in_inc_quo bool, in_inc_rfq bool, in_inc_is bool, in_inc_ir bool ) RETURNS SETOF parts_history_result LANGUAGE SQL AS @@ -530,6 +529,7 @@ $$ OR p.description @@ plainto_tsquery(in_description)) AND (in_date_from is null or in_date_from <= o.transdate) and (in_date_to is null or in_date_to >= o.transdate) + AND (in_serialnumber is null or i.serialnumber = in_serialnumber) AND ((in_inc_po IS NULL AND in_inc_so IS NULL AND in_inc_quo IS NULL AND in_inc_rfq IS NULL AND in_inc_ir IS NULL AND in_inc_is IS NULL) From 3c9dd249c8e5607bed580e3966b2a2b129a49e1f Mon Sep 17 00:00:00 2001 From: Erik Huelsmann Date: Tue, 22 Sep 2020 21:36:07 +0200 Subject: [PATCH 2/2] Support upgrading of databases with the old function definitions --- sql/modules/Goods.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sql/modules/Goods.sql b/sql/modules/Goods.sql index 305a88d13c..533a9e87ab 100644 --- a/sql/modules/Goods.sql +++ b/sql/modules/Goods.sql @@ -131,6 +131,13 @@ DROP FUNCTION IF EXISTS goods__search in_model text, in_drawing text, in_microfiche text, in_status text, in_date_from date, in_date_to date); +DROP FUNCTION IF EXISTS goods__search +(in_parttype text, in_partnumber text, in_description text, + in_partsgroup_id int, in_serial_number text, in_make text, + in_model text, in_drawing text, in_microfiche text, + in_status text, in_date_from date, in_date_to date); + + CREATE OR REPLACE FUNCTION goods__search (in_parttype text, in_partnumber text, in_description text, in_partsgroup_id int, in_serialnumber text, in_make text, @@ -491,6 +498,13 @@ discount numeric, serialnumber text ); +DROP FUNCTION IF EXISTS goods__history( + in_date_from date, in_date_to date, + in_partnumber text, in_description text, in_serial_number text, + in_inc_po bool, in_inc_so bool, in_inc_quo bool, in_inc_rfq bool, + in_inc_is bool, in_inc_ir bool +); + CREATE OR REPLACE FUNCTION goods__history( in_date_from date, in_date_to date, in_partnumber text, in_description text, in_serialnumber text,