-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #3108
Open
patrickrwilson
wants to merge
1
commit into
OCA:17.0
Choose a base branch
from
ursais:add_sale_product_approval
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
===================== | ||
Sale Product Approval | ||
===================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:5290a42368d5045c781cfd4477d2cb3a5310ed2dc8a0d5168a0f6109c3ca9ba9 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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 | ||
: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 | ||
: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 links the 'Can be sold' field to the states. The states then | ||
control whether or not the product can be sold or not in the particular | ||
state. | ||
|
||
.. 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 | ||
============= | ||
|
||
- Create product states. | ||
- Check the 'Approved to be added to SO' box on the states where the | ||
product is allowed to be added to an SO when it's in that state. | ||
- Check the 'Approved to be sold' box on the states where the product | ||
is allowed to be sold when it's in that state. | ||
|
||
Usage | ||
===== | ||
|
||
- When a product is moved to a state where it's approved, the 'Can be | ||
sold' box should be checked and the product is selectable on sales | ||
quotes. | ||
- If the product is not in a state where it's approved to be sold, then | ||
the 'Can be sold' check box is not checked and the product can not be | ||
added to sales quotes. | ||
- If it's not approved, any sales quote that already contained the | ||
product will show a warning and have an exception activity. | ||
|
||
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%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> | ||
- Hardik Suthar <hsuthar@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>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2021 Open Source Integrators | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from .hooks import _set_candidate_sale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2021 Open Source Integrators | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Sale Product Approval", | ||
"summary": """Control whether or not the product can be sold or not | ||
in the particular state""", | ||
"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": ["product_state", "sale_management", "stock"], | ||
"data": [ | ||
"security/res_groups.xml", | ||
"views/menu_items.xml", | ||
"views/product_exception.xml", | ||
"views/product_state.xml", | ||
"views/product_template.xml", | ||
"views/sale_order.xml", | ||
], | ||
"post_init_hook": "_set_candidate_sale", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2019 ForgeFlow S.L. | ||
# (http://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
def _set_candidate_sale(env): | ||
""" | ||
This post-init-hook will update last price information for all products | ||
""" | ||
product_obj = env["product.template"] | ||
products = product_obj.search([("sale_ok", "=", True)]) | ||
products.write({"candidate_sale": True, "sale_ok": True}) | ||
products.write({"candidate_sale_confirm": True, "sale_ok_confirm": True}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright 2021 Open Source Integrators | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import product_product | ||
from . import product_state | ||
from . import sale_order | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# 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" | ||
|
||
sale_ok = fields.Boolean( | ||
string="Can be added to Quote", | ||
copy=False, | ||
readonly=True, | ||
) | ||
sale_ok_confirm = fields.Boolean( | ||
string="Can be Sold", | ||
copy=False, | ||
readonly=True, | ||
) | ||
candidate_sale = fields.Boolean( | ||
string="Candidate to add to Quote", | ||
compute="_compute_candidate_sale_confirm", | ||
store=True, | ||
readonly=False, | ||
) | ||
candidate_sale_confirm = fields.Boolean( | ||
string="Candidate to be Sold", | ||
compute="_compute_candidate_sale_confirm", | ||
store=True, | ||
readonly=False, | ||
) | ||
can_edit_candidate = fields.Boolean(compute="_compute_can_edit_candidate") | ||
|
||
def _compute_can_edit_candidate(self): | ||
self.update( | ||
{ | ||
"can_edit_candidate": self.env.user.has_group( | ||
"sale_product_approval.group_product_administrator" | ||
) | ||
} | ||
) | ||
|
||
@api.depends("candidate_sale_confirm") | ||
def _compute_candidate_sale_confirm(self): | ||
for product in self: | ||
if product.candidate_sale_confirm: | ||
product.candidate_sale = True | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
templates = super().create(vals_list) | ||
templates._set_sale_ok_product() | ||
return templates | ||
|
||
def write(self, vals): | ||
res = super().write(vals) | ||
if ( | ||
"product_state_id" in vals | ||
or "candidate_sale" in vals | ||
or "candidate_sale_confirm" in vals | ||
): | ||
self._set_sale_ok_product() | ||
return res | ||
|
||
def _set_sale_ok_product(self): | ||
order_ids = ( | ||
self.env["sale.order.line"] | ||
.search( | ||
[ | ||
("product_id", "in", self.product_variant_ids.ids), | ||
("state", "in", ["draft", "sent"]), | ||
("approved_sale_confirm", "=", True), | ||
] | ||
) | ||
.mapped("order_id") | ||
) | ||
for product in self: | ||
if product.product_state_id: | ||
product.sale_ok = ( | ||
product.candidate_sale and product.product_state_id.approved_sale | ||
) | ||
product.sale_ok_confirm = ( | ||
product.candidate_sale_confirm | ||
and product.product_state_id.approved_sale_confirm | ||
) | ||
|
||
if not product.sale_ok_confirm: | ||
order_ids._log_exception_activity_sale(product) | ||
|
||
@api.model | ||
def _get_default_product_state_id(self): | ||
return self.env.ref( | ||
"product_state.product_state_draft", raise_if_not_found=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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_sale = fields.Boolean(string="Approved to be added to SO", default=True) | ||
approved_sale_confirm = fields.Boolean(string="Approved to be Sold", default=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2021 Open Source Integrators | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import SUPERUSER_ID, _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
exceptions_sale_approval_confirm = fields.Boolean( | ||
compute="_compute_exceptions_sale_approval_confirm", | ||
string="Exception", | ||
) | ||
override_saleable_exception = fields.Boolean() | ||
|
||
@api.depends("order_line.approved_sale_confirm") | ||
def _compute_exceptions_sale_approval_confirm(self): | ||
for so in self: | ||
so.exceptions_sale_approval_confirm = any( | ||
not line.approved_sale_confirm | ||
for line in so.order_line.filtered(lambda x: not x.display_type) | ||
) | ||
|
||
def _log_exception_activity_sale(self, product_id): | ||
for order in self: | ||
# Convert current date to the timezone of the user set on the order | ||
local_date = fields.Datetime.context_timestamp( | ||
order.user_id, fields.Datetime.now() | ||
).date() | ||
|
||
note = self._render_product_approval_exception(order, product_id) | ||
order.activity_schedule( | ||
"mail.mail_activity_data_warning", | ||
local_date, | ||
note=note, | ||
user_id=order.user_id.id or SUPERUSER_ID, | ||
) | ||
|
||
def _render_product_approval_exception(self, order, product_id): | ||
values = {"sale_order_ref": order, "product_ref": product_id} | ||
return self.env["ir.ui.view"]._render_template( | ||
template=self.env.ref("sale_product_approval.exception_on_product").id, | ||
values=values, | ||
) | ||
|
||
def action_confirm(self): | ||
res = super().action_confirm() | ||
for sale in self: | ||
if ( | ||
sale.exceptions_sale_approval_confirm | ||
and not sale.override_saleable_exception | ||
): | ||
raise UserError( | ||
_( | ||
"You can not confirm this sale order " | ||
"because some products are not sellable in this order." | ||
) | ||
) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2021 Open Source Integrators | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
approved_sale_confirm = fields.Boolean( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really needed as stored value ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, see. For the search. |
||
related="product_id.sale_ok_confirm", | ||
string="Approved for Sale", | ||
store=True, | ||
default=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- Create product states. | ||
- Check the 'Approved to be added to SO' box on the states where the | ||
product is allowed to be added to an SO when it's in that state. | ||
- Check the 'Approved to be sold' box on the states where the product is | ||
allowed to be sold when it's in that state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- [Open Source Integrators](https://opensourceintegrators.com). | ||
- Chandresh Thakkar \<<cthakkar@opensourceintegrators.com>\> | ||
- Daniel Reis \<<dreis@opensourceintegrators.com>\> | ||
- Patrick Wilson \<<pwilson@opensourceintegrators.com>\> | ||
- Hardik Suthar \<<hsuthar@opensourceintegrators.com>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module links the 'Can be sold' field to the states. The states then | ||
control whether or not the product can be sold or not in the particular | ||
state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- When a product is moved to a state where it's approved, the 'Can be | ||
sold' box should be checked and the product is selectable on sales | ||
quotes. | ||
- If the product is not in a state where it's approved to be sold, then | ||
the 'Can be sold' check box is not checked and the product can not be | ||
added to sales quotes. | ||
- If it's not approved, any sales quote that already contained the | ||
product will show a warning and have an exception activity. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<odoo> | ||
|
||
<record id="group_product_administrator" model="res.groups"> | ||
<field name="name">Product Administrator</field> | ||
<field name="category_id" ref="base.module_category_usability" /> | ||
</record> | ||
|
||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name should maybe reflect 'product approval' flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We went over the naming of these fields internally quite a bit and ended up settling on 'candidate' because the approval part is in the states and having the 'approved to be' on the products confused the users because they struggled to make the connection between the setting on the product depends on the state. So we settled on 'Candidate' to say basically its configured to be 'Sold', 'Purchased', etc as long as the state it's in allows it.