至于问题
我有代码
<t t-set="get_data_remain" t-value="o.execute_sql('
SELECT
SUM(a.qty) totalQty,
a.product_id,
b.name
FROM marketing_forecast_remain a
INNER JOIN product_template b
ON a.product_id = b.id
WHERE a.marketing_forecast_id = 65
GROUP BY a.product_id, b.name
ORDER BY b.name
;
')"/>
我在.py中调用函数来从view(xml)
执行我的sql问题是我想要查询我的查询参数值(WHERE条件)
WHERE a.marketing_forecast_id = 65
是
WHERE a.marketing_forecast_id = value of id field (field value from .py)
有人请帮帮我吗?
提前感谢。
*如果我错了,请纠正我
答案 0 :(得分:0)
你可以尝试,
<t t-set="get_data_remain" t-value="o.execute_sql('
SELECT
SUM(a.qty) totalQty,
a.product_id,
b.name
FROM marketing_forecast_remain a
INNER JOIN product_template b
ON a.product_id = b.id
WHERE a.marketing_forecast_id = %s
GROUP BY a.product_id, b.name
ORDER BY b.name
;
') %value"/>
<t t-set="get_data_remain" t-value="o.execute_sql('
SELECT
SUM(a.qty) totalQty,
a.product_id,
b.name
FROM marketing_forecast_remain a
INNER JOIN product_template b
ON a.product_id = b.id
WHERE a.marketing_forecast_id = value
GROUP BY a.product_id, b.name
ORDER BY b.name
;
')"/>
replace value with your field
答案 1 :(得分:0)
[<强>解决强>
我将查询移至 .py ,所以我不需要努力在xml中创建条件
def execute_sql(self):
query = "SELECT SUM(a.qty) totalQty, a.product_id, b.name " \
"FROM marketing_forecast_remain a " \
"INNER JOIN product_template b " \
"ON a.product_id = b.id " \
"WHERE a.marketing_forecast_id = %s " \
"GROUP BY a.product_id, b.name " \
"ORDER BY b.name;"
param = [self.id]
self._cr.execute(query,param)
_hasil = self._cr.dictfetchall()
return _hasil
%s 这是我设置的参数然后我通过此代码给出值
param = [self.id]
self._cr.execute(query,param)
所以在我看来(xml)我只需要调用这样的方法
<t t-set="get_data_remain" t-value="o.execute_sql()"/>
感谢。