mirror of
https://github.com/bringout/oca-purchase.git
synced 2026-04-21 03:02:04 +02:00
Add oca-purchase submodule with 96 purchase modules moved from oca-workflow-process
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b0628ee8ea
commit
7378b233e9
3994 changed files with 334316 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import exception_rule
|
||||
from . import purchase
|
||||
from . import purchase_line
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright 2017 Akretion (http://www.akretion.com)
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ExceptionRule(models.Model):
|
||||
_inherit = "exception.rule"
|
||||
|
||||
purchase_ids = fields.Many2many(comodel_name="purchase.order", string="Purchases")
|
||||
model = fields.Selection(
|
||||
selection_add=[
|
||||
("purchase.order", "Purchase order"),
|
||||
("purchase.order.line", "Purchase order line"),
|
||||
],
|
||||
ondelete={"purchase.order": "cascade", "purchase.order.line": "cascade"},
|
||||
)
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
# Copyright 2017 Akretion (http://www.akretion.com)
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = ["purchase.order", "base.exception"]
|
||||
_name = "purchase.order"
|
||||
_order = "main_exception_id asc, date_order desc, name desc"
|
||||
|
||||
@api.model
|
||||
def test_all_draft_orders(self):
|
||||
order_set = self.search([("state", "=", "draft")])
|
||||
order_set.detect_exceptions()
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def _reverse_field(self):
|
||||
return "purchase_ids"
|
||||
|
||||
def detect_exceptions(self):
|
||||
all_exceptions = super().detect_exceptions()
|
||||
lines = self.mapped("order_line")
|
||||
all_exceptions += lines.detect_exceptions()
|
||||
return all_exceptions
|
||||
|
||||
def _fields_trigger_check_exception(self):
|
||||
return ["ignore_exception", "order_line", "state"]
|
||||
|
||||
def _check_purchase_check_exception(self, vals):
|
||||
check_exceptions = any(
|
||||
field in vals for field in self._fields_trigger_check_exception()
|
||||
)
|
||||
if check_exceptions:
|
||||
self.purchase_check_exception()
|
||||
|
||||
def write(self, vals):
|
||||
result = super().write(vals)
|
||||
self._check_purchase_check_exception(vals)
|
||||
return result
|
||||
|
||||
def purchase_check_exception(self):
|
||||
orders = self.filtered(lambda s: s.state == "purchase")
|
||||
if orders:
|
||||
orders._check_exception()
|
||||
|
||||
def button_unlock(self):
|
||||
return super(
|
||||
PurchaseOrder, self.with_context(check_exception=False)
|
||||
).button_unlock()
|
||||
|
||||
def button_confirm(self):
|
||||
if self.detect_exceptions() and not self.ignore_exception:
|
||||
return self._popup_exceptions()
|
||||
return super().button_confirm()
|
||||
|
||||
def button_draft(self):
|
||||
res = super().button_draft()
|
||||
for order in self:
|
||||
order.exception_ids = False
|
||||
order.main_exception_id = False
|
||||
order.ignore_exception = False
|
||||
return res
|
||||
|
||||
def _purchase_get_lines(self):
|
||||
self.ensure_one()
|
||||
return self.order_line
|
||||
|
||||
@api.model
|
||||
def _get_popup_action(self):
|
||||
action = self.env.ref("purchase_exception.action_purchase_exception_confirm")
|
||||
return action
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright 2017 Akretion (http://www.akretion.com)
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = ["purchase.order.line", "base.exception.method"]
|
||||
_name = "purchase.order.line"
|
||||
|
||||
ignore_exception = fields.Boolean(
|
||||
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
|
||||
)
|
||||
|
||||
def _get_main_records(self):
|
||||
return self.mapped("order_id")
|
||||
|
||||
@api.model
|
||||
def _reverse_field(self):
|
||||
return "purchase_ids"
|
||||
|
||||
def _detect_exceptions(self, rule):
|
||||
records = super()._detect_exceptions(rule)
|
||||
return records.mapped("order_id")
|
||||
Loading…
Add table
Add a link
Reference in a new issue