mirror of
https://github.com/bringout/oca-workflow-process.git
synced 2026-04-23 04:32:05 +02:00
Initial commit: OCA Workflow Process packages (456 packages)
This commit is contained in:
commit
d366e42934
18799 changed files with 1284507 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
from . import exception_rule
|
||||
from . import sale_order
|
||||
from . import sale_order_line
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# 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 fields, models
|
||||
|
||||
|
||||
class ExceptionRule(models.Model):
|
||||
_inherit = "exception.rule"
|
||||
|
||||
model = fields.Selection(
|
||||
selection_add=[
|
||||
("sale.order", "Sale order"),
|
||||
("sale.order.line", "Sale order line"),
|
||||
],
|
||||
ondelete={
|
||||
"sale.order": "cascade",
|
||||
"sale.order.line": "cascade",
|
||||
},
|
||||
)
|
||||
sale_ids = fields.Many2many("sale.order", string="Sales")
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
# 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():
|
||||
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()
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
# © 2019 Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import html
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = ["sale.order.line", "base.exception.method"]
|
||||
_name = "sale.order.line"
|
||||
|
||||
exception_ids = fields.Many2many(
|
||||
"exception.rule", string="Exceptions", copy=False, readonly=True
|
||||
)
|
||||
exceptions_summary = fields.Html(
|
||||
readonly=True, compute="_compute_exceptions_summary"
|
||||
)
|
||||
ignore_exception = fields.Boolean(
|
||||
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
|
||||
)
|
||||
is_exception_danger = fields.Boolean(compute="_compute_is_exception_danger")
|
||||
|
||||
@api.depends("exception_ids", "ignore_exception")
|
||||
def _compute_is_exception_danger(self):
|
||||
for rec in self:
|
||||
rec.is_exception_danger = (
|
||||
len(rec.exception_ids) > 0 and not rec.ignore_exception
|
||||
)
|
||||
|
||||
@api.depends("exception_ids", "ignore_exception")
|
||||
def _compute_exceptions_summary(self):
|
||||
for rec in self:
|
||||
if rec.exception_ids and not rec.ignore_exception:
|
||||
rec.exceptions_summary = rec._get_exception_summary()
|
||||
else:
|
||||
rec.exceptions_summary = False
|
||||
|
||||
def _get_exception_summary(self):
|
||||
return "<ul>%s</ul>" % "".join(
|
||||
[
|
||||
"<li>%s: <i>%s</i></li>"
|
||||
% tuple(map(html.escape, (e.name, e.description)))
|
||||
for e in self.exception_ids
|
||||
]
|
||||
)
|
||||
|
||||
def _get_main_records(self):
|
||||
return self.mapped("order_id")
|
||||
|
||||
@api.model
|
||||
def _reverse_field(self):
|
||||
return "sale_ids"
|
||||
|
||||
def _detect_exceptions(self, rule):
|
||||
records = super()._detect_exceptions(rule)
|
||||
# Thanks to the new flush of odoo 13.0, queries will be optimized
|
||||
# together at the end even if we update the exception_ids many times.
|
||||
# On previous versions, this could be unoptimized.
|
||||
(self - records).exception_ids = [(3, rule.id)]
|
||||
records.exception_ids = [(4, rule.id)]
|
||||
return records.mapped("order_id")
|
||||
Loading…
Add table
Add a link
Reference in a new issue