[IMP] stock_account: rework on stock_history view joins
- Replace `LEFT JOIN` by simple `JOIN` for required fields - Use `JOIN ... ON (...)` syntax instead of implicit join `A.X = B.Y` - Remove of unused column quant_id Closes #9197 opw-650598
This commit is contained in:
parent
29bd622521
commit
5c9897a83f
|
@ -130,7 +130,6 @@ class stock_history(osv.osv):
|
||||||
FROM
|
FROM
|
||||||
((SELECT
|
((SELECT
|
||||||
stock_move.id AS id,
|
stock_move.id AS id,
|
||||||
quant.id AS quant_id,
|
|
||||||
stock_move.id AS move_id,
|
stock_move.id AS move_id,
|
||||||
dest_location.id AS location_id,
|
dest_location.id AS location_id,
|
||||||
dest_location.company_id AS company_id,
|
dest_location.company_id AS company_id,
|
||||||
|
@ -141,17 +140,21 @@ class stock_history(osv.osv):
|
||||||
quant.cost as price_unit_on_quant,
|
quant.cost as price_unit_on_quant,
|
||||||
stock_move.origin AS source
|
stock_move.origin AS source
|
||||||
FROM
|
FROM
|
||||||
stock_quant as quant, stock_quant_move_rel, stock_move
|
stock_move
|
||||||
LEFT JOIN
|
JOIN
|
||||||
|
stock_quant_move_rel on stock_quant_move_rel.move_id = stock_move.id
|
||||||
|
JOIN
|
||||||
|
stock_quant as quant on stock_quant_move_rel.quant_id = quant.id
|
||||||
|
JOIN
|
||||||
stock_location dest_location ON stock_move.location_dest_id = dest_location.id
|
stock_location dest_location ON stock_move.location_dest_id = dest_location.id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
stock_location source_location ON stock_move.location_id = source_location.id
|
stock_location source_location ON stock_move.location_id = source_location.id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
product_product ON product_product.id = stock_move.product_id
|
product_product ON product_product.id = stock_move.product_id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
product_template ON product_template.id = product_product.product_tmpl_id
|
product_template ON product_template.id = product_product.product_tmpl_id
|
||||||
WHERE quant.qty>0 AND stock_move.state = 'done' AND dest_location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id
|
WHERE quant.qty>0 AND stock_move.state = 'done' AND dest_location.usage in ('internal', 'transit')
|
||||||
AND stock_quant_move_rel.move_id = stock_move.id AND (
|
AND (
|
||||||
(source_location.company_id is null and dest_location.company_id is not null) or
|
(source_location.company_id is null and dest_location.company_id is not null) or
|
||||||
(source_location.company_id is not null and dest_location.company_id is null) or
|
(source_location.company_id is not null and dest_location.company_id is null) or
|
||||||
source_location.company_id != dest_location.company_id or
|
source_location.company_id != dest_location.company_id or
|
||||||
|
@ -159,7 +162,6 @@ class stock_history(osv.osv):
|
||||||
) UNION ALL
|
) UNION ALL
|
||||||
(SELECT
|
(SELECT
|
||||||
(-1) * stock_move.id AS id,
|
(-1) * stock_move.id AS id,
|
||||||
quant.id AS quant_id,
|
|
||||||
stock_move.id AS move_id,
|
stock_move.id AS move_id,
|
||||||
source_location.id AS location_id,
|
source_location.id AS location_id,
|
||||||
source_location.company_id AS company_id,
|
source_location.company_id AS company_id,
|
||||||
|
@ -170,17 +172,21 @@ class stock_history(osv.osv):
|
||||||
quant.cost as price_unit_on_quant,
|
quant.cost as price_unit_on_quant,
|
||||||
stock_move.origin AS source
|
stock_move.origin AS source
|
||||||
FROM
|
FROM
|
||||||
stock_quant as quant, stock_quant_move_rel, stock_move
|
stock_move
|
||||||
LEFT JOIN
|
JOIN
|
||||||
|
stock_quant_move_rel on stock_quant_move_rel.move_id = stock_move.id
|
||||||
|
JOIN
|
||||||
|
stock_quant as quant on stock_quant_move_rel.quant_id = quant.id
|
||||||
|
JOIN
|
||||||
stock_location source_location ON stock_move.location_id = source_location.id
|
stock_location source_location ON stock_move.location_id = source_location.id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
stock_location dest_location ON stock_move.location_dest_id = dest_location.id
|
stock_location dest_location ON stock_move.location_dest_id = dest_location.id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
product_product ON product_product.id = stock_move.product_id
|
product_product ON product_product.id = stock_move.product_id
|
||||||
LEFT JOIN
|
JOIN
|
||||||
product_template ON product_template.id = product_product.product_tmpl_id
|
product_template ON product_template.id = product_product.product_tmpl_id
|
||||||
WHERE quant.qty>0 AND stock_move.state = 'done' AND source_location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id
|
WHERE quant.qty>0 AND stock_move.state = 'done' AND source_location.usage in ('internal', 'transit')
|
||||||
AND stock_quant_move_rel.move_id = stock_move.id AND (
|
AND (
|
||||||
(dest_location.company_id is null and source_location.company_id is not null) or
|
(dest_location.company_id is null and source_location.company_id is not null) or
|
||||||
(dest_location.company_id is not null and source_location.company_id is null) or
|
(dest_location.company_id is not null and source_location.company_id is null) or
|
||||||
dest_location.company_id != source_location.company_id or
|
dest_location.company_id != source_location.company_id or
|
||||||
|
|
Loading…
Reference in New Issue