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

===================
Sale Minimum Amount
===================

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

.. |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_minimum_amount
: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_minimum_amount
: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|

This module enforces a minimum untaxed Sale Order amount per customer by
automatically applying a Sale Approval Block Reason when the amount is
below the configured threshold.

**Table of contents**

.. contents::
:local:

Usage
=====

If the untaxed amount of a Sale Order is below the configured minimum,
the order is automatically blocked and cannot be confirmed until the
approval block is released or the amount exceeds the minimum.

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_minimum_amount%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
=======

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_minimum_amount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_minimum_amount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions sale_minimum_amount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Sale Minimum Amount",
"version": "19.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
"summary": "Minimum sale order amount per customer",
"author": "Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"sale_order_approval_block",
],
"data": [
"data/sale_block_reason_data.xml",
"views/sale_order_view.xml",
"views/res_partner_view.xml",
],
"installable": True,
}
8 changes: 8 additions & 0 deletions sale_minimum_amount/data/sale_block_reason_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<odoo>
<record id="minimum_amount_block_reason" model="sale.approval.block.reason">
<field name="name">Minimum Amount per Customer</field>
<field
name="description"
>Set total minimum amount (before taxes) for a customer.</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions sale_minimum_amount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_partner
from . import sale_order
from . import sale_order_line
7 changes: 7 additions & 0 deletions sale_minimum_amount/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

minimum_so_amount = fields.Float(string="Minimum Sale Amount")
28 changes: 28 additions & 0 deletions sale_minimum_amount/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo import api, fields, models


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

minimum_so_amount = fields.Float(
related="partner_id.minimum_so_amount",
string="Sale Minimum Amount",
)

@api.constrains("partner_id")
def _check_minimum_amount(self):
for rec in self:
block_reason = rec.env.ref(
"sale_minimum_amount.minimum_amount_block_reason",
raise_if_not_found=False,
)
under_min = rec.amount_untaxed < rec.minimum_so_amount
force_release = rec.env.context.get(
"force_so_approval_block_release", False
)

if under_min and not rec.approval_block_id and not force_release:
rec.approval_block_id = block_reason
elif not under_min and rec.approval_block_id == block_reason:
rec.approval_block_id = False
return True
13 changes: 13 additions & 0 deletions sale_minimum_amount/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import api, models


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

@api.model
def _check_minimum_amount_fields(self):
return ["product_uom_qty", "price_unit"]

@api.constrains(lambda self: self._check_minimum_amount_fields())
def _constrains_minimum_amount(self):
self.order_id._check_minimum_amount()
3 changes: 3 additions & 0 deletions sale_minimum_amount/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions sale_minimum_amount/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Go to Sales / Customers
- Open a customer
- Set the field "Minimum Sale Amount"
2 changes: 2 additions & 0 deletions sale_minimum_amount/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]>
3 changes: 3 additions & 0 deletions sale_minimum_amount/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module enforces a minimum untaxed Sale Order amount per customer by
automatically applying a Sale Approval Block Reason when the amount is
below the configured threshold.
3 changes: 3 additions & 0 deletions sale_minimum_amount/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
If the untaxed amount of a Sale Order is below the configured minimum,
the order is automatically blocked and cannot be confirmed until the
approval block is released or the amount exceeds the minimum.
Loading
Loading