Skip to content

[16.0][FIX] purchase_sale_inter_company: handle pickings with lots/serials - #940

Closed
JasminSForgeFlow wants to merge 3 commits into
OCA:16.0from
ForgeFlow:16.0-imp-purchase_sale_inter_company
Closed

[16.0][FIX] purchase_sale_inter_company: handle pickings with lots/serials#940
JasminSForgeFlow wants to merge 3 commits into
OCA:16.0from
ForgeFlow:16.0-imp-purchase_sale_inter_company

Conversation

@JasminSForgeFlow

@JasminSForgeFlow JasminSForgeFlow commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

backport #541

include 78ca7a5

and adapt with 16.0

@JasminSForgeFlow
JasminSForgeFlow force-pushed the 16.0-imp-purchase_sale_inter_company branch from 584d0d4 to a9e215b Compare February 10, 2026 08:50
HekkiMelody and others added 2 commits February 10, 2026 11:50
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.
@JasminSForgeFlow
JasminSForgeFlow force-pushed the 16.0-imp-purchase_sale_inter_company branch from a9e215b to add6272 Compare February 10, 2026 11:55
@JasminSForgeFlow
JasminSForgeFlow marked this pull request as ready for review February 11, 2026 09:33

@marcos-mendez marcos-mendez 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.

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.conf or environment variables are correctly set for the test database.
  • The SUPERUSER_ID usage in stock_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 a SELECT FOR UPDATE to avoid race conditions.
  • Missing error handling for move.sale_line_id.auto_purchase_line_id: If auto_purchase_line_id is 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.

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:

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

@github-actions

Copy link
Copy Markdown

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.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jul 26, 2026
@github-actions github-actions Bot closed this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants