Metadata-Version: 2.1
Name: odoo-addon-sale_order_merge
Version: 17.0.1.0.0.1
Requires-Python: >=3.10
Requires-Dist: odoo>=17.0a,<17.1dev
Summary: Merge sale orders that are confirmed, invoiced or delivered
Home-page: https://github.com/OCA/sale-workflow
License: AGPL-3
Author: Opener B.V., Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 17.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

=================
Merge sale orders
=================

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

.. |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/17.0/sale_order_merge
    :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_order_merge
    :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 lets salespeople merge sale orders of the same customer into
a single order. The lines of the merged orders move to the target order,
and the other orders are cancelled.

Quotations, sent or not, can always be merged, and confirmed orders too
when the corresponding setting is enabled. When the target order is
confirmed, the pending deliveries of the merged orders are merged with
its own, and their draft invoices are merged into one.

**Table of contents**

.. contents::
   :local:

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

Quotations, sent or not, can always be merged. To merge confirmed orders
as well:

1. Go to **Settings > Sales**, section **Quotations & Orders**.
2. Enable **Merge confirmed orders** and save.

|MERGE_ORDER_CONFIRM|

The Sales settings page is only shown when the Sales application
(``sale_management``) is installed.

.. |MERGE_ORDER_CONFIRM| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_order_merge/static/img/readme/MERGE_ORDER_CONFIRM.png

Usage
=====

Merge criteria
--------------

An order can be merged with the orders that share its customer, delivery
address, warehouse, company and currency, and that are in the
**Quotation** or **Quotation Sent** status, or also in the **Sales
Order** status when **Merge confirmed orders** is enabled. The order you
merge into must have at least one line.

Merging from the form view
--------------------------

1. Open a quotation or a sales order. When other orders meet the merge
   criteria, a **Merge** button shows in the header.

   |SHOW_BTN_MERGE_FORM|

2. Click **Merge**. The wizard lists the order and every order it can be
   merged with. Remove the orders you do not want to merge; **Add a
   line** only offers orders that meet the merge criteria. **Merge
   into** is the target order.

   |WIZARD_MERGE|

3. Click **Merge**. The wizard closes and the view it was opened from
   reloads.

Merging from the list view
--------------------------

1. In the list of quotations or sales orders, select the orders to merge
   and choose **Actions > Merge selected orders**.

   |MENU_MERGE_TREE|

2. The target order is the first one created among the selected orders
   that are in a status that can be merged. If any selected order does
   not meet the merge criteria with it, an error lists those orders
   grouped by the criterion they fail, so you can correct the selection.

   |ERROR_CRITERIA|

3. Otherwise the wizard opens with the selected orders. Continue as in
   steps 2 and 3 of the previous section.

What the merge does
-------------------

- The lines of the merged orders move to the target order and the other
  orders are cancelled. Each cancelled order logs "Merged into" the
  target in its chatter, and the target logs the orders merged into it.
- When the target order is confirmed, the quotations among the merged
  orders are confirmed first. The pending deliveries to the customer are
  grouped by operation type, source location, destination location and
  partner, and each group is merged into a single delivery: the one of
  the target order, or the oldest one when the target order has none in
  that group. Done and cancelled deliveries are kept as they are and
  linked to the target order.
- When the target order is confirmed, the draft invoices of the orders
  are merged into one, preferably the draft invoice of the target order,
  and its taxes and due dates are recomputed. Invoices that are not in
  draft are kept as they are.
- When the target order is a quotation and some of the orders to merge
  are confirmed, the wizard warns that those orders are cancelled and
  their deliveries are not merged.
- When any of the orders merged into the target is locked (**Lock
  Confirmed Sales**), the merge stops without changing anything and asks
  you to unlock those orders first. The quotations that the merge
  confirms are unlocked so they can be cancelled.

Extending the merge
-------------------

Other modules can adapt the merge by overriding these methods:

- ``sale.order._can_merge``: conditions an order must meet to be merged.
- ``sale.order._get_merge_domain``: domain of the orders that meet the
  merge criteria of an order.
- ``sale.order._get_merge_depends``: fields of the order read by the
  merge criteria. Extend it along with the two previous methods, so that
  the merge candidates are computed again when those fields change.
- ``sale.order.merge._picking_can_merge``: deliveries that can be
  merged.
- ``sale.order.merge._get_picking_map_key``: how deliveries are grouped
  before merging each group into one.
- ``sale.order.merge._get_merge_result_action``: action returned once
  the orders are merged.

.. |SHOW_BTN_MERGE_FORM| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_order_merge/static/img/readme/SHOW_BTN_MERGE_FORM.png
.. |WIZARD_MERGE| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_order_merge/static/img/readme/WIZARD_MERGE.png
.. |MENU_MERGE_TREE| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_order_merge/static/img/readme/MENU_MERGE_TREE.png
.. |ERROR_CRITERIA| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_order_merge/static/img/readme/ERROR_CRITERIA.png

Known issues / Roadmap
======================

- With delivery routes in two or three steps, only the deliveries to the
  customer are merged. The internal transfers before them (pick, pack)
  are linked to the target order but stay separate.

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

* Opener B.V.

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

- Stefan Rijnhart stefan@opener.amsterdam
- `Binhex <https://www.binhex.cloud/>`__:

  - Edilio Escalona Almira e.escalona@binhex.cloud

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_order_merge>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
