Skip to content

Commit

Permalink
[17.0][ADD] sale_product_approval_purchase
Browse files Browse the repository at this point in the history
Depends on OCA#3108
  • Loading branch information
Patrick Wilson committed Apr 29, 2024
1 parent 0ad838f commit fc91b03
Show file tree
Hide file tree
Showing 17 changed files with 876 additions and 0 deletions.
114 changes: 114 additions & 0 deletions sale_product_approval_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
================================
Purchase Order Approval Workflow
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:83ed6597bcff5d34f8a8c1fb75578b65f2d75910965bd285dcaa2bdafe863e08
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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_product_approval_purchase
: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_product_approval_purchase
: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|

This module adds the purchase related settings to products and the
product states then control whether or not the product can be purchased.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

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

- The product states are configured to allow/block workflows for the
purchase order.
- The product is configured via check boxes.
- The 'Can be' check boxes are readonly and controlled by the state
configuration boxes and set accordingly based on the product state
settings.

Usage
=====

- A User will not be able to manually add a product that is not in an
approved state for PO.
- If a product is moved to a state where the 'Approved to be Purchased'
is not set, then the purchase order will show an exception:
- If a user tries clicks the 'Confirm Order' button, then a warning
shows informing the user that there is an exception.

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_product_approval_purchase%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
------------

- `Open Source Integrators <https://opensourceintegrators.com>`__.

- Chandresh Thakkar <[email protected]>
- Daniel Reis <[email protected]>
- Patrick Wilson <[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.

.. |maintainer-dreispt| image:: https://github.com/dreispt.png?size=40px
:target: https://github.com/dreispt
:alt: dreispt

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-dreispt|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions sale_product_approval_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
22 changes: 22 additions & 0 deletions sale_product_approval_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Purchase Order Approval Workflow",
"summary": "Purchase Order Product Apploval Workflow",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/sale-workflow",
"category": "Products",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"maintainers": ["dreispt"],
"development_status": "Alpha",
"depends": ["purchase", "sale_product_approval"],
"data": [
"views/product_state.xml",
"views/product_template.xml",
"views/purchase_order.xml",
"views/product_exception.xml",
],
}
6 changes: 6 additions & 0 deletions sale_product_approval_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import product_state
from . import product_template
from . import purchase_order
10 changes: 10 additions & 0 deletions sale_product_approval_purchase/models/product_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductState(models.Model):
_inherit = "product.state"

approved_purchase = fields.Boolean(string="Approved to be Purchased", default=True)
48 changes: 48 additions & 0 deletions sale_product_approval_purchase/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

purchase_ok = fields.Boolean(
string="Can be Purchased",
copy=False,
readonly=True,
)
candidate_purchase = fields.Boolean(string="Candidate to Purchase")

@api.model
def create(self, vals):
new = super().create(vals)
new._set_purchase_ok()
return new

def write(self, vals):
res = super().write(vals)
if "product_state_id" in vals or "candidate_purchase" in vals:
self._set_purchase_ok()
return res

def _set_purchase_ok(self):
for product in self:
if product.product_state_id:
product.purchase_ok = (
product.candidate_purchase
and product.product_state_id.approved_purchase
)
if not product.purchase_ok:
order_ids = (
self.env["purchase.order.line"]
.search(
[
("product_id", "in", product.product_variant_ids.ids),
("state", "in", ["draft", "sent", "to approve"]),
("approved_purchase", "=", True),
]
)
.mapped("order_id")
)
order_ids._log_exception_activity_purchase(product)
68 changes: 68 additions & 0 deletions sale_product_approval_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import date

from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import UserError


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

approved_purchase = fields.Boolean(
related="product_id.purchase_ok",
string="Approved for Purchase",
store=True,
default=True,
)


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

exceptions_purchase_approval = fields.Boolean(
compute="_compute_exceptions", string="Exception", default=False
)
override_exception = fields.Boolean(default=False)

@api.depends("order_line.approved_purchase")
def _compute_exceptions(self):
self.exceptions_purchase_approval = any(
not line.approved_purchase for line in self.order_line
)

def _log_exception_activity_purchase(self, product_id):
for order in self:
note = self._render_product_state_excep(order, product_id)
order.activity_schedule(
"mail.mail_activity_data_warning",
date.today(),
note=note,
user_id=order.user_id.id or SUPERUSER_ID,
)

def _render_product_state_excep(self, order, product_id):
values = {"purchase_order_ref": order, "product_ref": product_id}
return self.env["ir.ui.view"]._render_template(
template=self.env.ref(
"sale_product_approval_purchase.exception_on_product"
).id,
values=values,
)

def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
for purchase in self:
if (
purchase.exceptions_purchase_approval
and not purchase.override_exception
and not self._context.get("override_ex")
):
raise UserError(
_(
"You can not confirm this purchase order "
"because some products are not purchasable in this order."
)
)
return res
3 changes: 3 additions & 0 deletions sale_product_approval_purchase/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
6 changes: 6 additions & 0 deletions sale_product_approval_purchase/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- The product states are configured to allow/block workflows for the
purchase order.
- The product is configured via check boxes.
- The 'Can be' check boxes are readonly and controlled by the state
configuration boxes and set accordingly based on the product state
settings.
4 changes: 4 additions & 0 deletions sale_product_approval_purchase/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Open Source Integrators](https://opensourceintegrators.com).
- Chandresh Thakkar \<<[email protected]>\>
- Daniel Reis \<<[email protected]>\>
- Patrick Wilson \<<[email protected]>\>
2 changes: 2 additions & 0 deletions sale_product_approval_purchase/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds the purchase related settings to products and the
product states then control whether or not the product can be purchased.
6 changes: 6 additions & 0 deletions sale_product_approval_purchase/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- A User will not be able to manually add a product that is not in an
approved state for PO.
- If a product is moved to a state where the 'Approved to be Purchased'
is not set, then the purchase order will show an exception:
- If a user tries clicks the 'Confirm Order' button, then a warning
shows informing the user that there is an exception.
Loading

0 comments on commit fc91b03

Please sign in to comment.