How to override a method without calling the previously inherited one but directly the framework method?
An exemple is that the model product.product has an unlink method which delete the related product template if no more variants exists.
def unlink(self, cr, uid, ids, context=None):
unlink_ids = []
unlink_product_tmpl_ids = []
for product in self.browse(cr, uid, ids, context=context):
...
tmpl_id = product.product_tmpl_id.id
# Check if the product is last product of this template
other_product_ids = self.search(cr, uid, [('product_tmpl_id', '=', tmpl_id), ('id', '!=', product.id)], context=context)
if not other_product_ids:
unlink_product_tmpl_ids.append(tmpl_id)
unlink_ids.append(product.id)
res = super(product_product, self).unlink(cr, uid, unlink_ids, context=context)
# delete templates after calling super, as deleting template could lead to deleting
# products due to ondelete='cascade'
self.pool.get('product.template').unlink(cr, uid, unlink_product_tmpl_ids, context=context)
return res
I would like to override this unlink method to delete the template only if it is a real template (defining attributes) and not a simple single variant template. I have for this created the field is_template. The override method would be modified with:
if not other_product_ids and not product.product_tmpl_id.is_template:
and be placed in a new module.
But this fails as the previously defined method is called (with the super()) and will unlink the template even if it is a "real template". Would you have some suggestion on how to bypass the previously inherited method?
Have you tried just not including the "super" call? In that case, if you have a dependency on the product module, at least only your method will be called.