Skip to content
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

[17.0] [ADD] sale_blanket_order_tier_validation #3277

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
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
112 changes: 112 additions & 0 deletions sale_blanket_order_tier_validation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
===================================
Sale Blanket Orders Tier Validation
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:adb4549c4d5a6fc42fc865560f51f2d2ab705b8ac7a18c08cced1309637bf945
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/licence-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/17.0/sale_blanket_order_tier_validation
: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-17-0/sale-workflow-17-0-sale_blanket_order_tier_validation
: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=17.0
:alt: Try me on Runboat

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

Extends the functionality of your Sale Blanket Orders to support a tier
validation process

**Table of contents**

.. contents::
:local:

Installation
============

This module depends on ``base_tier_validation``. You can find it at
`OCA/server-ux <https://github.com/OCA/server-ux>`__

Configuration
=============

To configure this module, you need to:

1. Go to *Settings > Technical > Tier Validations > Tier Definition*.
2. Create as many tiers as you want for Purchase Order model.

Usage
=====

To use this module, you need to:

1. Create a Sale Blanket Orders triggering at least one "Tier
Definition".
2. Click on *Request Validation* button.
3. Under the tab *Reviews* have a look to pending reviews and their
statuses.
4. Once all reviews are validated click on *Confirm Order*.

Additional features:

- You can filter the Blanket Orders requesting your review through the
filter *Needs my Review*.
- User with rights to confirm the Blanket Orders (validate all tiers
that would be generated) can directly do the operation, this is,
there is no need for her/him to request a validation.

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_blanket_order_tier_validation%0Aversion:%2017.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
-------

* Open Source Integrators

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

- Patrick Wilson <[email protected]>
- Nikul Chaudhary <[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/17.0/sale_blanket_order_tier_validation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sale_blanket_order_tier_validation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
23 changes: 23 additions & 0 deletions sale_blanket_order_tier_validation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Blanket Orders Tier Validation",
"summary": """
Extends the functionality of your Sale Blanket Orders
to support a tier validation process.
""",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"category": "Sales",
"version": "17.0.1.0.0",
"depends": [
"sale_blanket_order",
"base_tier_validation",
],
"data": [
"views/sale_blanket_order_views.xml",
],
"application": False,
"installable": True,
}
4 changes: 4 additions & 0 deletions sale_blanket_order_tier_validation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import sale_blanket_order
from . import tier_definition
56 changes: 56 additions & 0 deletions sale_blanket_order_tier_validation/models/sale_blanket_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import float_is_zero


class SaleBlanketOrder(models.Model):
"""
Adding tier validation functionality to Blanket Orders.
"""

_name = "sale.blanket.order"
_inherit = ["sale.blanket.order", "tier.validation"]
_state_from = ["draft"]
_state_to = ["open", "done", "expired"]

_tier_validation_manual_config = False

@api.depends(
"line_ids.remaining_uom_qty",
"validity_date",
"confirmed",
)
def _compute_state(self):
"""Complete override of Blanket Order Compute State Method:
The OCA Blanket Order module sets state via compute method which messes
with tier validation checks so we are going to instead set the state
to 'Open' only when clicking confirmed. This also forces process as before
just changing data would reset BO back to Open if expired."""
today = fields.Date.today()
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for order in self:
if not order.confirmed:
order.state = "draft"
elif order.validity_date <= today:
order.state = "expired"

Check warning on line 38 in sale_blanket_order_tier_validation/models/sale_blanket_order.py

View check run for this annotation

Codecov / codecov/patch

sale_blanket_order_tier_validation/models/sale_blanket_order.py#L38

Added line #L38 was not covered by tests
elif float_is_zero(
sum(
order.line_ids.filtered(lambda line: not line.display_type).mapped(
"remaining_uom_qty"
)
),
precision_digits=precision,
):
order.state = "done"

Check warning on line 47 in sale_blanket_order_tier_validation/models/sale_blanket_order.py

View check run for this annotation

Codecov / codecov/patch

sale_blanket_order_tier_validation/models/sale_blanket_order.py#L47

Added line #L47 was not covered by tests
# Removing else statement from original method
# else:
# order.state = "open"

def action_confirm(self):
"""Set the state to 'Open' when clicking confirmed instead of during compute."""
for rec in self:
rec.write({"state": "open"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I did OCA/server-ux#939 so that tier validations can be applied to computed state fields as in this model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider reviewing that change and refactoring this module to work with it? You wouldn't have to jump through hoops like you do in the code above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the refactoring in ursais#14. What do you think?

return super().action_confirm()
18 changes: 18 additions & 0 deletions sale_blanket_order_tier_validation/models/tier_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models


class TierDefinition(models.Model):
"""
Add Sale Blanket Order model to tier definitions.
"""

_inherit = "tier.definition"

@api.model
def _get_tier_validation_model_names(self):
"""This method adds the Sale Blanket Order model to tier definitions."""
res = super()._get_tier_validation_model_names()
res.append("sale.blanket.order")
return res
3 changes: 3 additions & 0 deletions sale_blanket_order_tier_validation/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions sale_blanket_order_tier_validation/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To configure this module, you need to:

1. Go to *Settings \> Technical \> Tier Validations \> Tier
Definition*.
2. Create as many tiers as you want for Purchase Order model.
2 changes: 2 additions & 0 deletions sale_blanket_order_tier_validation/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Patrick Wilson \<<[email protected]>\>
- Nikul Chaudhary \<<[email protected]>\>
2 changes: 2 additions & 0 deletions sale_blanket_order_tier_validation/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Extends the functionality of your Sale Blanket Orders
to support a tier validation process
2 changes: 2 additions & 0 deletions sale_blanket_order_tier_validation/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module depends on `base_tier_validation`. You can find it at
[OCA/server-ux](https://github.com/OCA/server-ux)
15 changes: 15 additions & 0 deletions sale_blanket_order_tier_validation/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
To use this module, you need to:

1. Create a Sale Blanket Orders triggering at least one "Tier Definition".
2. Click on *Request Validation* button.
3. Under the tab *Reviews* have a look to pending reviews and their
statuses.
4. Once all reviews are validated click on *Confirm Order*.

Additional features:

- You can filter the Blanket Orders requesting your review through the filter
*Needs my Review*.
- User with rights to confirm the Blanket Orders (validate all tiers that would be
generated) can directly do the operation, this is, there is no need
for her/him to request a validation.
Loading
Loading