Files
Odoo-18.0-20251222/sale_block_no_stock/models/sale_order.py
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

42 lines
1.5 KiB
Python
Executable File

# Copyright 2024 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
from odoo import models
class SaleOrder(models.Model):
_inherit = "sale.order"
def action_confirm(self):
"""Check the stock of the products before confirming the sale order."""
if self.env.context.get("skip_block_no_stock_check") and all(
self.env.user in company.sale_line_block_allowed_groups.users
for company in self.mapped("company_id")
):
return super().action_confirm()
for record in self:
field_to_check = record.sudo().company_id.sale_line_field_block
if not field_to_check:
continue
blocked_lines = self.env["sale.order.line"].browse()
lines = record.order_line.filtered_domain(
[("product_type", "=", "consu"), ("is_storable", "=", True)]
)
for line in lines:
if line.product_uom_qty > line[field_to_check.name]:
blocked_lines |= line
if blocked_lines:
action = self.env["ir.actions.actions"]._for_xml_id(
"sale_block_no_stock.sale_order_block_wizard_action"
)
action["context"] = {
"default_sale_line_block_ids": [
(0, 0, {"sale_line_id": line.id}) for line in blocked_lines
]
}
return action
return super().action_confirm()