Odoo中的One2many小部件上的事件on-delete

问题描述 投票:1回答:1

我有一个one2many小部件,当用户删除任何行时,我需要有一个条件。

是否有我可以覆盖的on删除方法?我已经尝试过使用unlink方法,但是one2many小部件无法执行它。并且该行仍被删除。

<field context="{'medical_quotation_id': medical_quotation_id, 'outpatient_id': id}" name="medical_quotation_line_ids" widget="one2many_list">
    <tree string="Medical Quotation Lines" create="false">
        <field name="sequence" widget="handle" />
        <field name="medical_quotation_so_id" />
        <field name="dealer" />
        <field name="product_id" invisible="1"
            on_change="onchange_product_id(product_id, product_uom_qty, False, name)" />
        <field name="name" />
        <field name="lot_id" />
        <field name="remark" />
        <field name="product_uom_qty"
            on_change="onchange_product_id(product_id, product_uom_qty, False, name)" />
        <field name="product_uom" options="{'no_open': True}" />
        <field name="price_unit" />
        <!-- <field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]" /> -->
        <field name="discount" />
        <field name="price_subtotal" />
    </tree>
</field>


@api.multi
def unlink(self):
    # import ipdb; ipdb.set_trace()
    for rec in self:
        if rec.medical_quotation_so_id:
            raise Warning(_('Cannot delete the line that has been invoiced!'))
        if rec.dealer == 'system':
            raise Warning(_('Cannot delete rows created by the system!'))
    return super(MedicalQuotationLine, self).unlink()    

有什么想法吗?

python odoo odoo-8 qweb
1个回答
0
投票

尝试以这种方式申请,

def unlink(self, cr, uid, ids, context=None):
    for res in self.browse(cr, uid, ids, context=context):
        if res.medical_quotation_line_ids: 
            raise osv.except_osv(_('Error!'), _('Cannot delete the line that has been invoiced!'))
    return super(MedicalQuotationLine, self).unlink(cr, uid, ids, context=context)

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.