跳至內容
選單
此問題已被標幟
5 回覆
5289 瀏覽次數

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

頭像
捨棄

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

最佳答案

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.

頭像
捨棄
最佳答案

Hi,

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

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

Thanks

頭像
捨棄
作者 最佳答案

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

Best regards,

Claudio


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
7月 25
1336
3
11月 24
4891
3
11月 23
7714
1
4月 23
2723
1
3月 22
2348