stock.picking的sale_id无法调用的问题
未解决
Odoo 新手求助
-
from odoo import api, fields, models, _
class StockPickingInherit(models.Model):
_inherit = "stock.picking"x_partner_ref = fields.Char(string='流水号', compute='_compute_partner_ref', store=True) @api.depends('purchase_id.partner_ref', 'sale_id.x_serial') def _compute_partner_ref(self): for picking in self: if picking.purchase_id: picking.x_partner_ref = picking.purchase_id.partner_ref elif picking.sale_id: picking.x_partner_ref = picking.sale_id.x_serial else: picking.x_partner_ref = False
在上面代码中会报这个错误:
ValueError: Wrong @depends on '_compute_partner_ref' (compute method of field stock.picking.x_partner_ref). Dependency field 'sale_id' not found in model stock.picking.
但是用下面这个方法就没问题:@api.depends('purchase_id.partner_ref') def _compute_partner_ref(self): for picking in self: if picking.purchase_id: picking.x_partner_ref = picking.purchase_id.partner_ref else: picking.x_partner_ref = False
是不是在stock.picking中需要扩展sale_id字段?请问应该如何改造?
-
@billchen0769 请问,这个问题解决了么?建议在发贴时说明你使用的odoo版本。