python-3.x - 如何从 odoo 11 和 postgresql 中的数据库中获取相关字段值?

标签 python-3.x postgresql odoo-11

我试图从数据库中获取相关字段值,但它显示列“column_name”不存在

当我尝试找出 product_id 的值或使用 join 查找 sale.order 和 product.product Model 之间的公共(public)数据时。但它显示列“column_name”不存在。

在 sale.order 模型中,字段定义类似于

product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product')

但是当我尝试像下面的代码那样连接两个表以根据产品获取所有数据时,就像下面的代码一样。

select coalesce(p.name,'Unassigned Product'), count(*) from sale_order o left join product_product p on o.product_id = p.id where o.state = 'sale' group by p.name;

它显示以下错误,

column o.product_id does not exist
LINE 1: ... from sale_order o left join product_product p on o.product_...

当我尝试像下面的代码一样从 sale_order 表中获取数据时。

select product_id from sale_order; 

它显示以下错误。

column "product_id" does not exist

任何人都可以帮助我获得该值。

最佳答案

要从数据库访问相关字段,您必须使用 store=True 关键字。 将您的字段定义重写为,

product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product', store=True)

然后卸载和安装模块。

关于python-3.x - 如何从 odoo 11 和 postgresql 中的数据库中获取相关字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807028/

相关文章:

python - CMD 自动完成无法正常工作

python - 在 kivy 标签上生成随机数

SQL group by 无聚合

crash - 奥多 11 : Cant update module because new template was added to the module

javascript - 如何在 Odoo 11 中通过 do_action() java 脚本方法显示 action_id

python - 如何在 View 中的 Odoo 11 中从组标签中删除标签

python - 程序将我发送到错误功能,如何将其更改为ItayVAT?

python - 循环字典列表时无法转换数据类型

python - Django 南迁移失败

sql - 如何在 postgresql 和 rails 3 中按月分组