Skip to content

Commit

Permalink
[IMP] sale_cancel_reason: cancel reason in mass quotation cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-wichowski committed Apr 9, 2024
1 parent 8040cc4 commit 61340f5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions sale_cancel_reason/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"depends": ["sale"],
"data": [
"wizard/cancel_reason_view.xml",
"wizard/mass_cancel_orders_view.xml",
"view/sale_view.xml",
"security/ir.model.access.csv",
"data/sale_order_cancel_reason.xml",
Expand Down
27 changes: 22 additions & 5 deletions sale_cancel_reason/tests/test_sale_cancel_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ def setUpClass(cls):
cls.reason = CancelReason.create({"name": "Canceled for tests"})
cls.partner = cls.env.ref("base.res_partner_2")
cls.product = cls.env.ref("product.product_product_7")
cls.sale_order = SaleOrder.create(
cls.sale_order_1 = SaleOrder.create(
{
"partner_id": cls.partner.id,
"order_line": [
(0, 0, {"product_id": cls.product.id, "product_uom_qty": 8})
],
}
)
cls.sale_order_2 = cls.sale_order_1.copy()
cls.sale_orders = cls.sale_order_1 + cls.sale_order_2

def test_sale_order_cancel_reason(self):
"""
Expand All @@ -29,12 +31,27 @@ def test_sale_order_cancel_reason(self):
"""
SaleOrderCancel = self.env["sale.order.cancel"]
wizard = SaleOrderCancel.create(
{"reason_id": self.reason.id, "order_id": self.sale_order.id}
{"reason_id": self.reason.id, "order_id": self.sale_order_1.id}
)
wizard.with_context(
active_model="sale.order", active_ids=self.sale_order.id
active_model="sale.order", active_ids=self.sale_order_1.id
).action_cancel()
self.assertEqual(
self.sale_order.state, "cancel", "the sale order should be canceled"
self.sale_order_1.state, "cancel", "the sale order should be canceled"
)
self.assertEqual(self.sale_order_1.cancel_reason_id.id, self.reason.id)

def test_sale_order_cancel_reason_mass_cancel(self):
MassCancelOrders = self.env["sale.mass.cancel.orders"]
wizard = MassCancelOrders.with_context(
active_model="sale.order", active_ids=self.sale_orders.ids
).create({"reason_id": self.reason.id})
wizard.action_mass_cancel()

self.assertRecordValues(
self.sale_orders,
[
{"cancel_reason_id": self.reason.id},
{"cancel_reason_id": self.reason.id},
],
)
self.assertEqual(self.sale_order.cancel_reason_id.id, self.reason.id)
2 changes: 1 addition & 1 deletion sale_cancel_reason/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2013 Guewen Baconnier, Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import cancel_reason
from . import cancel_reason, mass_cancel_orders
13 changes: 13 additions & 0 deletions sale_cancel_reason/wizard/mass_cancel_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import models, fields


class SaleMassCancelOrders(models.TransientModel):
_inherit = "sale.mass.cancel.orders"

reason_id = fields.Many2one(
"sale.order.cancel.reason", string="Reason", required=True
)

def action_mass_cancel(self):
self.sale_order_ids.write({"cancel_reason_id": self.reason_id.id})
return super().action_mass_cancel()
15 changes: 15 additions & 0 deletions sale_cancel_reason/wizard/mass_cancel_orders_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mass_cancel_orders_view_form" model="ir.ui.view">
<field name="name">sale.mass.cancel.orders.form</field>
<field name="model">sale.mass.cancel.orders</field>
<field name="inherit_id" ref="sale.mass_cancel_orders_view_form"/>
<field name="arch" type="xml">
<footer position="before">
<group>
<field name="reason_id"/>
</group>
</footer>
</field>
</record>
</odoo>

0 comments on commit 61340f5

Please sign in to comment.