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_product_approval_stock #3111

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 115 additions & 0 deletions sale_product_approval_stock/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
================================
Delivery Order Approval Workflow
================================

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

.. |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_stock
: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_stock
: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 shipping related settings to products and the
product states then control whether or not the product can be shipped.

.. 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
delivery 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 manufacturing to the DO.
- If a product is moved to a state where the 'Approved to be Shipped'
is not set, then the delivery order will show an exception:
- If a user tries clicks either the 'Mark As TODO' or 'Validate'
buttons, 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_stock%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 <cthakkar@opensourceintegrators.com>
- Daniel Reis <dreis@opensourceintegrators.com>
- Patrick Wilson <pwilson@opensourceintegrators.com>

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_stock>`_ 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_stock/__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_stock/__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": "Delivery Order Approval Workflow",
"summary": "Delivery 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": ["stock", "sale_product_approval"],
"data": [
"views/product_state.xml",
"views/product_template.xml",
"views/stock_picking.xml",
"views/delivery_order_exception.xml",
],
}
6 changes: 6 additions & 0 deletions sale_product_approval_stock/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 stock_picking
10 changes: 10 additions & 0 deletions sale_product_approval_stock/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_ship = fields.Boolean(string="Approved to be Shipped", default=True)
46 changes: 46 additions & 0 deletions sale_product_approval_stock/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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"

ship_ok = fields.Boolean(
string="Can be Shipped",
copy=False,
readonly=True,
)
candidate_ship = fields.Boolean(string="Candidate to Ship")

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

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

def _set_ship_ok(self):
for product in self:
if product.product_state_id:
product.ship_ok = (
product.candidate_ship and product.product_state_id.approved_ship
)
if not product.ship_ok:
pick_ids = self.env["stock.picking"].search(
[
("product_id", "=", product.id),
(
"state",
"in",
["draft", "confirmed", "waiting", "assigned"],
),
]
)
pick_ids._log_exception_activity_stock(product)
74 changes: 74 additions & 0 deletions sale_product_approval_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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 StockPicking(models.Model):
_inherit = "stock.picking"

do_exceptions = fields.Boolean(
compute="_compute_stock_exception", string="Stock Exception"
)
override_exception = fields.Boolean(default=False)

@api.depends("move_ids_without_package")
def _compute_stock_exception(self):
for rec in self:
rec.do_exceptions = any(
not line.do_line_exceptions for line in rec.move_ids_without_package
)

def _log_exception_activity_stock(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 = {"delivery_order_ref": order, "product_ref": product_id}
return self.env["ir.ui.view"]._render_template(
template=self.env.ref(
"sale_product_approval_stock.exception_on_delivery_order"
).id,
values=values,
)

def button_validate(self):
res = super().button_validate()
self.check_do_exception()
return res

def action_confirm(self):
res = super().action_confirm()
self.check_do_exception()
return res

def check_do_exception(self):
for do in self:
if (
do.do_exceptions
and not do.override_exception
and not self._context.get("override_ex")
):
raise UserError(
_(
"You can not do Validate/Mark as Done because some products are not "
"allowed in this delivery order."
)
)
return True


class StockMove(models.Model):
_inherit = "stock.move"

do_line_exceptions = fields.Boolean(related="product_id.ship_ok")
pick_state = fields.Selection(related="picking_id.state", string="Picking State")
3 changes: 3 additions & 0 deletions sale_product_approval_stock/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_stock/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
delivery 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_stock/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 \<<cthakkar@opensourceintegrators.com>\>
- Daniel Reis \<<dreis@opensourceintegrators.com>\>
- Patrick Wilson \<<pwilson@opensourceintegrators.com>\>
2 changes: 2 additions & 0 deletions sale_product_approval_stock/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds the shipping related settings to products and the
product states then control whether or not the product can be shipped.
7 changes: 7 additions & 0 deletions sale_product_approval_stock/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- A User will not be able to manually add a product that is not in an
approved state for manufacturing to the DO.
- If a product is moved to a state where the 'Approved to be Shipped' is
not set, then the delivery order will show an exception:
- If a user tries clicks either the 'Mark As TODO' or 'Validate'
buttons, then a warning shows informing the user that there is an
exception.