fix: 出入库查询视图 (#936)

Co-authored-by: lyx <2027667395@qq.com>
Reviewed-on: daoyoucloud/tachybase#936
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: hello@lv <2256334253@qq.com>
Co-committed-by: hello@lv <2256334253@qq.com>
This commit is contained in:
hello@lv 2024-05-08 23:08:59 +08:00 committed by sealday
parent 62bfe29825
commit 11e235b429

View File

@ -24,13 +24,15 @@ FROM
ELSE r.in_stock_id
END
)
WHERE
r.direct_record_id IS NULL
UNION ALL
SELECT
NULL AS contract_id,
r.id AS record_id,
r."createdAt",
r."updatedAt",
CAST('r_' || r.id AS VARCHAR) AS id,
CAST('r_' || r.id || '_' || c.id AS VARCHAR) AS id,
NULL AS rc_id,
(
CASE
@ -49,12 +51,17 @@ FROM
JOIN project p ON p.id = r.in_stock_id
JOIN project p2 ON p2.id = r.out_stock_id
JOIN company c ON c.roles @> '["associated"]'
AND c.id = p.company_id
OR c.id = p2.company_id
AND (
c.id = p.company_id
OR c.id = p2.company_id
)
JOIN project p3 ON p3.company_id = c.id
AND p3.id = p.id
OR p3.id = p2.id
AND (
p3.id = p.id
OR p3.id = p2.id
)
WHERE
rc.id IS NULL
AND r.in_stock_id IS NOT NULL
AND r.out_stock_id IS NOT NULL
AND r.direct_record_id IS NULL