python - Run self._cr.execute on Compute Field
问题描述
On Odoo 12, Im trying run self._cr.execute
on compute but return me Null
, I tried domain and is working but because the Query i will use is complex i need to do it with SQL Query.
_inherit ='purchase.order.line'
partner1 = fields.Many2one('res.partner', string='Vendor 1', compute='_compute_vendors', copy = True, store=True, readonly= False)
partner2 = fields.Many2one('res.partner', string='Vendor 2', compute='_compute_vendors', copy = True, store=True, readonly= False)
partner3 = fields.Many2one('res.partner', string='Vendor 3', compute='_compute_vendors', copy = True, store=True, readonly= False)
@api.depends('product_id')
def _compute_vendors(self):
vendors = []
vendors.append(self._cr.execute("""SELECT partner_id FROM purchase_order_line"""))
Any solution?
解决方案
执行 return None
,检索您可以使用 fetchall 的选定记录:
# first execute the query
self._cr.execute("""SELECT partner_id FROM purchase_order_line""")
# fetc rows
vendors = [r[0] for r in self._cr.fetchall()]
推荐阅读
- optimization - 具有多个节点访问的 VRP(车辆路由问题)
- mysql - 由于处理程序中的 yml 格式错误,Rails 延迟的工作人员崩溃
- mysql - 回滚试运行事务后无法继续执行进一步操作
- javascript - 在渲染的图像上绘制线条和形状的最佳解决方案
- react-native - 在 react-navigation 中获取 Stack.Navigator 上的屏幕加载事件
- spring - KafkaStreams:自定义 JsonSerge
- node.js - 打字稿:代码看起来正确,编译器抱怨
- mfc - 如何将 CListCtrl 中的 CheckBox 设置为不可用?
- android - 如何使用 MockK 使用私有方法模拟 Android Worker
- html - 如何在使用 django 小部件调整时包含 oninvalid 属性?