Skip to content

[ADD] zero_stock_blockage: add module with stock approval field and access #738

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 2 commits 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
12 changes: 12 additions & 0 deletions zero_stock_blockage/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
'name': 'Zero Stock Approval',
'version': '1.0',
'depends': ['sale_management'],
'description': """
This module adds a zero stock approval feature to sale orders.
""",
'data': [
'views/sale_order_view.xml'
],
'license': 'LGPL-3'
}
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
19 changes: 19 additions & 0 deletions zero_stock_blockage/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import api, models, fields
from odoo.exceptions import UserError


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

stock_approval = fields.Boolean(string='Zero Stock Approvalexchttps')
stock_approval_readonly = fields.Boolean(compute='_compute_stock_approval_readonly')

@api.depends_context('uid')
def _compute_stock_approval_readonly(self):
self.stock_approval_readonly = self.env.user.has_group('sales_team.group_sale_manager')

def action_confirm(self):
for records in self:
if not records.stock_approval:
raise UserError("You are not allowed to confirm this order unless 'Zero Stock Approvalexchttps' is enabled.")
return super().action_confirm()
12 changes: 12 additions & 0 deletions zero_stock_blockage/views/sale_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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="stock_approval" readonly="not stock_approval_readonly"/>
</xpath>
</field>
</record>
</odoo>