Skip to content

Commit 705dd6e

Browse files
author
kuay-odoo
committed
[ADD] zero_stock_blockage: approval checkbox for sale order confirmation
- Added `is_approval` boolean field to `sale.order` model. - Introduced computed field `is_approval_read` to control read-only access. - Only Sales Managers (based on group) can edit the approval checkbox. - Overrode `action_confirm` to block confirmation if not approved. - XML view updated to display approval checkbox next to payment terms. - Enforces a lightweight approval mechanism before confirming sales orders.
1 parent 03fea4d commit 705dd6e

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

zero_stock_blockage/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

zero_stock_blockage/__manifest__.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Zero Stock Blockage",
3+
"description": "Apply approval to confirm sale order",
4+
"version": "1.0",
5+
"depends": ["sale_management"],
6+
"data": [
7+
"views/sale_order.xml",
8+
],
9+
"auto-install": True,
10+
"application": False,
11+
"license": "LGPL-3",
12+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import sale_order
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from odoo import api, fields, models
2+
from odoo.exceptions import UserError
3+
4+
5+
class SaleOrder(models.Model):
6+
_inherit = "sale.order"
7+
8+
is_approval = fields.Boolean(string="Approval")
9+
is_approval_read = fields.Boolean(compute="_compute_to_set_approval")
10+
11+
@api.depends_context("uid")
12+
def _compute_to_set_approval(self):
13+
user = self.env.user
14+
is_user_manager = user.has_group("sales_team.group_sale_manager")
15+
for record in self:
16+
if is_user_manager:
17+
record.is_approval_read = True
18+
else:
19+
record.is_approval_read = False
20+
21+
def action_confirm(self):
22+
if not self.is_approval:
23+
raise UserError("You are not authenticated to Confirm Sale Order")
24+
25+
return super().action_confirm()
+13
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_approval_checkbox" model="ir.ui.view">
4+
<field name="name">sale.approval.checkbox</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="is_approval" readonly="not is_approval_read" />
10+
</xpath>
11+
</field>
12+
</record>
13+
</odoo>

0 commit comments

Comments
 (0)