Skip to Content
Menu
This question has been flagged
5 Replies
4385 Views

Dear

We develop an application that inherits the contract module "Contracts Management - Recurring" by means of which a partner can have several contracts. The partner_id field can only be made mandatory at the view level, because other applications such as Project enter records into the account.analytic.account model for which this field is not mandatory. On the other hand in the Contacts module (res.partner) it is allowed to delete contacts, permission that can not be removed from the users. However, in the Contacts module there are 2 options to delete contacts, the first with the Action \ Delete button and the second by clicking on the kanban of the "Contacts & Address" page. In both cases the contact is deleted without taking into account that it has contracts in the contract module. What I need is that in the 2 deletion options it is not allowed to delete the contact that has associated contracts.

I would appreciate any suggestions.

We are working with Odoo 11.0

Avatar
Discard

Hi Niyas, thank you for your kind answer!

But, it is not clear to me in which model I should put it, is it in account.analytic.account.py? What effect does the clause ondelete = 'restrict'? 

Best regards,
Claudio Zayas

On Monday, May 13, 2019, 9:44:53 AM GMT-4, Niyas Raphy <niyasraphyk@gmail.com> wrote:


A new question Do not allow deleting a contact with an associated contract on Help has been posted. Click here to access the question :

See question

Sent by Odoo S.A. using Odoo.

Hi Niyas, thank you for your kind answer!

But, it is not clear to me in which module I should put it, is it in account.analytic.account.py? What effect does the clause ondelete = 'restricted'? 

Best Answer

Hi Claudio Zayas,

You need to inherit the "account.analytic.account" object in your custom module and overwrite the partner_id field and add ondelete="restrict" in the field.

class AnalyticAccount(models.Model):
_inherit = 'account.analytic.account'

partner_id = fields.Many2one(ondelete="restrict")

ondelete restrict will now allow user to delete any partner record if it is associated with any Contract.

Avatar
Discard
Best Answer

Hi,

You can use ondelete='restrict' with the partner field in your model.

partner = fields.Many2one('res.partner', string='Partner', ondelete='restrict')

Thanks

Avatar
Discard
Author Best Answer

Dear Sudhir & Niyas, thank you very much for your help. I applied your solution and it worked fine!

Best regards,

Claudio


Avatar
Discard
Related Posts Replies Views Activity
3
Nov 24
3135
0
Apr 24
258
3
Nov 23
3769
1
Apr 23
1112
1
Mar 22
1394