Skip to content

[ADD] zero stock blockage: added zero stock block approval functionality #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zero_stock_blockage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions zero_stock_blockage/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ZERO STOCK BLOCKAGE",
"version": "1.0",
"summary": "Restrict Sales Order Confirmation if stock is zero",
"description": "Adds approval mechanism for sales orders with zero stock.",
"category": "Sales",
"application": True,
"depends": ["base", "sale"],
"data": [
"views/zero_stock_blockage_views.xml",
],
"license": "LGPL-3",
"installable": True,
}
1 change: 1 addition & 0 deletions zero_stock_blockage/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
25 changes: 25 additions & 0 deletions zero_stock_blockage/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from odoo import fields, models, api
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = "sale.order"

zero_stock_approval = fields.Boolean(string="Approval", default="false")

def action_confirm(self):
result = super().action_confirm()
for order in self:
if not order.zero_stock_approval:
raise UserError(
"This sale order cannot be confirmed without zero stock approval"
)
return result

@api.model
def fields_get(self, allfields=None, attributes=None):
res = super().fields_get(allfields, attributes)
if not self.env.user.has_group("sales_team.group_sale_manager"):
if "zero_stock_approval" in res:
res["zero_stock_approval"]["readonly"] = True
return res
14 changes: 14 additions & 0 deletions zero_stock_blockage/views/zero_stock_blockage_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_order_form_inherit_zero_stock" model="ir.ui.view">
<field name="name">sale.order.form.zero.stock</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='payment_term_id']" position="after">
<field name="zero_stock_approval"
/>
</xpath>
</field>
</record>
</odoo>