[16.0][FIX] purchase_sale_inter_company: handle pickings with lots/serials - #940
[16.0][FIX] purchase_sale_inter_company: handle pickings with lots/serials#940JasminSForgeFlow wants to merge 3 commits into
Conversation
584d0d4 to
a9e215b
Compare
Previously an intercompany picking with tracked products would simply throw an error. With this fix, the method searches for a lot in the destination company that matches the one in the source company (same name and same product). A new lot is created by duplicating the original, if none is found.
a9e215b to
add6272
Compare
…n destination company
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failure is caused by a database connection error (Connection to the database failed) during the Odoo startup, not directly due to the code changes in this PR. This likely indicates an infrastructure or environment issue in the test runner (e.g., runboat) rather than a bug in the module logic.
2. Suggested Fix
No fix is needed for the code changes themselves, as the failure is unrelated to the implementation. However, to ensure stability in future runs, verify that:
- The database service is correctly initialized and accessible.
- The
odoo.confor environment variables are correctly set for the test database. - The
SUPERUSER_IDusage instock_picking.py(line 74) is safe and doesn't cause unexpected behavior in multi-company contexts.
3. Additional Code Issues
-
Potential race condition in lot creation: In
stock_picking.py(lines 93–97),lot_id.copy()is called without a lock. If two processes try to create the same lot simultaneously, it could lead to duplicate records or errors.- Suggested fix: Wrap the lot creation logic in a
with self.env.cr.savepoint():block or use aSELECT FOR UPDATEto avoid race conditions.
- Suggested fix: Wrap the lot creation logic in a
-
Missing error handling for
move.sale_line_id.auto_purchase_line_id: Ifauto_purchase_line_idis not set,move.sale_line_id.auto_purchase_line_id.move_ids.mapped("move_line_ids")will raise an AttributeError.- Suggested fix: Add a check like
if move.sale_line_id and move.sale_line_id.auto_purchase_line_id:before accessing nested fields.
- Suggested fix: Add a check like
4. Test Improvements
To better cover the lot/serial number logic, add the following test cases in a TransactionCase or SavepointCase:
Test Case 1: Lot/Serial Number Propagation
- Create two companies with different warehouses.
- Create a product tracked by lot.
- Create a sale order in Company A and a corresponding purchase order in Company B.
- Confirm a picking with a lot/serial number in Company A.
- Assert that the same lot/serial number is created in Company B.
- Assert that no duplicate lots are created if the same lot name already exists.
Test Case 2: Mismatch Between Move Lines
- Create a sale/purchase order with mismatched move lines (e.g., 2 move lines in sale vs 1 in purchase).
- Confirm that a warning activity is scheduled.
- Validate that the activity is assigned to the correct user.
Test Case 3: No Lot/Serial Number Handling
- Confirm that the code doesn't break when move lines do not have lot/serial numbers.
- Ensure no error occurs in such cases.
Use @tagged('post_install', 'manual_install') for these tests, as they involve inter-company and multi-company logic.
Summary
- The test failure is due to an infrastructure issue, not the code.
- The new lot/serial number logic is generally correct but may benefit from race condition handling.
- Add tests covering lot propagation, mismatch handling, and edge cases for robustness.
⏰ This PR has been open for 33 days.
🔍 No human reviews yet after 33 days. PSC members: a quick review would help keep this contributor engaged with OCA.
💤 Last activity was 32 days ago.
Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)
Reciprocal Review Request
Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):
My open PRs across OCA:
- server-tools#3554 [MIG] datetime_formatter: Migration to 18.0
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
Reviewing each other's work helps the whole community move forward. Thank you!
Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
backport #541
include 78ca7a5
and adapt with 16.0