From 41daa8ee9a29ade4d548e852322154d6fb8f84ec Mon Sep 17 00:00:00 2001
From: Carolina Fernandez
Date: Fri, 5 Jan 2024 15:50:45 -0300
Subject: [PATCH] [MIG] stock_lot_scrap: Migration to 16.0
---
stock_lot_scrap/README.rst | 13 +++++----
stock_lot_scrap/__manifest__.py | 3 +-
stock_lot_scrap/models/__init__.py | 2 +-
.../{stock_production_lot.py => stock_lot.py} | 28 ++++++++++---------
stock_lot_scrap/readme/CONTRIBUTORS.rst | 1 +
stock_lot_scrap/static/description/index.html | 9 +++---
stock_lot_scrap/tests/test_stock_lot_scrap.py | 7 +++--
7 files changed, 35 insertions(+), 28 deletions(-)
rename stock_lot_scrap/models/{stock_production_lot.py => stock_lot.py} (83%)
diff --git a/stock_lot_scrap/README.rst b/stock_lot_scrap/README.rst
index a0accaf94a3f..d76cd753a9ad 100644
--- a/stock_lot_scrap/README.rst
+++ b/stock_lot_scrap/README.rst
@@ -7,7 +7,7 @@ Scrap Production Lot
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:18b4f801e7ac8c515fb91fc05bc17b09ae314f40963aa31695e16d116aab23b3
+ !! source digest: sha256:a1b0470f00d0544b144393d2d88084606a6592ca309c3fe97c11e763d7cc2451
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Scrap Production Lot
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
- :target: https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_lot_scrap
+ :target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_lot_scrap
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_lot_scrap
+ :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_lot_scrap
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=14.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -55,7 +55,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -77,6 +77,7 @@ Contributors
* David Vidal
* Vicent Cubells
* Carlos Roca
+ * Carolina Fernandez
Maintainers
~~~~~~~~~~~
@@ -91,6 +92,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/stock-logistics-workflow `_ project on GitHub.
+This module is part of the `OCA/stock-logistics-workflow `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_lot_scrap/__manifest__.py b/stock_lot_scrap/__manifest__.py
index fd71a65d54e8..9a1951f2c723 100644
--- a/stock_lot_scrap/__manifest__.py
+++ b/stock_lot_scrap/__manifest__.py
@@ -2,13 +2,14 @@
# Copyright 2016 Pedro M. Baeza
# Copyright 2017 David Vidal
# Copyright 2021 Tecnativa - Carlos Roca
+# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Scrap Production Lot",
"summary": "This module adds a button in Production Lot/Serial Number "
"view form to Scrap all products contained.",
- "version": "14.0.1.0.2",
+ "version": "16.0.1.0.0",
"category": "Stock",
"license": "AGPL-3",
"author": "Tecnativa," "Odoo Community Association (OCA)",
diff --git a/stock_lot_scrap/models/__init__.py b/stock_lot_scrap/models/__init__.py
index 54186c17b059..50f5973d2336 100644
--- a/stock_lot_scrap/models/__init__.py
+++ b/stock_lot_scrap/models/__init__.py
@@ -1,2 +1,2 @@
-from . import stock_production_lot
+from . import stock_lot
from . import stock_scrap
diff --git a/stock_lot_scrap/models/stock_production_lot.py b/stock_lot_scrap/models/stock_lot.py
similarity index 83%
rename from stock_lot_scrap/models/stock_production_lot.py
rename to stock_lot_scrap/models/stock_lot.py
index a6c1186e3feb..9169f70d0e7f 100644
--- a/stock_lot_scrap/models/stock_production_lot.py
+++ b/stock_lot_scrap/models/stock_lot.py
@@ -1,6 +1,7 @@
# Copyright 2016 Carlos Dauden
# Copyright 2016 Pedro M. Baeza
# Copyright 2017 David Vidal
+# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from lxml import etree
@@ -9,20 +10,22 @@
from odoo.exceptions import ValidationError
-class StockProductionLot(models.Model):
- _inherit = "stock.production.lot"
+class StockLot(models.Model):
+ _inherit = "stock.lot"
@api.model
- def fields_view_get(
- self, view_id=None, view_type="form", toolbar=False, submenu=False
- ): # pragma: no cover
+ def _get_view(self, view_id=None, view_type="form", **options):
"""Inject the button here to avoid conflicts with other modules
that add a header element in the main view.
"""
- res = super().fields_view_get(
- view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
- )
- eview = etree.fromstring(res["arch"])
+ arch, view = super()._get_view(view_id, view_type, **options)
+
+ if isinstance(arch, bytes):
+ # If arch is bytes, convert it to an XML element
+ eview = etree.fromstring(arch)
+ else:
+ # If arch is already an XML element, no need to parse
+ eview = arch
xml_header = eview.xpath("//header")
if not xml_header:
# Create a header
@@ -39,15 +42,14 @@ def fields_view_get(
"type": "object",
"name": "action_scrap_lot",
"confirm": _(
- "This will scrap the whole lot. Are you"
- " sure you want to continue?"
+ "This will scrap the whole lot. Are you sure you want to continue?"
),
"string": _("Scrap"),
},
)
header_element.append(button_element)
- res["arch"] = etree.tostring(eview)
- return res
+ arch = eview # Return the XML element directly
+ return arch, view
def _prepare_scrap_vals(self, quant, scrap_location_id):
self.ensure_one()
diff --git a/stock_lot_scrap/readme/CONTRIBUTORS.rst b/stock_lot_scrap/readme/CONTRIBUTORS.rst
index f036c743b245..930c2c7b3f8e 100644
--- a/stock_lot_scrap/readme/CONTRIBUTORS.rst
+++ b/stock_lot_scrap/readme/CONTRIBUTORS.rst
@@ -5,3 +5,4 @@
* David Vidal
* Vicent Cubells
* Carlos Roca
+ * Carolina Fernandez
diff --git a/stock_lot_scrap/static/description/index.html b/stock_lot_scrap/static/description/index.html
index 35b39a56a715..092d12d1168c 100644
--- a/stock_lot_scrap/static/description/index.html
+++ b/stock_lot_scrap/static/description/index.html
@@ -367,9 +367,9 @@ Scrap Production Lot
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:18b4f801e7ac8c515fb91fc05bc17b09ae314f40963aa31695e16d116aab23b3
+!! source digest: sha256:a1b0470f00d0544b144393d2d88084606a6592ca309c3fe97c11e763d7cc2451
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

This module adds a button in Production Lot/Serial Number view form to
Scrap all quants contained.
Table of contents
@@ -406,7 +406,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -426,6 +426,7 @@
David Vidal
Vicent Cubells
Carlos Roca
+
Carolina Fernandez
@@ -437,7 +438,7 @@
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/stock-logistics-workflow project on GitHub.
+
This module is part of the OCA/stock-logistics-workflow project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_lot_scrap/tests/test_stock_lot_scrap.py b/stock_lot_scrap/tests/test_stock_lot_scrap.py
index 7ea04c488939..02f2db4e5f46 100644
--- a/stock_lot_scrap/tests/test_stock_lot_scrap.py
+++ b/stock_lot_scrap/tests/test_stock_lot_scrap.py
@@ -1,6 +1,7 @@
# Copyright 2016 Carlos Dauden
# Copyright 2016 Pedro M. Baeza
# Copyright 2017 David Vidal
+# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
@@ -9,7 +10,7 @@
@tagged("post_install", "-at_install")
-class TestStockLotScrap(common.SavepointCase):
+class TestStockLotScrap(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -17,7 +18,7 @@ def setUpClass(cls):
{"name": "Test product", "type": "product"}
)
cls.company = cls.env.ref("base.main_company")
- cls.lot010 = cls.env["stock.production.lot"].create(
+ cls.lot010 = cls.env["stock.lot"].create(
{
"name": "0000010",
"product_id": cls.product.id,
@@ -56,7 +57,7 @@ def test_picking_created(self):
def test_warning(self):
product_new = self.product.create({"name": "Test product 040"})
- self.lot040 = self.env["stock.production.lot"].create(
+ self.lot040 = self.env["stock.lot"].create(
{
"name": "0000040",
"product_id": product_new.id,