Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
5 Risposte
5288 Visualizzazioni

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
Abbandona

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'? 

Risposta migliore

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
Abbandona
Risposta migliore

Hi,

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

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

Thanks

Avatar
Abbandona
Autore Risposta migliore

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

Best regards,

Claudio


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
lug 25
1336
3
nov 24
4891
3
nov 23
7714
1
apr 23
2723
1
mar 22
2347