【发布时间】:2019-02-19 20:08:24
【问题描述】:
我正在开发 odoo 版本 11。我创建了一个名为 test 的视图。我升级了模块。稍后我需要进行一些更改,包括更改一些值和删除一些值。每当我尝试升级模块时,我都会收到错误
psycopg2.OperationalError:无法从视图“测试”中删除详细信息: 包含 GROUP BY 的视图不会自动更新。提示:至 启用从视图中删除,提供 INSTEAD OF DELETE 触发器或 一个无条件的 ON DELETE DO INSTEAD 规则。
如何提供规则?我的代码如下
@api.model_cr
def init(self):
cr = self.env.cr
tools.drop_view_if_exists(cr, 'o_test')
cr.execute("""
CREATE or replace view o_test as
(
SELECT
mve.id as id,
acc.code as account_code,
SUM (mve.debit-mve.credit) AS balance,
mve.account_id as account_id
FROM account_move_line mve
LEFT JOIN account_account acc ON mve.account_id = acc.id
GROUP BY mve.id,mve.account_id,acc.code
)
""")
我想把代码改成如下:
@api.model_cr
def init(self):
cr = self.env.cr
tools.drop_view_if_exists(cr, 'o_test')
cr.execute("""
CREATE or replace view o_test as
(
SELECT
mve.account_id as id,
acc.code as account_code,
SUM (mve.debit-mve.credit) AS balance,
mve.account_id as account_id
FROM account_move_line mve
LEFT JOIN account_account acc ON mve.account_id = acc.id
GROUP BY mve.account_id,acc.code
)
""")
【问题讨论】:
标签: python-3.x postgresql psycopg2 odoo-11