-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[16.0][IMP] sale_stock_cancel_restriction: Option to restrict if delivered #3636
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
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from . import sale_order | ||
| from . import stock_warehouse |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,11 @@ class SaleOrder(models.Model): | |
| _inherit = "sale.order" | ||
|
|
||
| def action_cancel(self): | ||
| """Force to call the cancel method on done picking for having the | ||
| expected error, as Odoo has now filter out such pickings from the | ||
| cancel operation. | ||
| """ | ||
| self.mapped("picking_ids").filtered(lambda r: r.state == "done").action_cancel() | ||
| # Force to call the cancel method on done picking for having the | ||
| # expected error, as Odoo has now filter out such pickings from the | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug (multi-record recordset): for order in self:
domain = [("state", "=", "done")]
if order.warehouse_id.restrict_sale_cancel_after_delivery:
domain += [("picking_type_id.code", "=", "outgoing")]
order.picking_ids.filtered_domain(domain).action_cancel()
return super().action_cancel() |
||
| # cancel operation. | ||
| domain = [("state", "=", "done")] | ||
| if self.warehouse_id.restrict_sale_cancel_after_delivery: | ||
| domain += [("picking_type_id.code", "=", "outgoing")] | ||
| self.picking_ids.filtered_domain(domain).action_cancel() | ||
| return super().action_cancel() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright 2025 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
| HELP_RESTRICT = """ | ||
| If set, will block cancellation of sale orders if any delivery is done. | ||
| Otherwise, it will block cancellation when any transfer is done. | ||
| """ | ||
|
|
||
|
|
||
| class StockWarehouse(models.Model): | ||
| _inherit = "stock.warehouse" | ||
|
|
||
| restrict_sale_cancel_after_delivery = fields.Boolean( | ||
| help=HELP_RESTRICT, default=False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: restrict_sale_cancel_after_delivery = fields.Boolean(help=HELP_RESTRICT) |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <!-- Copyright 2025 Camptocamp SA | ||
| License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
| <odoo> | ||
|
|
||
| <record id="view_warehouse" model="ir.ui.view"> | ||
| <field name="name">stock.warehouse.form.inherit</field> | ||
| <field name="model">stock.warehouse</field> | ||
| <field name="inherit_id" ref="stock.view_warehouse" /> | ||
| <field name="arch" type="xml"> | ||
| <field name="partner_id" position="after"> | ||
| <field name="restrict_sale_cancel_after_delivery" /> | ||
| </field> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version should be bumped (e.g.
16.0.1.1.0) since this PR adds a new feature (new field onstock.warehouse, new configurable behavior).