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][ADD] - sale_order_line_cancel #2357

Open
wants to merge 10 commits into
base: 16.0
Choose a base branch
from

Conversation

sbejaoui
Copy link
Contributor

@sbejaoui sbejaoui commented Feb 2, 2023

This module allows you to cancel the remaining quantity on sale order by adding
a dedicated action to sale lines. It also add two new fields to track canceled
and remaining to deliver quantities.

@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from 685f327 to da21d81 Compare February 2, 2023 14:53
@sbejaoui
Copy link
Contributor Author

sbejaoui commented Feb 2, 2023

cc/ @lmignon

@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch 3 times, most recently from 6418faf to f5d3431 Compare February 2, 2023 16:22
Copy link
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.

@sbejaoui I tested the odoo native behavior and it seems that this addon could be simplified and only provide the functionality in a specific context. On a sale order line, you can edit the quantity even if the SO is validated... IMO this behavior is dangerous and should be forbidden. Hopefully, an option is available into the settings to prevent the modification of quantities when the sale order is confirmed... It's only in the context where the modification is no more possible that this functionality makes sens and should be activated. Moreover, I've the feeling that all the custom code written to cancel the moves could be removed (and the dependency on OCA/stock-logistics-workflow#1202). When you change the qty on a confirmed line, Odoo takes the necessary steps to reflect this change in the picking chain. The only thing Odoo doesn't do is to prevent the cancel of quantities that are partially processed. Instead, it generate the return picking to revert this outgoing moves... I prefer to prevent the cancellation of qties already partially processed than adding more work to do by opertors. This behaviour could be a configurable option..

@sbejaoui
Copy link
Contributor Author

sbejaoui commented Feb 6, 2023

@sbejaoui I tested the odoo native behavior and it seems that this addon ..

Thanks @lmignon for your input,

I understand your PoV, It's true that the change of the ordered quantity trigger the change/cancellation of the related moves.

This feature is meant to simplify the process and make it done with a simple click. It also keep the information of the initial ordered quantity and store the canceled quantity. The difference between the two fields may be helpful for sale reporting.

The dependency to OCA/stock-logistics-workflow#1202 is not a must. It's, IMO, a simpler way to get all sale line related moves instead of recursive loop.

@lmignon
Copy link
Contributor

lmignon commented Feb 7, 2023

@sbejaoui I tested the odoo native behavior and it seems that this addon ..

Thanks @lmignon for your input,

I understand your PoV, It's true that the change of the ordered quantity trigger the change/cancellation of the related moves.

This feature is meant to simplify the process and make it done with a simple click. It also keep the information of the initial ordered quantity and store the canceled quantity. The difference between the two fields may be helpful for sale reporting.

The dependency to OCA/stock-logistics-workflow#1202 is not a must. It's, IMO, a simpler way to get all sale line related moves instead of recursive loop.

IMO, the functionality should only be available if the change of qty on confirmed sale order is activated..

@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from f5d3431 to db0f8d6 Compare February 8, 2023 15:13
@sbejaoui sbejaoui requested a review from lmignon February 8, 2023 15:13
@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from db0f8d6 to 74a1b1f Compare February 8, 2023 15:40
Copy link
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.

Some comment to add to the desciption

sale_cancel_remaining/readme/DESCRIPTION.rst Outdated Show resolved Hide resolved
sale_cancel_remaining/wizards/__init__.py Outdated Show resolved Hide resolved
@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch 3 times, most recently from 0f051b2 to 23f56a1 Compare February 8, 2023 16:25
@rousseldenis rousseldenis added this to the 16.0 milestone Feb 14, 2023
Copy link
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

I did many tests and it works quite well. It restricts the possibility of changing the quantity on the sale order line but at least the cancelation is working properly while in standard odoo you can end-up with a very weird reverse picking as decreasing the sale order line quantity generates a negative move that is supposed to be merged with the original move but if it can't be assigned to the same picking, it will create a reverse picking.

A few remarks that would make this module more complete:

  • when you set the sales order back to quotation, product_qty_canceled on the lines should be reset to 0
  • I would display the cancel button on a locked sales order as you expect auto-locking to be enabled and you allow canceling the lines
  • When canceling the sales order, I would also write product_qty_remains_to_deliver in product_qty_canceled
  • If you don't generate the backorder of the outgoing picking, the product_qty_canceled on the lines should also increase

sale_cancel_remaining/views/sale_order_line.xml Outdated Show resolved Hide resolved
sale_cancel_remaining/views/sale_order_line.xml Outdated Show resolved Hide resolved
sale_cancel_remaining/wizards/cancel_remaining_wizard.py Outdated Show resolved Hide resolved
sale_cancel_remaining/wizards/cancel_remaining_wizard.py Outdated Show resolved Hide resolved
@jbaudoux
Copy link
Contributor

jbaudoux commented Mar 30, 2023

The dependency to OCA/stock-logistics-workflow#1202 is not a must. It's, IMO, a simpler way to get all sale line related moves instead of recursive loop.

Just a side note that this way of finding the right moves of the chain is not safe as moves can be merged. For example, a single pick move could serve multiple delivery moves. This specific use case is covered by the stock_available_to_promise_release module which, in case you cancel the outgoing move, will unrelease the outgoing move and while unreleasing it, will go through the picking chain up to the source picking and split any merged move.

A solution would be that this module only cancel the outgoing move and have another module using the dependency to OCA/stock-logistics-workflow#1202 to propagate the cancelation.

You can maybe add this remark in a ROADMAP file.

sale_cancel_remaining/__manifest__.py Outdated Show resolved Hide resolved
@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from 23f56a1 to a07abf4 Compare April 1, 2023 21:56
@sbejaoui sbejaoui changed the title [16.0][ADD] - sale_cancel_remaining [16.0][ADD] - sale_order_line_cancel Apr 1, 2023
@sbejaoui sbejaoui requested a review from jbaudoux April 1, 2023 21:57
@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from a07abf4 to 34bf905 Compare April 1, 2023 22:08
Copy link
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements
LGTM

@OCA-git-bot
Copy link
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). 🤖

sale_order_line_cancel/__manifest__.py Outdated Show resolved Hide resolved
@cyrilmanuel
Copy link

ping @sbejaoui :)

@cyrilmanuel
Copy link

thank you @sbejaoui 👍 @rousseldenis can yo check the PR ?

sbejaoui and others added 3 commits January 12, 2024 15:06
Cancel remaining qty by running negative procurement orders to let odoo generate the appropriate operations
@lmignon lmignon force-pushed the 16.0-sale_cancel_remaining-sbj branch from 8585123 to b5cd7f0 Compare February 12, 2024 09:48
Co-authored-by: Jacques-Etienne Baudoux <[email protected]>
for rec in sale_moves:
if rec.state != "cancel":
continue
rec.sale_line_id.product_qty_canceled = rec.product_uom_qty
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct for the kits (mrp)

Copy link
Contributor

@jbaudoux jbaudoux Feb 21, 2024

Choose a reason for hiding this comment

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

we should also ensure on sale.order.line that product_qty_canceled <= product_uom_qty - qty_delivered


def _action_cancel(self):
orders = self.filtered(lambda s: s.state != "cancel")
orders_with_picking = orders.filtered("picking_ids")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is better as in sale_stock they use qty_delivered_method:

Suggested change
orders_with_picking = orders.filtered("picking_ids")
orders_with_picking = orders.filtered(lambda o: any(line.qty_delivered_method == 'stock_move' for line in o.order_line)):

Copy link
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

@cyrilmanuel
Copy link

Hi @sbejaoui little ping, could you check about the comment of @jbaudoux ?

@jbaudoux
Copy link
Contributor

jbaudoux commented May 8, 2024

See acsone#4

Allows to check the cancellation on sale order line level

Include normal sales (not locked)
<field name="perm_create" eval="1" />
<field name="perm_write" eval="1" />
<field name="perm_unlink" eval="1" />
</record>

Choose a reason for hiding this comment

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

is it possible to add entry for users in groups sales_team.group_sale_salesman ?

sale.order.line.cancel access own document

@sbejaoui sbejaoui force-pushed the 16.0-sale_cancel_remaining-sbj branch from 29b4996 to 736014a Compare November 13, 2024 23:53
for line in self:
if line._get_moves_to_cancel():
continue
line.product_qty_canceled = line.qty_to_deliver
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux ,

The canceled quantity is not the same as the quantity to deliver because the quantity to deliver includes returned quantities.
For example, in an order of 10 units, if I deliver 8 and then cancel the remaining 2, and later my customer returns 2 units, I would expect the following values:

  • Quantity to deliver: 4
  • Quantity canceled: 2

_description = "Cancel Remaining Wizard"

def _get_sale_order_line(self):
active_id = self._context.get("active_id")
Copy link
Contributor

Choose a reason for hiding this comment

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

_context is deprecated

Suggested change
active_id = self._context.get("active_id")
active_id = self.env.context.get("active_id")

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.

6 participants