我想尝试从销售订单模块中的服务器操作执行查询,并在"更多"菜单中添加操作,但单击操作时发现错误我尝试单独查询数据库并执行良好服务器操作中的 Python 代码:
if context.get('active_model') == 'sales.order' and context.get('active_ids'):
self.Invoiced(cr, uid, context['active_ids'], context=context)
def Invoiced(self):
for item in self:
self.env.cr.execute('update sale_order_line as l set qty_invoiced = l.product_uom_qty FROM sale_order s where l.order_id = s.id and s.state = "done"')
self.deadline = self.env.cr.fetchone()
错误:
Odoo 服务器错误
语法错误:扫描字符串文本时 EOL
在 postgresSql 中,您不能对字符串值使用双引号:
像这样使用双引号
SELECT
name as "full name" // here because i'm puttin a space inside the name of the column
您的查询应如下所示:
self.env.cr.execute("""
update sale_order_line as l set qty_invoiced = l.product_uom_qty FROM sale_order s where l.order_id = s.id and s.state = 'done'
""")
使用三引号,以便您可以将查询拆分为多行,以格式化代码以使其更具可读性。 对不起,我的英语^^。