簡體   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