У меня есть виджет one2many
, который должен иметь условие, когда пользователь удаляет любую строку.
Существует ли метод удаления, который я могу переопределить? Я пытался с 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','<>','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()
Есть идеи?