【发布时间】:2020-06-24 14:57:15
【问题描述】:
我有一个one2many 小部件,当用户删除任何行时,我需要有一个条件。
是否有我可以覆盖的 on delete 方法?我尝试过使用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()
有什么想法吗?
【问题讨论】:
-
啊,Odoo 8 我想知道为什么它不应该按照你的方式工作,但是在那个版本中它没有在 One2many 字段删除时调用
unlink。试试看一下父模型的write方法,至少应该有那些黑魔法三重命令之类的东西,可以使用。 -
您是否建议将以前的
One2many与当前的One2many进行比较?会试试的,谢谢。 -
没有写入值将有三个命令。只需查看 Model.write() 的文档字符串即可。记录了删除的神奇数字。
-
stackoverflow.com/questions/9377402/… 你可以在第一反应中找到神奇的数字