check qt
This commit is contained in:
@@ -21,9 +21,11 @@ Rules checked:
|
||||
Rows linked to a purchase lot and rows without purchase lot are both
|
||||
included.
|
||||
|
||||
Zero lot_qt rows are allowed when they keep the memory of an open quantity
|
||||
consumed by a physical lot, as long as at least lot_p or lot_s is set. Unlinked
|
||||
lot_qt rows are reported as anomalies.
|
||||
Zero lot_qt rows are completely ignored by the checks. They may be the memory
|
||||
of an open quantity consumed by a physical lot. This also matters when the
|
||||
virtual lot becomes negative to compensate the difference between theoretical
|
||||
and executed quantity: lot_qt represents usable open forecast and stops at
|
||||
zero.
|
||||
|
||||
Notes:
|
||||
- The script uses the lot current state, i.e. lot_lot.lot_state joined to
|
||||
@@ -354,13 +356,17 @@ FROM (
|
||||
b.line_id,
|
||||
b.virtual_lot_id,
|
||||
ROUND(b.lot_qt_quantity, 5) AS observed_value,
|
||||
ROUND(COALESCE(b.virtual_quantity, 0), 5) AS expected_value,
|
||||
ROUND(b.lot_qt_quantity - COALESCE(b.virtual_quantity, 0), 5) AS diff,
|
||||
'sum lot_qt where lot_p = virtual lot must equal virtual lot quantity'
|
||||
ROUND(GREATEST(COALESCE(b.virtual_quantity, 0), 0), 5) AS expected_value,
|
||||
ROUND(
|
||||
b.lot_qt_quantity
|
||||
- GREATEST(COALESCE(b.virtual_quantity, 0), 0), 5) AS diff,
|
||||
'sum non-zero lot_qt where lot_p = virtual lot must equal positive virtual lot quantity'
|
||||
AS detail
|
||||
FROM purchase_lot_qt_balance b, params p
|
||||
WHERE b.lot_qt_cross_category_count = 0
|
||||
AND ABS(b.lot_qt_quantity - COALESCE(b.virtual_quantity, 0)) > p.epsilon
|
||||
AND ABS(
|
||||
b.lot_qt_quantity
|
||||
- GREATEST(COALESCE(b.virtual_quantity, 0), 0)) > p.epsilon
|
||||
|
||||
UNION ALL
|
||||
|
||||
@@ -372,13 +378,17 @@ FROM (
|
||||
b.line_id,
|
||||
b.virtual_lot_id,
|
||||
ROUND(b.lot_qt_quantity, 5) AS observed_value,
|
||||
ROUND(COALESCE(b.virtual_quantity, 0), 5) AS expected_value,
|
||||
ROUND(b.lot_qt_quantity - COALESCE(b.virtual_quantity, 0), 5) AS diff,
|
||||
'sum lot_qt where lot_s = virtual lot must equal virtual lot quantity'
|
||||
ROUND(GREATEST(COALESCE(b.virtual_quantity, 0), 0), 5) AS expected_value,
|
||||
ROUND(
|
||||
b.lot_qt_quantity
|
||||
- GREATEST(COALESCE(b.virtual_quantity, 0), 0), 5) AS diff,
|
||||
'sum non-zero lot_qt where lot_s = virtual lot must equal positive virtual lot quantity'
|
||||
AS detail
|
||||
FROM sale_lot_qt_balance b, params p
|
||||
WHERE b.lot_qt_cross_category_count = 0
|
||||
AND ABS(b.lot_qt_quantity - COALESCE(b.virtual_quantity, 0)) > p.epsilon
|
||||
AND ABS(
|
||||
b.lot_qt_quantity
|
||||
- GREATEST(COALESCE(b.virtual_quantity, 0), 0)) > p.epsilon
|
||||
|
||||
UNION ALL
|
||||
|
||||
@@ -460,10 +470,11 @@ FROM (
|
||||
COALESCE(lqt.lot_quantity, 0)::numeric AS observed_value,
|
||||
0::numeric AS expected_value,
|
||||
COALESCE(lqt.lot_quantity, 0)::numeric AS diff,
|
||||
'lot_qt row has neither lot_p nor lot_s; zero rows are allowed only when linked to at least one virtual lot'
|
||||
'non-zero lot_qt row has neither lot_p nor lot_s'
|
||||
AS detail
|
||||
FROM lot_qt lqt
|
||||
WHERE lqt.lot_p IS NULL
|
||||
AND lqt.lot_s IS NULL
|
||||
AND COALESCE(lqt.lot_quantity, 0) <> 0
|
||||
) issues
|
||||
ORDER BY check_name, contract_number, line_id, virtual_lot_id;
|
||||
|
||||
Reference in New Issue
Block a user