From f8cbdd2cdc9f2f776a2213ad9647c0241351b615 Mon Sep 17 00:00:00 2001
From: Karnav Sojitra <kaso@odoo.com>
Date: Mon, 12 Jun 2023 12:49:52 +0000
Subject: [PATCH] [FIX] l10n_fr_pos_cert:  add usererror for non-unalterable
 accounting

The error will occur when a user try to print POS inalterability check report
for pos orders when accounting is not unalterable for that company.
steps to produce:

1. install l10n_fr_pos_cert the  module
2. switch to company other than FR company
3. pos > reporting > POS inalterability check .

when the company's country is not in unalterable country :
https://github.com/odoo/odoo/blob/3b88958f5a07edf86d2fc9c8080ee46d16b872ef/addons/l10n_fr/models/res_company.py#L14-L24

1. so,`_check_pos_hash_integrity()` gets Nonetype which will lead to above
traceback, when trying to update the data dictionary.
2. Also, `_check_hash_pos_integrity()` is not defined in our standard code so ,
this commit optimize the `_get_report_values` method.
see : https://github.com/odoo/odoo/blob/3b88958f5a07edf86d2fc9c8080ee46d16b872ef/addons/l10n_fr_pos_cert/report/pos_hash_integrity.py#LL11C1-L22

sentry-4243853702

closes odoo/odoo#126798

X-original-commit: 131edcc188b5fcb40b2ecc8f8b88855a6d7edd13
Signed-off-by: Achraf Ben Azzouz (abz) <abz@odoo.com>
---
 addons/l10n_fr_pos_cert/i18n/l10n_fr_pos_cert.pot    | 8 ++++++++
 addons/l10n_fr_pos_cert/models/res_company.py        | 2 ++
 addons/l10n_fr_pos_cert/report/pos_hash_integrity.py | 6 ++----
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/addons/l10n_fr_pos_cert/i18n/l10n_fr_pos_cert.pot b/addons/l10n_fr_pos_cert/i18n/l10n_fr_pos_cert.pot
index 9289974a1814..42f15fb2dfbb 100644
--- a/addons/l10n_fr_pos_cert/i18n/l10n_fr_pos_cert.pot
+++ b/addons/l10n_fr_pos_cert/i18n/l10n_fr_pos_cert.pot
@@ -55,6 +55,14 @@ msgstr ""
 msgid "Account Closing"
 msgstr ""
 
+#. module: l10n_fr_pos_cert
+#: code:addons/l10n_fr_pos_cert/models/res_company.py:0
+#, python-format
+msgid ""
+"Accounting is not unalterable for the company %s. This mechanism is designed"
+" for companies where accounting is unalterable."
+msgstr ""
+
 #. module: l10n_fr_pos_cert
 #: code:addons/l10n_fr_pos_cert/models/pos.py:0
 #, python-format
diff --git a/addons/l10n_fr_pos_cert/models/res_company.py b/addons/l10n_fr_pos_cert/models/res_company.py
index ebbf7335410b..39d9b125b0b5 100644
--- a/addons/l10n_fr_pos_cert/models/res_company.py
+++ b/addons/l10n_fr_pos_cert/models/res_company.py
@@ -94,3 +94,5 @@ class ResCompany(models.Model):
                 'printing_date': format_date(self.env,  Date.to_string( Date.today())),
                 'corrupted_orders': corrupted_orders or 'None'
             }
+        else:
+            raise UserError(_('Accounting is not unalterable for the company %s. This mechanism is designed for companies where accounting is unalterable.') % self.env.company.name)
diff --git a/addons/l10n_fr_pos_cert/report/pos_hash_integrity.py b/addons/l10n_fr_pos_cert/report/pos_hash_integrity.py
index d7c36038022b..348cbac473ae 100644
--- a/addons/l10n_fr_pos_cert/report/pos_hash_integrity.py
+++ b/addons/l10n_fr_pos_cert/report/pos_hash_integrity.py
@@ -10,10 +10,8 @@ class ReportPosHashIntegrity(models.AbstractModel):
 
     @api.model
     def _get_report_values(self, docids, data=None):
-        if data:
-            data.update(self.env.company._check_pos_hash_integrity())
-        else:
-            data = self.env.company._check_hash_pos_integrity()
+        data = data or {}
+        data.update(self.env.company._check_pos_hash_integrity() or {})
         return {
             'doc_ids' : docids,
             'doc_model' : self.env['res.company'],
-- 
GitLab