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

时间:2017-03-16 13:40:56

标签: python openerp odoo-10

方法我想跳过

@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中,它是一个基类,所以我不能改变它,所以我想执行我正确的方法。怎么做?

1 个答案:

答案 0 :(得分:0)

class my_product_class (models.Model):

_inherit="product.template"


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

这里我继承了类在返回方法中,假设要覆盖的类的名称