From 5e268d889306dc6ea83011b77a64844bf0451e77 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Fri, 16 Aug 2019 11:37:39 +0000 Subject: [PATCH] [FIX] account: avoid deleting contact on invoice From Invoicing/Accounting generate an invoice toward a customer which is a child contact of a company. Click on "Validate" and print the invoice: the name and contact information of the customer will be in the report. Now go into Contacts and delete the customer. If you print again the report there will be no mention of the customer, and also from the invoicing tree view there is no customer information. This is due to the contraint on the deletion that affect only the parent contact (i.e. a company) which is being billed. The solution is to put a constraint on the account model to restrict the deletion of the contact if it is customer of an invoice. opw-2052717 closes odoo/odoo#35761 Signed-off-by: Nicolas Martinelli (nim) --- addons/account/models/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 4caeb61d2ee..ec7cca76b2b 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -304,7 +304,7 @@ class AccountInvoice(models.Model): "means direct payment.") partner_id = fields.Many2one('res.partner', string='Partner', change_default=True, readonly=True, states={'draft': [('readonly', False)]}, - track_visibility='always', help="You can find a contact by its Name, TIN, Email or Internal Reference.") + track_visibility='always', ondelete='restrict', help="You can find a contact by its Name, TIN, Email or Internal Reference.") vendor_bill_id = fields.Many2one('account.invoice', string='Vendor Bill', help="Auto-complete from a past bill.") payment_term_id = fields.Many2one('account.payment.term', string='Payment Terms', oldname='payment_term',