Skip to content

Commit c9eec9e

Browse files
committed
[ADD] sale_order_zero_stock_blockage: add manager approval on insufficient stock
Currently, a sales user can confirm a Quotation even if it contains no products or if the products have insufficient stock compared to the order quantity. This leads to the creation of invalid Sales Orders, which negatively impacts inventory planning and invoicing. This module introduces a validation to the Sales Order confirmation process to prevent these issues. The following checks are added: 1. Prevent confirmation if the order has no lines. 2. Prevent confirmation if the product stock is insufficient. To bypass the insufficient stock restriction, a user with the 'Sales Manager' group must enable the new 'Approval' (zero_stock_approval) field on the order. Technical details: - Model `sale.order`: Added `zero_stock_approval` Boolean field. - Method `fields_get`: Overridden to set `zero_stock_approval` as readonly for users who are not in the `sales_team.group_sale_manager` group. - Method `action_confirm`: Added logic to raise a `UserError` if: - The order has no lines. - A product's `qty_available` is less than `product_uom_qty` (for goods) and the `zero_stock_approval` is not enabled. Task-5382939
1 parent b68a192 commit c9eec9e

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Sale Order Zero Stock Blockage",
3+
"description": """
4+
Zero Stock Blockage is module to prevent order to confirm if product is out of stock.
5+
6+
But if manager wants then he can aprove that order.
7+
""",
8+
"version": "1.0",
9+
"depends": ['sale_management', 'stock'],
10+
"author": "danal",
11+
"category": "Category",
12+
"license": "LGPL-3",
13+
"data": [
14+
"views/sale_order_view.xml",
15+
],
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import sale_order
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from odoo.exceptions import UserError
2+
3+
from odoo import fields, models, api
4+
5+
6+
class SaleOrder(models.Model):
7+
_inherit = 'sale.order'
8+
9+
zero_stock_approval = fields.Boolean(string="Approval", copy=False)
10+
11+
@api.model
12+
def fields_get(self, allfields=None, attributes=None):
13+
res = super().fields_get(allfields, attributes)
14+
if not self.env.user.has_group("sales_team.group_sale_manager"):
15+
if "zero_stock_approval" in res:
16+
res["zero_stock_approval"]["readonly"] = True
17+
return res
18+
19+
def action_confirm(self):
20+
for record in self:
21+
if not record.order_line:
22+
raise UserError("You cannot confirm a Quotation without any products.")
23+
if record.zero_stock_approval:
24+
return super().action_confirm()
25+
for line in record.order_line:
26+
if (
27+
line.product_id.qty_available < line.product_uom_qty
28+
and line.product_id.type == "consu"
29+
and not record.zero_stock_approval
30+
and not self.env.user.has_group("sales_team.group_sale_manager")
31+
):
32+
raise UserError(
33+
"Cannot confirm this Sale Order due to insufficient stock.\n\nPlease get approval or adjust the quantities."
34+
)
35+
return super().action_confirm()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<record id="sale_order_view_inherit" model="ir.ui.view">
4+
<field name="name">sale.order.view.inherit</field>
5+
<field name="model">sale.order</field>
6+
<field name="inherit_id" ref="sale.view_order_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//field[@name='payment_term_id']" position="after">
9+
<field name="zero_stock_approval"/>
10+
</xpath>
11+
</field>
12+
</record>
13+
</odoo>

0 commit comments

Comments
 (0)