-
-
Notifications
You must be signed in to change notification settings - Fork 980
/
sale_order.py
28 lines (23 loc) · 1.08 KB
/
sale_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models
class SaleOrder(models.Model):
_inherit = "sale.order"
def _should_auto_remove_zero_quantity_lines(self):
self.ensure_one()
return self.company_id.sale_auto_remove_zero_quantity_lines
def action_confirm(self):
for order in self:
if order._should_auto_remove_zero_quantity_lines():
zero_or_empty_lines = order.order_line.filtered(
lambda line: (line.product_id and line.product_uom_qty == 0)
or (line.display_type == "line_note" and not line.name.strip())
)
if zero_or_empty_lines:
body = _(
"Some lines with zero quantities or empty notes were "
"removed upon confirmation."
)
order.message_post(body=body)
zero_or_empty_lines.unlink()
return super().action_confirm()