[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:
Nicolas Seinlet 2015-10-22 15:37:06 +02:00 committed by Denis Ledoux
parent 29bd622521
commit 5c9897a83f
1 changed files with 22 additions and 16 deletions

View File

@ -130,7 +130,6 @@ class stock_history(osv.osv):
FROM
((SELECT
stock_move.id AS id,
quant.id AS quant_id,
stock_move.id AS move_id,
dest_location.id AS location_id,
dest_location.company_id AS company_id,
@ -141,17 +140,21 @@ class stock_history(osv.osv):
quant.cost as price_unit_on_quant,
stock_move.origin AS source
FROM
stock_quant as quant, stock_quant_move_rel, stock_move
LEFT JOIN
stock_move
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
LEFT JOIN
JOIN
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
LEFT JOIN
JOIN
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
AND stock_quant_move_rel.move_id = stock_move.id AND (
WHERE quant.qty>0 AND stock_move.state = 'done' AND dest_location.usage in ('internal', 'transit')
AND (
(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 != dest_location.company_id or
@ -159,7 +162,6 @@ class stock_history(osv.osv):
) UNION ALL
(SELECT
(-1) * stock_move.id AS id,
quant.id AS quant_id,
stock_move.id AS move_id,
source_location.id AS location_id,
source_location.company_id AS company_id,
@ -170,17 +172,21 @@ class stock_history(osv.osv):
quant.cost as price_unit_on_quant,
stock_move.origin AS source
FROM
stock_quant as quant, stock_quant_move_rel, stock_move
LEFT JOIN
stock_move
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
LEFT JOIN
JOIN
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
LEFT JOIN
JOIN
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
AND stock_quant_move_rel.move_id = stock_move.id AND (
WHERE quant.qty>0 AND stock_move.state = 'done' AND source_location.usage in ('internal', 'transit')
AND (
(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 != source_location.company_id or