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

===============================
Sale Order Partial Confirmation
===============================

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

.. |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/16.0/sale_order_confirm_partial
: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-16-0/sale-workflow-16-0-sale_order_confirm_partial
: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=16.0
:alt: Try me on Runboat

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

This module allows to select which sale order lines you would like to
confirm. It also can create a new quotation in the "Cancel" state with
all the unconfirmed lines from the original quotation in case you need
to keep that information.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Sometimes you need to confirm only selected lines of a Sales Order. Eg
your customer has asked you a quotation for a desk, five chairs and a
sofa. However in the end he decides to order only a desk and 2 chairs.

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

Go to "Sales -> Configuration -> Settings" and scroll down to the
"Quotation & Orders" section. Enable the "Partial Confirmation"
checkbox. Enable the "Save Unconfirmed Items" checkbox if you want to
create a quotation with all the unconfirmed items. Define a suffix for
the unconfirmed items quotation in the "Unconfirmed Quotation Suffix"
field. If no suffix is defined then a standard "-U" suffix will be used.
Eg "SO00023-U".

Usage
=====

Open a quotation and click the "Confirm" button. A wizard will pop-up
with the following options available:

- "All Items"
- "Selected Items"

Choose "Selected Items", set the lines quantities you want to confirm in
the list below and click "Confirm". If you don't want to confirm
specific lines at all, just set their quantity to 0. Note, that
confirmed quantity cannot be negative or greater than ordered quantity
of related SO line. If you put invalid quantity, you'll be notified via
error message. Quotation will be updated according to your selection and
confirmed.

If you have enabled "Save Unconfirmed Items" in the settings a new
quotation in the "Cancel" state will be created with all the lines that
were not confirmed. Internal note "Created from will be posted in the
chatter of the unconfirmed lines quotation. Internal note "Unconfirmed
lines are saved in will be posted in the chatter of the confirmed sales
order.

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_order_confirm_partial%0Aversion:%2016.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
-------

* Cetmix

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

Cetmix OÜ https://cetmix.com

- Ivan Sokolov

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/16.0/sale_order_confirm_partial>`_ 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_order_confirm_partial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import wizard
18 changes: 18 additions & 0 deletions sale_order_confirm_partial/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale Order Partial Confirmation",
"summary": "Select sales order lines to be confirmed",
"author": "Cetmix, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"category": "Sales",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["sale"],
"data": [
"security/ir.model.access.csv",
"views/res_config_settings_views.xml",
"wizard/sale_order_confirm_partial_views.xml",
],
"installable": True,
}
4 changes: 4 additions & 0 deletions sale_order_confirm_partial/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import res_config_settings
from . import sale_order
26 changes: 26 additions & 0 deletions sale_order_confirm_partial/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

sale_order_confirm_partial_enabled = fields.Boolean(
string="Partial Confirmation",
config_parameter="sale_order_confirm_partial.enabled",
)
so_confirm_partial_save_unconfirmed = fields.Boolean(
string="Save Unconfirmed Items",
config_parameter="sale_order_confirm_partial.save_unconfirmed",
help=(
"If enabled a new quotation in the 'Cancel' "
"state will be created with all the lines "
"that were not confirmed."
),
)
so_confirm_partial_unconfirmed_suffix = fields.Char(
string="Unconfirmed Quotation Suffix",
config_parameter="sale_order_confirm_partial.unconfirmed_suffix",
default="-U",
)
149 changes: 149 additions & 0 deletions sale_order_confirm_partial/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright (C) 2024 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, models


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

def action_confirm(self):
"""
If partial confirmation feature is enabled,
instead of standard SO confirmation at first we need
to open the partial confirmation wizard for current SO.

If feature is disabled or 'standard_confirm_proceed' context key
was specified as True, then we proceed with standard confirmation.
"""

force_confirm = self.env.context.get("standard_confirm_proceed", False)
partial_confirm_enabled = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"sale_order_confirm_partial.enabled",
False,
)
)
if force_confirm or not partial_confirm_enabled:
return super().action_confirm()
action = self.env["ir.actions.act_window"]._for_xml_id(
"sale_order_confirm_partial.sale_order_confirm_partial_action"
)
action.update(
{
"context": {
"default_sale_order_id": self.id,
}
}
)
return action

def _process_unconfirmed_quotation(self, confirmed_lines):
"""
If 'Save Unconfirmed Items' feature is enabled,
then create a new quotation in the 'Cancel' state
and move all unconfirmed lines to it.

Quantities of those lines should be reduced
depending on confirmed quantities.

If after reduction the quantity of any line
is less than or equal to 0, then remove that line.

Args:
confirmed_lines: sale.order.confirm.partial.line recordset.
Lines to be confirmed.

Returns:
sale.order: Created unconfirmed quotation
None: If feature is disabled or no unconfirmed lines
"""
self.ensure_one()
ICPsudo = self.env["ir.config_parameter"].sudo()
save_unconfirmed = ICPsudo.get_param(
"sale_order_confirm_partial.save_unconfirmed", False
)
if not save_unconfirmed:
return
# If all lines are confirmed and confirmed quantity
# is equal to ordered quantity, then no need to create
# unconfirmed quotation.
if all(
[
line.confirmed_qty == line.so_line_id.product_uom_qty
for line in confirmed_lines
]
) and len(confirmed_lines) == len(self.order_line):
return
unconfirmed_suffix = ICPsudo.get_param(
"sale_order_confirm_partial.unconfirmed_suffix", "-U"
)
unconfirmed_order = self.copy(
{
"name": self.name + unconfirmed_suffix,
"order_line": False,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not to set "cancel" state directly here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because in the loop below I'm changing order lines of this order, but Odoo restricts such changes for orders in Cancel state

}
)
unconfirmed_lines = self.env["sale.order.line"]
for line in self.order_line:
confirmed_line = confirmed_lines.filtered(lambda x: x.so_line_id == line)
if confirmed_line.confirmed_qty == line.product_uom_qty:
continue
unconfirmed_lines |= line.copy(
{
"order_id": unconfirmed_order.id,
"product_uom_qty": line.product_uom_qty
- confirmed_line.confirmed_qty,
}
)
unconfirmed_order.state = "cancel"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check the comment at L84

unconfirmed_order.message_post(
body=_(
"Created from "
"<a href=# data-oe-model=sale.order data-oe-id=%(id)d>%(name)s</a>"
)
% {"id": self.id, "name": self.name},
partner_id=self.env.ref("base.partner_root").id,
subtype_id=self.env.ref("mail.mt_note").id,
)
return unconfirmed_order

def _update_order_lines_qty(self, confirmed_lines):
"""
Update quantities of order lines depending
on confirmed quantities in selected lines.

Args:
confirmed_lines: sale.order.confirm.partial.line recordset.
"""
self.ensure_one()
for line in confirmed_lines:
line.so_line_id.product_uom_qty = line.confirmed_qty

def action_confirm_partial(self, confirmed_lines):
"""
Confirms only selected lines of the SO.

If 'Save Unconfirmed Items' feature is enabled,
then it creates also a new quotation in the 'Cancel' state
containing all unconfirmed lines and quantities.

Args:
confirmed_lines: sale.order.confirm.partial.line recordset.
Lines to be confirmed.
"""
self.ensure_one()
unconfirmed_quotation = self._process_unconfirmed_quotation(confirmed_lines)
self._update_order_lines_qty(confirmed_lines)
self.with_context(standard_confirm_proceed=True).action_confirm()
if unconfirmed_quotation:
self.message_post(
body=_(
"Unconfirmed lines are saved in "
"<a href=# data-oe-model=sale.order data-oe-id=%(id)d>%(name)s</a>"
)
% {"id": unconfirmed_quotation.id, "name": unconfirmed_quotation.name},
partner_id=self.env.ref("base.partner_root").id,
subtype_id=self.env.ref("mail.mt_note").id,
)
4 changes: 4 additions & 0 deletions sale_order_confirm_partial/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Go to "Sales -> Configuration -> Settings" and scroll down to the "Quotation & Orders" section.
Enable the "Partial Confirmation" checkbox.
Enable the "Save Unconfirmed Items" checkbox if you want to create a quotation with all the unconfirmed items.
Define a suffix for the unconfirmed items quotation in the "Unconfirmed Quotation Suffix" field. If no suffix is defined then a standard "-U" suffix will be used. Eg "SO00023-U".
2 changes: 2 additions & 0 deletions sale_order_confirm_partial/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sometimes you need to confirm only selected lines of a Sales Order.
Eg your customer has asked you a quotation for a desk, five chairs and a sofa. However in the end he decides to order only a desk and 2 chairs.
3 changes: 3 additions & 0 deletions sale_order_confirm_partial/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cetmix OÜ https://cetmix.com

- Ivan Sokolov
1 change: 1 addition & 0 deletions sale_order_confirm_partial/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to select which sale order lines you would like to confirm. It also can create a new quotation in the "Cancel" state with all the unconfirmed lines from the original quotation in case you need to keep that information.
14 changes: 14 additions & 0 deletions sale_order_confirm_partial/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Open a quotation and click the "Confirm" button.
A wizard will pop-up with the following options available:

- "All Items"
- "Selected Items"

Choose "Selected Items", set the lines quantities you want to confirm in the list below and click "Confirm".
If you don't want to confirm specific lines at all, just set their quantity to 0.
Note, that confirmed quantity cannot be negative or greater than ordered quantity of related SO line. If you put invalid quantity, you'll be notified via error message.
Quotation will be updated according to your selection and confirmed.

If you have enabled "Save Unconfirmed Items" in the settings a new quotation in the "Cancel" state will be created with all the lines that were not confirmed.
Internal note "Created from <SalesOrderNumber> will be posted in the chatter of the unconfirmed lines quotation.
Internal note "Unconfirmed lines are saved in <UnconfirmedQuotationNumber> will be posted in the chatter of the confirmed sales order.
3 changes: 3 additions & 0 deletions sale_order_confirm_partial/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sale_order_confirm_partial_wizard,access_sale_order_confirm_partial_wizard,model_sale_order_confirm_partial,sales_team.group_sale_salesman,1,1,1,1
access_sale_order_confirm_partial_line,access_sale_order_confirm_partial_line,model_sale_order_confirm_partial_line,sales_team.group_sale_salesman,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading