Skip to content
Open
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
85 changes: 85 additions & 0 deletions sale_order_approval_block/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========================
Sale Order Approval Block
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:00866fd230bf28cbdee4973f95d7a710b5e1a7df2a50afc6b72ab54d87311e6e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/19.0/sale_order_approval_block
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-19-0/sale-workflow-19-0-sale_order_approval_block
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Adds an approval block mechanism to Sale Orders, allowing them to be
blocked with a specific reason until explicitly released.

Blocked orders cannot be confirmed until the block is removed.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_approval_block%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ForgeFlow

Contributors
------------

- `ForgeFlow <https://www.forgeflow.com>`__

- Aaron Henriquez [email protected]

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/19.0/sale_order_approval_block>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sale_order_approval_block/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
19 changes: 19 additions & 0 deletions sale_order_approval_block/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Sale Order Approval Block",
"version": "19.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
"summary": "Block sale orders with approval reasons",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"sale_exception",
],
"data": [
"security/ir.model.access.csv",
"security/sale_order_approval_block_security.xml",
"data/sale_exception_data.xml",
"views/sale_approval_block_reason_view.xml",
"views/sale_order_view.xml",
],
}
14 changes: 14 additions & 0 deletions sale_order_approval_block/data/sale_exception_data.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="so_excep_approval_block" model="exception.rule">
<field name="name">Approval Blocked</field>
<field name="description">The approval has been blocked,
with a Blocking reason.</field>
<field name="sequence">100</field>
<field name="model">sale.order</field>
<field
name="code"
>if 'approval_block_id' in self._fields and self.approval_block_id: failed = True</field>
<field name="active" eval="True" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions sale_order_approval_block/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_approval_block_reason
from . import sale_order
10 changes: 10 additions & 0 deletions sale_order_approval_block/models/sale_approval_block_reason.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class SaleApprovalBlockReason(models.Model):
_name = "sale.approval.block.reason"
_description = "Sale Approval Block Reason"

name = fields.Char(required=True)
description = fields.Text()
active = fields.Boolean(default=True)
63 changes: 63 additions & 0 deletions sale_order_approval_block/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from odoo import api, fields, models


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

approval_block_id = fields.Many2one(
comodel_name="sale.approval.block.reason",
string="Approval Block Reason",
)
approval_blocked = fields.Boolean(
compute="_compute_approval_blocked",
)

@api.depends("approval_block_id")
def _compute_approval_blocked(self):
for rec in self:
rec.approval_blocked = bool(rec.approval_block_id)

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for vals, so in zip(vals_list, records, strict=False):
if vals.get("approval_block_id"):
so.message_post(
body=self.env._(
'Order "%(order)s" blocked with reason "%(reason)s"',
order=so.name,
reason=so.approval_block_id.name,
)
)
return records

def write(self, vals):
res = super().write(vals)
for so in self:
if vals.get("approval_block_id"):
so.message_post(
body=self.env._(
'Order "%(order)s" blocked with reason "%(reason)s"',
order=so.name,
reason=so.approval_block_id.name,
)
)
elif "approval_block_id" in vals and not vals["approval_block_id"]:
so.message_post(
body=self.env._(
'Order "%(order)s" approval block released.',
order=so.name,
)
)
return res

def button_approve(self, force=False):
for rec in self:
if rec.approval_block_id:
rec.button_release_approval_block()
return super().button_approve(force=force)

def button_release_approval_block(self):
for order in self:
order.approval_block_id = False
return True
3 changes: 3 additions & 0 deletions sale_order_approval_block/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions sale_order_approval_block/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ForgeFlow](https://www.forgeflow.com)
- Aaron Henriquez <[email protected]>
4 changes: 4 additions & 0 deletions sale_order_approval_block/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Adds an approval block mechanism to Sale Orders, allowing them to be
blocked with a specific reason until explicitly released.

Blocked orders cannot be confirmed until the block is removed.
3 changes: 3 additions & 0 deletions sale_order_approval_block/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sale_order_approval_block_reason,sale.order.block.reason,model_sale_approval_block_reason,sales_team.group_sale_salesman,1,0,0,0
access_sale_order_approval_block_reason_manager,sale.order.block.reason,model_sale_approval_block_reason,sales_team.group_sale_manager,1,1,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="group_quote_approval_block" model="res.groups">
<field name="name">Release Quote with approval block</field>
<field
name="user_ids"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>
<record id="sales_team.group_sale_manager" model="res.groups">
<field name="implied_ids" eval="[(4, ref('group_quote_approval_block'))]" />
</record>
</odoo>
Loading