在odoo10中创建新对象后,如何调用我的方法?

2024-04-20 10:02:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是我从模块继承来的奥多10股票数量我添加了一个新属性和一个新方法。 我希望我的方法在每次在中创建一个新对象后执行股票数量. 这是我的密码 谢谢你的帮助

class stock_quant(models.Model):
    _inherit = 'stock.quant'
    inventory_value_charge = fields.Float('Total Value',store=True,compute='update_stock_value')

    @api.one
    @api.depends('qty')
    def update_stock_value(self):
        stock_price_obj = self.env['stock.price.partition'].search([('id', '!=', False)])
        val_obj = stock_price_obj.search([('reception.pack_operation_product_ids.pack_lot_ids.lot_id.id', '=', self.lot_id.id)])
        if val_obj!= False:
            val_obj.calccule_price()
        else:
            self.inventory_value_charge=self.inventory_value
        #stock_price_obj = self.env['stock.price.partition'].search([('reception.pack_operation_product_ids.pack_lot_ids.lot_id.id', '=', self.lot_id.id)])
        return True

    @api.model
    def create(self, vals):
        res = super(stock_quant, self).create(vals)
        self.update_stock_value()
        return res

Tags: selfapiidobjidssearchvaluestock
2条回答

像这样改变你的创建函数

@api.model
def create(self, vals):
    res = super(stock_quant, self).create(vals)
    res.update_stock_value()
    return res

首先计算字段,不必调用 方法,因为它在 创建呼叫。在write call中也是如此,但前提是更改了qty字段。在

所以删除您第二次调用的create方法。在

现在确保通过添加一些print调用来调用您的方法,如果 你不知道如何在IDE中使用debug。在

确保在__init__文件中导入模块。在

相关问题 更多 >