我是odoo的新手,当我在继承的sale_order_line类中添加一个函数时,我收到了这个错误。下面是代码。能不能让我知道我在哪里犯了大错?
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)],
change_default=True, ondelete='restrict', required=True)
salesman_id = fields.Char(string='Salesman')
@api.onchange(product_id)
@api.depends(salesman_id)
def user_id_tracking(self):
print '$$$$$$$$$$$$$$$$$$', self.product_id
self.env.cr.execute("""SELECT user_id FROM stock_location as sl WHERE sl.id in
(SELECT sq.location_id FROM stock_change_product_qty as sq,product_template as pt
WHERE sq.product_id = %d)""", self.product_id)
res = self.env.cr.fetchone()
self.salesman_id = res[0]
lot_id = fields.Many2one('stock.production.lot', string='Lot/Serial Number', copy=False)
答案 0 :(得分:1)
当你改变salesman_id
时,你正在告诉odoo触发这个功能,并且在你改变同一个字段的内部,所以odoo会继续调用你的方法。
remove depends decorator because you are using it the wrong way use it only for compute field.
只需保留onchange
而不是set
依赖于的相同字段来计算字段值。