繁体   English   中英

覆盖一次odoo版本10 python的写入

[英]overwrite write for once odoo version 10 python

方法我想跳过

@api.multi
def write(self, vals):
    if 'uom_id' in vals:
        new_uom = self.env['product.uom'].browse(vals['uom_id'])
        updated = self.filtered(lambda template: template.uom_id != new_uom)
        done_moves = self.env['stock.move'].search([('product_id', 'in', updated.mapped('product_variant_ids').ids)], limit=1)
        if done_moves:
            raise UserError(_("You can not change the unit of measure of a product that has already been used in a done stock move. If you need to change the unit of measure, you may deactivate this product."))
    return super(ProductTemplate, self).write(vals)

方法我想执行:

@api.multi
def write(self, vals):
    if 'uom_id' in vals:
        new_uom = self.env['product.uom'].browse(vals['uom_id'])
        updated = self.filtered(lambda template: template.uom_id != new_uom)
        done_moves = self.env['stock.move'].search([('product_id', 'in', updated.mapped('product_variant_ids').ids)], limit=1)
    print("@")   
    return super(my_product_class, self).write(vals)\

第一个write方法是在product.py中,它是一个基类,所以我不能改变它,所以我想执行我正确的方法。 这个怎么做?

class my_product_class (models.Model):

_inherit="product.template"


@api.multi
def write(self, vals):
    print(" ")
    return super(**ProductTemplate**, self).write(vals)

在这里我继承了类在返回方法中,该类的名称被假定为覆盖

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM