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:
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)
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?
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 2/19/15, 4:55 AM|
|Seen: 1395 times|
|Last updated: 3/16/15, 8:10 AM|