Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] purchase_sale_stock_inter_company : partial dropshipping deliveries is wrong #741

Open
metaminux opened this issue Dec 13, 2024 · 0 comments
Labels

Comments

@metaminux
Copy link
Contributor

Module

purchase_sale_stock_inter_company

Describe the bug

When using inter company and dropshipping, if delivery is not complete (but with partial deliveries and backorders), quantities computed as delivered in the "customer" company are wrong.

To Reproduce

16.0:

Steps to reproduce the behavior:

  1. In a runboat, install purchase_sale_stock_inter_company
  2. Configure My Company (Chicago) :
  3. Sale from purchase = True
  4. Warehouse = Chicago 1
  5. Sale user = Marc Demo
  6. Sale Orders Auto Validation = True
  7. Configure My Company (San Francisco) :
  8. Sale from purchase = True
  9. Warehouse = Your Company
  10. Sale user = Marc Demo
  11. Sale Orders Auto Validation = True
  12. Enable dropshipping
  13. Configure product "FURN_6666" :
  14. Dropship route = True
  15. Add a first supplier price with supplier = "My Company (San Francisco)"
  16. Switch to My company (Chicago)
  17. Open customer "Deco Addict" and click on Sales/Quotations
  18. Click New button to create a new quotation
  19. Add a line for product "FURN_6666" with qty = 5
  20. Confirm quotation.
  21. Go to generated PO with My Company (San Francisco) as supplier and confirm it
  22. Switch to My company (San Francisco)
  23. Go to the new created inter company SO for customer My company (Chicago)
  24. Go to the generated PO for the external suppllier (by default "Wood corner") and confirm it
  25. Go to the dropship and set done quantity = 3, validate and create a backorder (everything is fine in both companies)
  26. Finish the delivery (qty = 2)

Expected behavior
In both companies, we should have 2 dropship pickings for each sales orders in "done" state and quantities should be 3 for the first one and 2 for the second (the backorder).
Each sale order should have a computed delivered quanity of 5.

Here, quantities are OK in My Company (San Francisco) (the "supplier" company)
But quantities are not OK in My Company (Chicago) (the "customer" company) because quantities are reset to 0 on the first dropship picking when validating the backorder. So final computed delivered quantity is only 2 !

Additional context
The steps to reproduce are quite long, but I think the bug is related to the _action_done method of stock.picking

def _action_done(self):
# Only DropShip pickings
po_picks = self.browse()
for pick in self.filtered(
lambda x: x.location_dest_id.usage == "customer"
).sudo():
purchase = pick.sale_id.auto_purchase_order_id
if not purchase:
continue
purchase.picking_ids.write({"intercompany_picking_id": pick.id})
for move_line in pick.move_line_ids:
qty_done = move_line.qty_done
sale_line_id = move_line.move_id.sale_line_id
po_move_lines = sale_line_id.auto_purchase_line_id.move_ids.mapped(
"move_line_ids"
)
for po_move_line in po_move_lines:
if po_move_line.reserved_qty >= qty_done:
po_move_line.qty_done = qty_done
qty_done = 0.0
else:
po_move_line.qty_done = po_move_line.reserved_qty
qty_done -= po_move_line.reserved_qty
po_picks |= po_move_line.picking_id
if qty_done and po_move_lines:
po_move_lines[-1:].qty_done += qty_done
elif not po_move_lines:
raise UserError(
_(
"There's no corresponding line in PO %(po)s for assigning "
"qty from %(pick_name)s for product %(product)s"
)
% (
{
"po": purchase.name,
"pick_name": pick.name,
"product": move_line.product_id.name,
}
)
)
# Transfer dropship pickings
for po_pick in po_picks.sudo():
po_pick.with_company(po_pick.company_id.id)._action_done()
return super()._action_done()

I'll propose a PR with a test confirming this issue and a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant