From 8f8dfe5a48d6c816adcd3dd8a6394f087a30f1e7 Mon Sep 17 00:00:00 2001
From: Juliana <juliana@le-filament.com>
Date: Tue, 19 Jul 2022 15:31:47 +0200
Subject: [PATCH] [ADD]Change state whan justif added

---
 models/account.py            |  2 ++
 wizard/upload_file_wizard.py | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/models/account.py b/models/account.py
index 7bb4d72..b7d3f74 100644
--- a/models/account.py
+++ b/models/account.py
@@ -54,6 +54,8 @@ class AccountInvoice(models.Model):
             )
             file.delete()
             self.proof_file = False
+            if self.type == "in_invoice":
+                self.state = "draft"
         except:
             self.proof_file = False
 
diff --git a/wizard/upload_file_wizard.py b/wizard/upload_file_wizard.py
index f7eb67e..408d265 100644
--- a/wizard/upload_file_wizard.py
+++ b/wizard/upload_file_wizard.py
@@ -26,10 +26,12 @@ class UploadFileWizard(models.TransientModel):
             Ajoute un fichier sur la GED Alfresco
             @return: fonction get_partner_files() de res.partner
         """
+        is_in_invoice = False
         if self.env.context["active_model"] == "account.invoice":
             account_id = self.env["account.invoice"].browse(self.env.context["active_id"])
             if account_id.type == "in_invoice":
                 proof_folder = self.env.user.company_id.proof_invoice_cmis
+                is_in_invoice = True
             else:
                 proof_folder = self.env.user.company_id.proof_invoice_customer_cmis
         else:
@@ -74,6 +76,14 @@ class UploadFileWizard(models.TransientModel):
                 )
                 file_id = file.getProperties().get('cmis:objectId')
                 obj.proof_file = file.getObjectId()
+                if is_in_invoice == True:
+                    obj.state = "paid"
+                    if obj.task_ids:
+                        for task in obj.task_ids:
+                            task.stage_id = self.env.ref(
+                                "adefpat_project.project_stage_paye"
+                            ).id
+
             except Exception as e:
                 raise UserError(json.loads(e.details).get('message'))
 
-- 
GitLab