Skip to content

Commit 7a85bed

Browse files
committed
[ADD] dev_zero_stock_blockage: implemented zero stock approval task
Ensure that Sales Orders cannot be confirmed without Zero Stock Approval, restricting Sales Users from modifying the field while allowing only Sales Administrators to approve orders. --> Inherited Model - Inherited the main model sale order. - Added a new boolean field zero stock approval in the sale order model. - Overridden fields get() to make the field read-only for Sales Users (sales person) - Made action confirm() to restrict order confirmation unless zero stock approval is checked. - Implemented sale order views xml to display zero stock approval after payment term id. Access Rights - Sales Administrator - Can edit the field. - Sales User : Read-only access. - Created a boolean field 'zero_stock_approval' to allow admins to approve orders with low stock - Only Sales Manager can edit this field; others see it as readonly - If any product has demand > available stock and the user is not a manager, they must get admin approval - Blocked order confirmation if quantity is less than available and no approval is given - Skipped stock check for service and combo products (only checked consu {goods} type) - Added a warning message popup when admin gives approval for a product with low stock Ensures better control over order confirmation based on stock approval.
1 parent 4c650f3 commit 7a85bed

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

dev_zero_stock_blockage/__init__.py

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': 'Dev Zero Stock Blockage',
3+
'version': '1.0',
4+
'summary': 'Add zero stock blockage feature to sale order',
5+
'description': """
6+
Add zero stock blockage feature to sale order
7+
""",
8+
'author': 'Raghav Agiwal',
9+
'depends': ['sale_management', 'stock'],
10+
'data': [
11+
'views/sale_order_views.xml',
12+
],
13+
'installable': True,
14+
'application': True,
15+
'license': 'LGPL-3'
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import sale_order
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from odoo import api, models, fields
2+
from odoo.exceptions import UserError
3+
4+
5+
class SaleOrder(models.Model):
6+
_inherit = 'sale.order'
7+
8+
zero_stock_approval = fields.Boolean(
9+
string="Approval",
10+
)
11+
12+
@api.onchange('zero_stock_approval')
13+
def _onchange_zero_stock_approval(self):
14+
if self.zero_stock_approval and self.env.user.has_group('sales_team.group_sale_manager'):
15+
for line in self.order_line:
16+
if line.product_id.type in ['consu', 'product'] and line.product_uom_qty > line.product_id.qty_available:
17+
return {
18+
'warning': {
19+
'title': "Heads Up!",
20+
'message': (
21+
f"Just a quick reminder..!! You are approving this order where product '{line.product_id.display_name}' "
22+
f"has demand {line.product_uom_qty} > available {line.product_id.qty_available}."
23+
)
24+
}
25+
}
26+
27+
@api.model
28+
def fields_get(self, allfields=None, attributes=None):
29+
fields = super().fields_get(allfields=allfields, attributes=attributes)
30+
if not self.env.user.has_group('sales_team.group_sale_manager'):
31+
if "zero_stock_approval" in fields:
32+
fields['zero_stock_approval']['readonly'] = True
33+
return fields
34+
35+
def action_confirm(self):
36+
for order in self:
37+
for line in order.order_line:
38+
demand_qty = line.product_uom_qty
39+
available_qty = line.product_id.qty_available
40+
41+
# if demand_qty <= 0:
42+
# raise UserError(
43+
# f"You cannot confirm this Sale Order.\n"
44+
# f"Product '{line.product_id.display_name}' has a quantity of {demand_qty}.\n"
45+
# f"Quantity must be greater than zero."
46+
# )
47+
48+
if (
49+
line.product_id.type == 'consu'
50+
and demand_qty > available_qty
51+
and not self.env.user.has_group('sales_team.group_sale_manager')
52+
and not order.zero_stock_approval
53+
):
54+
raise UserError(
55+
f"Cannot confirm this Sale Order.\n"
56+
f"Product '{line.product_id.display_name}' has only {available_qty} in stock, "
57+
f"but {demand_qty} is requested.\n"
58+
f"Approval is required to proceed."
59+
)
60+
return super().action_confirm()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<record id="view_sale_order_form" model="ir.ui.view">
4+
<field name="name">sale.order.form</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+
14+
</odoo>

0 commit comments

Comments
 (0)