Skip to content

[FIX] stock_move_manual_lot: action_assing based on stock_move.write_… - #17

Open
dkubiak789 wants to merge 5 commits into
fix/12.0/stock_move_manual_lot/multiple_linesfrom
fix/12.0/stock_move_manual_lot/swap_lots
Open

[FIX] stock_move_manual_lot: action_assing based on stock_move.write_…#17
dkubiak789 wants to merge 5 commits into
fix/12.0/stock_move_manual_lot/multiple_linesfrom
fix/12.0/stock_move_manual_lot/swap_lots

Conversation

@dkubiak789

Copy link
Copy Markdown

…date

@hbrunn hbrunn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please still add the changed tests that trigger the bug you fix

self.assertEqual(picking2.move_line_ids.lot_id, lot1)

self.assertEqual(self.quant2.reserved_quantity, 1)
self.assertEqual(picking2.move_line_ids.lot_id, self.lot2)

@StefanRijnhart StefanRijnhart Jan 7, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how self.lot2 relates to lot2, but we now seem to assert that the lot on the first picking is equal to lot2 in line 110, and the lot on the second picking is equal to self.lot2, which makes the tests fail on

2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: FAIL: test_02_reassign_reservation (odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot.TestStockMoveManualLot) 
2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: ` Pickings are rereserved after their lots were fetched on another 
2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: Traceback (most recent call last): 
2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: `   File "/home/bruno/buildout/ou120/parts/stock-logistics-workflow/stock_move_manual_lot/tests/test_stock_move_manual_lot.py", line 114, in test_02_reassign_reservation 
2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: `     self.assertEqual(picking2.move_line_ids.lot_id, self.lot2) 
2022-01-07 09:33:58,814 204298 ERROR 12stock_move_manual_lot odoo.addons.stock_move_manual_lot.tests.test_stock_move_manual_lot: ` AssertionError: stock.production.lot(1122,) != stock.production.lot(1123,) 

And I think that what Holger means is, the tests won't reproduce the problem unless the write date of the stock moves are backdated somewhere.

@dkubiak789
dkubiak789 force-pushed the fix/12.0/stock_move_manual_lot/swap_lots branch from 8e8d534 to 69a4c6a Compare January 10, 2022 16:26
@StefanRijnhart

StefanRijnhart commented Jan 11, 2022

Copy link
Copy Markdown

@dkubiak789 you don't need to add all these tests. We already have a swap lot tests. The problem is reproduced with this small change:

--- a/stock_move_manual_lot/tests/test_stock_move_manual_lot.py
+++ b/stock_move_manual_lot/tests/test_stock_move_manual_lot.py
@@ -1,5 +1,6 @@
 # Copyright 2021 Opener B.V. <stefan@opener.amsterdam>
 # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from datetime import timedelta
 from uuid import uuid1
 from odoo.exceptions import UserError
 from odoo.tests.common import TransactionCase
@@ -90,7 +91,12 @@ class TestStockMoveManualLot(TransactionCase):
         self.assertEqual(self.quant2.reserved_quantity, 1)
         self.assertEqual(picking2.move_line_ids.lot_id, self.lot2)
         self.assertTrue(self.picking.move_line_ids)
-        picking2.move_line_ids.manual_lot_id = self.lot1
+        self.picking.move_lines.write_date -= timedelta(minutes=1)
+        picking2.write({
+            "move_line_ids": [
+                (1, picking2.move_line_ids.id, {
+                    "manual_lot_id": self.lot1.id,
+                })]})
         self.assertTrue(self.picking.move_line_ids)
         self.assertEqual(self.picking.move_line_ids.lot_id, self.lot2)
         with self.assertRaises(

@dkubiak789

Copy link
Copy Markdown
Author

When I run tests in test_stock_move_manual_lot.py there is an error:
ERROR: null value in column "purchase_line_warn" violates not-null constraint
on product create
https://github.com/VanMoof/stock-logistics-workflow/blob/12.0/stock_move_manual_lot/tests/test_stock_move_manual_lot.py#L10
How to fix it @StefanRijnhart

@StefanRijnhart

StefanRijnhart commented Jan 12, 2022

Copy link
Copy Markdown

@dkubiak789 use a database that does not have purchase installed.
It is a required field introduced by the purchase module, for which it provides a default value. The problem arises when the purchase module is installed but not loaded yet. In that case, the field is still required (as per database constraint), but the code that provides the default is not active yet. That is why the problem never occurs when the tests are loaded during the installation of the modules.

@dkubiak789

Copy link
Copy Markdown
Author

Thank you @StefanRijnhart

@dkubiak789
dkubiak789 force-pushed the fix/12.0/stock_move_manual_lot/swap_lots branch from 3b2e7ce to 4e4748a Compare January 12, 2022 15:39

@StefanRijnhart StefanRijnhart left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

* [IMP] stock_move_manual_lot: make test setup more generic

* [FIX] stock_move_manual_lot: keep product_qty up to date

This prevents overassignment and, in rare cases, reservation errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants