-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsale_order.py
More file actions
76 lines (61 loc) · 2.3 KB
/
sale_order.py
File metadata and controls
76 lines (61 loc) · 2.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2011 Akretion, Sodexis
# Copyright 2018 Akretion
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class SaleOrder(models.Model):
_inherit = ["sale.order", "base.exception"]
_name = "sale.order"
@api.model
def _reverse_field(self):
return "sale_ids"
def detect_exceptions(self):
all_exceptions = super().detect_exceptions()
lines = self.mapped("order_line")
all_exceptions += lines.detect_exceptions()
return all_exceptions
@api.model
def test_all_draft_orders(self):
order_set = self.search([("state", "=", "draft")])
order_set.detect_exceptions()
return True
def _fields_trigger_check_exception(self):
return ["ignore_exception", "order_line", "state"]
def _check_sale_check_exception(self, vals):
check_exceptions = any(
field in vals for field in self._fields_trigger_check_exception()
)
if check_exceptions:
self.sale_check_exception()
def write(self, vals):
result = super().write(vals)
self._check_sale_check_exception(vals)
return result
def sale_check_exception(self):
orders = self.filtered(lambda s: s.state == "sale")
if orders:
orders._check_exception()
def action_confirm(self):
if self.detect_exceptions():
exception_map = {sale.id: sale.exception_ids.ids for sale in self}
self.env.cr.rollback()
for sale in self:
exception_ids = exception_map.get(sale.id, [])
sale.write({"exception_ids": [(6, 0, exception_ids)]})
return self._popup_exceptions()
return super().action_confirm()
def action_draft(self):
res = super().action_draft()
orders = self.filtered("ignore_exception")
orders.write({"ignore_exception": False})
return res
def _sale_get_lines(self):
self.ensure_one()
return self.order_line
@api.model
def _get_popup_action(self):
return self.env.ref("sale_exception.action_sale_exception_confirm")
def action_unlock(self):
return super(
SaleOrder, self.with_context(check_exception=False)
).action_unlock()