在 xml odoo 上连接字符串和字段值
Concatenate string and field value on xml odoo
进入问题的重点
我有密码
<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 中的函数从视图 (xml)
中执行我的 sql
问题是我想更改查询参数的值(WHERE 条件)
WHERE a.marketing_forecast_id = 65
成为
WHERE a.marketing_forecast_id = value of id field (field value from .py)
有人帮帮我吗?
提前致谢。
*如有错误请指正
你可以试试,
<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
[已解决]
我将我的查询移动到 .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()"/>
谢谢。
进入问题的重点
我有密码
<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 中的函数从视图 (xml)
中执行我的 sql问题是我想更改查询参数的值(WHERE 条件)
WHERE a.marketing_forecast_id = 65
成为
WHERE a.marketing_forecast_id = value of id field (field value from .py)
有人帮帮我吗?
提前致谢。
*如有错误请指正
你可以试试,
<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
[已解决]
我将我的查询移动到 .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()"/>
谢谢。