Skip to content

[16.0][FIX] purchase_sale_stock_inter_company - #888

Closed
AdrianaSaiz wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-purchase_sale_stock_inter_company
Closed

[16.0][FIX] purchase_sale_stock_inter_company#888
AdrianaSaiz wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-purchase_sale_stock_inter_company

Conversation

@AdrianaSaiz

@AdrianaSaiz AdrianaSaiz commented Oct 9, 2025

Copy link
Copy Markdown

Problem:
In intercompany scenarios with partial deliveries from different warehouses, automatic validation fails. For instance when Company A purchases 2 units from Company B, and Company B delivers via two separate 1-unit pickings:

First delivery validates correctly but remaining quantity gets cancelled instead of creating a backorder
Second delivery fails with "No corresponding line in PO" because the purchase order line was cancelled
Manual validation works correctly, but automatic validation doesn't respect backorder configuration

Root Cause:
The _set_intercompany_picking_qty() method returns all pickings related to the purchase order, including already completed pickings from previous partial deliveries. When processing backorders, the system attempts to validate these completed pickings, causing validation failures.

Changes Made:
Changed from _action_done() to button_validate() to respect user backorder configuration instead of always canceling remaining quantities
Added picking state filtering: Filter out completed/cancelled pickings before validation to prevent attempts to validate already processed transfers

Impact:
Fixes intercompany partial deliveries with backorders
Respects user backorder settings (Create/Ask/Never)
Maintains backward compatibility for single deliveries

@AdrianaSaiz
AdrianaSaiz force-pushed the 16.0-fix-purchase_sale_stock_inter_company branch 3 times, most recently from 371c816 to 53efb09 Compare October 9, 2025 18:03

@xAdrianCif xAdrianCif 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.

Great work! thx!

@AdrianaSaiz
AdrianaSaiz marked this pull request as ready for review October 10, 2025 10:10
@AdrianaSaiz
AdrianaSaiz force-pushed the 16.0-fix-purchase_sale_stock_inter_company branch from f21e259 to 03d255f Compare October 13, 2025 17:19

@OscarIndias OscarIndias 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.

LGTM!

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@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 Feb 15, 2026

@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 server startup, which occurs before any code in the PR is executed. This is not due to the changes in stock_picking.py, but likely due to misconfiguration or environment issues in the test runner (e.g., runboat).

2. Suggested Fix

There is no code fix needed for the PR itself, as the failure is unrelated to the changes. However, ensure that:

  • The test environment (e.g., runboat) is properly configured with a valid database connection.
  • The database service is up and accessible.
  • If this is a CI issue, verify that odoo.conf or environment variables are correctly set for the test DB.

3. Additional Code Issues

No real bugs found in the provided diff. The code change is valid:

  • button_validate() is the correct method to use instead of _action_done() for triggering validation with context.
  • Filtering out done and cancel states is correct.
  • Context keys like skip_backorder, skip_immediate, and bypass_set_number_of_packages are valid and used in Odoo's stock flows.

4. Test Improvements

To better cover this logic, consider adding the following test cases in a TransactionCase or SavepointCase:

def test_intercompany_picking_done_with_pending_picks(self):
    # Create intercompany purchase and sale orders
    # Create a stock picking for the purchase order
    # Ensure that the related sale picking is validated with correct context
    # Assert that the sale picking is in 'done' state

Use @tagged('post_install', 'standard') to mark tests that require inter-company setup.

Also, test edge cases like:

  • When po_picks contains a mix of done and draft pickings.
  • When po_pick.company_id is different from the current company.

These tests should be added to test/stock_picking.py or a new test file under purchase_sale_stock_inter_company/tests/.


Summary: No functional bugs in the code change. The test failure is environment-related and unrelated to the PR.


⏰ PR Aging Alert

This PR by @AdrianaSaiz has been open for 157 days (5 months).

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 github-actions Bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 22, 2026
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.

5 participants