mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[stock_analysis_forecast] Capitalize all the SQL keywords
This commit is contained in:
@@ -24,40 +24,40 @@ class ReportStockForecast(models.Model):
|
||||
|
||||
def init(self, cr):
|
||||
tools.drop_view_if_exists(cr, 'report_stock_forecast')
|
||||
cr.execute("""CREATE or REPLACE VIEW report_stock_forecast AS (SELECT
|
||||
MIN(id) as id,
|
||||
product_id as product_id,
|
||||
date as date,
|
||||
cr.execute("""CREATE OR REPLACE VIEW report_stock_forecast AS (SELECT
|
||||
MIN(id) AS id,
|
||||
product_id AS product_id,
|
||||
date AS date,
|
||||
sum(product_qty) AS quantity,
|
||||
sum(in_quantity) AS incoming_quantity,
|
||||
sum(out_quantity) AS outgoing_quantity,
|
||||
location_id
|
||||
FROM
|
||||
(SELECT
|
||||
MIN(id) as id,
|
||||
MAIN.product_id as product_id,
|
||||
MAIN.location_id as location_id,
|
||||
SUB.date as date,
|
||||
MIN(id) AS id,
|
||||
MAIN.product_id AS product_id,
|
||||
MAIN.location_id AS location_id,
|
||||
SUB.date AS date,
|
||||
CASE WHEN MAIN.date = SUB.date
|
||||
THEN sum(MAIN.product_qty) ELSE 0 END as product_qty,
|
||||
THEN sum(MAIN.product_qty) ELSE 0 END AS product_qty,
|
||||
CASE WHEN MAIN.date = SUB.date
|
||||
THEN sum(MAIN.in_quantity) ELSE 0 END as in_quantity,
|
||||
THEN sum(MAIN.in_quantity) ELSE 0 END AS in_quantity,
|
||||
CASE WHEN MAIN.date = SUB.date
|
||||
THEN sum(MAIN.out_quantity) ELSE 0 END as out_quantity
|
||||
THEN sum(MAIN.out_quantity) ELSE 0 END AS out_quantity
|
||||
FROM
|
||||
(SELECT
|
||||
MIN(sq.id) as id,
|
||||
MIN(sq.id) AS id,
|
||||
sq.product_id,
|
||||
date_trunc(
|
||||
'week',
|
||||
to_date(to_char(CURRENT_DATE, 'YYYY/MM/DD'),
|
||||
'YYYY/MM/DD')) as date,
|
||||
'YYYY/MM/DD')) AS date,
|
||||
SUM(sq.qty) AS product_qty,
|
||||
0 AS in_quantity,
|
||||
0 AS out_quantity,
|
||||
sq.location_id
|
||||
FROM
|
||||
stock_quant as sq
|
||||
stock_quant AS sq
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = sq.product_id
|
||||
LEFT JOIN
|
||||
@@ -67,7 +67,7 @@ class ReportStockForecast(models.Model):
|
||||
GROUP BY date, sq.product_id, sq.location_id
|
||||
UNION ALL
|
||||
SELECT
|
||||
MIN(-sm.id) as id,
|
||||
MIN(-sm.id) AS id,
|
||||
sm.product_id,
|
||||
CASE WHEN sm.date_expected > CURRENT_DATE
|
||||
THEN date_trunc(
|
||||
@@ -82,9 +82,9 @@ class ReportStockForecast(models.Model):
|
||||
0 AS product_qty,
|
||||
SUM(sm.product_qty) AS in_quantity,
|
||||
0 AS out_quantity,
|
||||
dest_location.id as location_id
|
||||
dest_location.id AS location_id
|
||||
FROM
|
||||
stock_move as sm
|
||||
stock_move AS sm
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = sm.product_id
|
||||
LEFT JOIN
|
||||
@@ -94,13 +94,13 @@ class ReportStockForecast(models.Model):
|
||||
stock_location source_location
|
||||
ON sm.location_id = source_location.id
|
||||
WHERE
|
||||
sm.state IN ('confirmed','assigned','waiting') and
|
||||
source_location.usage != 'internal' and
|
||||
sm.state IN ('confirmed','assigned','waiting') AND
|
||||
source_location.usage != 'internal' AND
|
||||
dest_location.usage = 'internal'
|
||||
GROUP BY sm.date_expected, sm.product_id, dest_location.id
|
||||
UNION ALL
|
||||
SELECT
|
||||
MIN(-sm.id) as id,
|
||||
MIN(-sm.id) AS id,
|
||||
sm.product_id,
|
||||
CASE WHEN sm.date_expected > CURRENT_DATE
|
||||
THEN date_trunc(
|
||||
@@ -115,9 +115,9 @@ class ReportStockForecast(models.Model):
|
||||
0 AS product_qty,
|
||||
0 AS in_quantity,
|
||||
SUM(sm.product_qty) AS out_quantity,
|
||||
source_location.id as location_id
|
||||
source_location.id AS location_id
|
||||
FROM
|
||||
stock_move as sm
|
||||
stock_move AS sm
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = sm.product_id
|
||||
LEFT JOIN
|
||||
@@ -127,11 +127,11 @@ class ReportStockForecast(models.Model):
|
||||
stock_location dest_location
|
||||
ON sm.location_dest_id = dest_location.id
|
||||
WHERE
|
||||
sm.state IN ('confirmed','assigned','waiting') and
|
||||
source_location.usage = 'internal' and
|
||||
sm.state IN ('confirmed','assigned','waiting') AND
|
||||
source_location.usage = 'internal' AND
|
||||
dest_location.usage != 'internal'
|
||||
GROUP BY sm.date_expected, sm.product_id, source_location.id)
|
||||
as MAIN
|
||||
AS MAIN
|
||||
LEFT JOIN
|
||||
(SELECT DISTINCT date
|
||||
FROM
|
||||
@@ -150,13 +150,13 @@ class ReportStockForecast(models.Model):
|
||||
stock_location dest_location
|
||||
ON sm.location_dest_id = dest_location.id
|
||||
WHERE
|
||||
sm.state IN ('confirmed','assigned','waiting') and
|
||||
sm.date_expected > CURRENT_DATE and
|
||||
sm.state IN ('confirmed','assigned','waiting') AND
|
||||
sm.date_expected > CURRENT_DATE AND
|
||||
((dest_location.usage = 'internal'
|
||||
AND source_location.usage != 'internal')
|
||||
or (source_location.usage = 'internal'
|
||||
OR (source_location.usage = 'internal'
|
||||
AND dest_location.usage != 'internal'))) AS DATE_SEARCH)
|
||||
SUB ON (SUB.date IS NOT NULL)
|
||||
GROUP BY MAIN.product_id,SUB.date, MAIN.date, MAIN.location_id
|
||||
GROUP BY MAIN.product_id, SUB.date, MAIN.date, MAIN.location_id
|
||||
) AS FINAL
|
||||
GROUP BY product_id,date, location_id)""")
|
||||
GROUP BY product_id, date, location_id)""")
|
||||
|
||||
Reference in New Issue
Block a user