From a72623c1da4437167982142dc2a20cf299787649 Mon Sep 17 00:00:00 2001
From: Jinjiu Liu <jili@odoo.com>
Date: Mon, 12 Dec 2022 14:06:55 +0000
Subject: [PATCH] [FIX] delivery: add method to check if commercial invoice is
 needed

This is a side fix to add a helper method in delivery. The main fix is
here: https://github.com/odoo/enterprise/pull/34907

Also included the change when localization is IN, as when the ship_from
country is IN, the commercial invoice information is mandatory.
Reference is here: https://github.com/odoo/odoo/pull/82084 and https://github.com/odoo/odoo/pull/84159

opw-3031665

closes odoo/odoo#107753

Related: odoo/enterprise#34907
Signed-off-by: Tiffany Chang <tic@odoo.com>
---
 addons/delivery/models/stock_picking.py      |  4 ++++
 addons/l10n_in_stock/__init__.py             |  2 ++
 addons/l10n_in_stock/models/__init__.py      |  4 ++++
 addons/l10n_in_stock/models/stock_picking.py | 12 ++++++++++++
 4 files changed, 22 insertions(+)
 create mode 100644 addons/l10n_in_stock/models/__init__.py
 create mode 100644 addons/l10n_in_stock/models/stock_picking.py

diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py
index 946655e55100..c5bb9da8f22f 100644
--- a/addons/delivery/models/stock_picking.py
+++ b/addons/delivery/models/stock_picking.py
@@ -272,6 +272,10 @@ class StockPicking(models.Model):
             weight += move.product_qty * move.product_id.weight
         return weight
 
+    def _should_generate_commercial_invoice(self):
+        self.ensure_one()
+        return self.picking_type_id.warehouse_id.partner_id.country_id != self.partner_id.country_id
+
 
 class StockReturnPicking(models.TransientModel):
     _inherit = 'stock.return.picking'
diff --git a/addons/l10n_in_stock/__init__.py b/addons/l10n_in_stock/__init__.py
index 67dee8c60dbf..dc5e6b693d19 100644
--- a/addons/l10n_in_stock/__init__.py
+++ b/addons/l10n_in_stock/__init__.py
@@ -1,2 +1,4 @@
 # -*- coding: utf-8 -*-
 # Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import models
diff --git a/addons/l10n_in_stock/models/__init__.py b/addons/l10n_in_stock/models/__init__.py
new file mode 100644
index 000000000000..ac9517445aee
--- /dev/null
+++ b/addons/l10n_in_stock/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import stock_picking
diff --git a/addons/l10n_in_stock/models/stock_picking.py b/addons/l10n_in_stock/models/stock_picking.py
new file mode 100644
index 000000000000..ec0f5c1972d7
--- /dev/null
+++ b/addons/l10n_in_stock/models/stock_picking.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models
+
+
+class StockPicking(models.Model):
+    _inherit = 'stock.picking'
+
+    def _should_generate_commercial_invoice(self):
+        super(StockPicking, self)._should_generate_commercial_invoice()
+        return True
-- 
GitLab