Update project_invoice.py

This commit is contained in:
zainab2097 2024-09-03 13:13:28 +03:00 committed by GitHub
parent 25b662d20d
commit b887d2d495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -233,8 +233,9 @@ class ProjectInvoice(models.Model):
def action_set_to_draft(self):
self.ensure_one()
if self.invoice_id.state=='draft':
self.invoice_id.unlink()
if self.invoice_id and self.invoice_id.state=='draft':
self.invoice_id.sudo().write({'posted_before':False})
self.invoice_id.sudo().unlink()
self.state = 'draft'
else:
raise UserError(_("Kindly The invoice is not in draft state, so it cannot be unlinked."))