Skip to content

[16.0][IMP] sale_order_line_cancel: Refactor and create base addon#3894

Merged
OCA-git-bot merged 4 commits intoOCA:16.0from
mt-software-de:16-refactor-sale_order_line_cancel
Oct 8, 2025
Merged

[16.0][IMP] sale_order_line_cancel: Refactor and create base addon#3894
OCA-git-bot merged 4 commits intoOCA:16.0from
mt-software-de:16-refactor-sale_order_line_cancel

Conversation

@mt-software-de
Copy link
Copy Markdown
Contributor

@mt-software-de mt-software-de commented Sep 11, 2025

This PR moves the base functionality of sale_order_line_cancel into an own addon sale_order_line_cancel_base.
This allows it, to use it also without stock modules.

Within this refactoring i changed the logic, when the update of product_qty_canceled, before it was triggered by canceling a stock move. Now it is directly triggered when someone cancels the remaining qty.
This leads to the improvement i wanted, you can cancel the remaining qty of sale.order.lines without a stock.move.
This happens when a sale.order.line creates a not confirmed purchase.order.

sale_order_line_cancel will be now only adding the functionality to cancel the stock.moves when the cancel on the sale.order.lines is triggered or the other way around.

IMO: the naming of the addons should be sale_order_line_cancel and sale_order_line_cancel_stock, but i don't know if this would be good since sale_order_line_cancel is already in use.

A next task would be to create a addon called sale_order_line_cancel_purchase.

@mt-software-de mt-software-de force-pushed the 16-refactor-sale_order_line_cancel branch 4 times, most recently from d46d217 to 99603a5 Compare September 11, 2025 22:03
@mt-software-de
Copy link
Copy Markdown
Contributor Author

)
== 1
and rec.state in ("sale", "done")
and rec.qty_delivered_method == "stock_move"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line is now gone, imo it is not needed to check for qty_delivered_method.

sale_lines = self.env["sale.order.line"]
for move in self:
if (
move.sale_line_id
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This check was removed it is already in _is_move_to_take_into_account_for_qty_canceled

sale_line
and self.state == "cancel"
and self.picking_type_id.code == "outgoing"
and sale_line.state not in ["draft", "sent", "cancel"]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This ensures that i can not be called for a canceled order line.

and self.state == "cancel"
and self.picking_type_id.code == "outgoing"
and sale_line.state not in ["draft", "sent", "cancel"]
and not sale_line._get_moves_to_cancel()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This check ensures that there are no other open move lines, like in a mrp scenario.

@mt-software-de mt-software-de force-pushed the 16-refactor-sale_order_line_cancel branch 4 times, most recently from 27ea46c to 1e721c1 Compare September 12, 2025 08:34
Comment on lines 14 to 18
lines = self.filtered(
lambda l: l.qty_delivered_method == "stock_move"
and l.can_cancel_remaining_qty
)
return lines.move_ids.filtered(lambda m: m.state not in ("done", "cancel"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On a performance point of view, this code iterates 2 times on the lines.... We should do it on 1 loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry no. It doesn't, or? :-)
At first it iterates on lines and then on the moves.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lmignon Not sure, as at return lines.move_ids... lines are recordset. No more iteration

Copy link
Copy Markdown
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

The changes seem consistent overall. I have a quick question about the reason for no longer using the ‘qty_to_deliver’ attribute...
As for the module names, I find them counterintuitive. I would prefer to keep the basic functionality in sale_order_line_cancel and the code related to stock in sale_stock_sale_order_line_cancel. This seems to me to follow the logic adopted by Odoo.

@mt-software-de
Copy link
Copy Markdown
Contributor Author

mt-software-de commented Sep 14, 2025

The changes seem consistent overall. I have a quick question about the reason for no longer using the ‘qty_to_deliver’ attribute...

Because by changing the dependency to only sale in the base addon, it is not available anymore.

@mt-software-de
Copy link
Copy Markdown
Contributor Author

As for the module names, I find them counterintuitive. I would prefer to keep the basic functionality in sale_order_line_cancel and the code related to stock in sale_stock_sale_order_line_cancel. This seems to me to follow the logic adopted by Odoo.

Yes thats what i have written in the description of this PR. The only concern i have about this, whats about other user which are using this addon already? If we are changing the name the initial functionality isn't available anymore only if they know to install the renamed addon.

@mt-software-de mt-software-de force-pushed the 16-refactor-sale_order_line_cancel branch from 1e721c1 to 1cf272c Compare September 14, 2025 12:36
@rousseldenis
Copy link
Copy Markdown
Contributor

As for the module names, I find them counterintuitive. I would prefer to keep the basic functionality in sale_order_line_cancel and the code related to stock in sale_stock_sale_order_line_cancel. This seems to me to follow the logic adopted by Odoo.

Yes thats what i have written in the description of this PR. The only concern i have about this, whats about other user which are using this addon already? If we are changing the name the initial functionality isn't available anymore only if they know to install the renamed addon.

Agree with @lmignon on that.

@mt-software-de
Copy link
Copy Markdown
Contributor Author

As for the module names, I find them counterintuitive. I would prefer to keep the basic functionality in sale_order_line_cancel and the code related to stock in sale_stock_sale_order_line_cancel. This seems to me to follow the logic adopted by Odoo.

Yes thats what i have written in the description of this PR. The only concern i have about this, whats about other user which are using this addon already? If we are changing the name the initial functionality isn't available anymore only if they know to install the renamed addon.

Agree with @lmignon on that.

OK perfect then i will rename the modules

@mt-software-de mt-software-de force-pushed the 16-refactor-sale_order_line_cancel branch 3 times, most recently from 5e83699 to afc2300 Compare September 17, 2025 06:22
@rousseldenis rousseldenis added this to the 16.0 milestone Sep 25, 2025
@rousseldenis
Copy link
Copy Markdown
Contributor

@lmignon

@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). 🤖

@rousseldenis
Copy link
Copy Markdown
Contributor

/ocabot merge major

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-3894-by-rousseldenis-bump-major, awaiting test results.

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at e6bc28a. Thanks a lot for contributing to OCA. ❤️

@OCA-git-bot OCA-git-bot merged commit a2cbb62 into OCA:16.0 Oct 8, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants