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
3 changes: 2 additions & 1 deletion sale_order_revision/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale order revisions
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b0e8b598479388b8dd3c07820ec6ee7d5363bd0420cc2521f8b3041e9a39e3b3
!! source digest: sha256:acade735e80e4d45eb2bd16323b5faa402d223962f79449028812760bb1b0742
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -84,6 +84,7 @@ Contributors
* Raf Ven <raf.ven@dynapps.be>
* Jeroen Evens <jeroen.evens@dynapps.be>
* Kitti U. <kittiu@ecosoft.co.th>
* Daniel Reis <dreis@opensourceintegrators.com>

Maintainers
~~~~~~~~~~~
Expand Down
36 changes: 31 additions & 5 deletions sale_order_revision/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright 2020 Ecosoft Co., Ltd. (<http://ecosoft.co.th>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import _, fields, models


class SaleOrder(models.Model):
Expand Down Expand Up @@ -34,11 +34,37 @@ def _prepare_revision_data(self, new_revision):

def action_view_revisions(self):
self.ensure_one()
result = self.env["ir.actions.actions"]._for_xml_id("sale.action_orders")
result["domain"] = ["|", ("active", "=", False), ("active", "=", True)]
result["context"] = {
domain = ["|", ("active", "=", False), ("active", "=", True)]
context = {
"active_test": 0,
"search_default_current_revision_id": self.id,
"default_current_revision_id": self.id,
}
return result
search_view = self.env.ref("sale.sale_order_view_search_inherit_sale")
return {
"name": _("Previous Revisions"),
"view_mode": "tree,form",
"res_model": "sale.order",
"type": "ir.actions.act_window",
"search_view_id": search_view.id,
"domain": domain,
"context": context,
}

def create_revision(self):
# Extends base_revision module
action = super().create_revision()
# Keep links to Invoices on the new Sale Order
old_lines = self.order_line
new_lines = self.current_revision_id.order_line
for old_line, new_line in zip(old_lines, new_lines):
new_line.invoice_lines = old_line.invoice_lines
return action

def action_cancel_create_revision(self):
for sale in self:
sale.action_cancel()
action = sale.create_revision()
if len(self) == 1:
return action
return {}
1 change: 1 addition & 0 deletions sale_order_revision/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* Raf Ven <raf.ven@dynapps.be>
* Jeroen Evens <jeroen.evens@dynapps.be>
* Kitti U. <kittiu@ecosoft.co.th>
* Daniel Reis <dreis@opensourceintegrators.com>
12 changes: 2 additions & 10 deletions sale_order_revision/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
On cancelled orders, you can click on the "New copy of Quotation" button. This
will create a new revision of the quotation, with the same base number and a
'-revno' suffix appended. A message is added in the chatter saying that a new
revision was created.

In the form view, a new tab is added that lists the previous revisions, with
the date they were made obsolete and the user who performed the action.

The old revisions of a sale order are flagged as inactive, so they don't
clutter up searches.
Create new revisions or versions for Sales Orders,
keeping the history of previous revisions.
12 changes: 12 additions & 0 deletions sale_order_revision/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
On Sales Orders, click on the "New Revision" button.
This creates a new revision of the quotation,
with the same base number and a '-revno' suffix appended.

A message is added in the chatter saying that a new
revision was created.

In the form view, a new tab is added that lists the previous revisions, with
the date they were made obsolete and the user who performed the action.

The old revisions of a sale order are flagged as inactive, so they don't
clutter up searches.
3 changes: 2 additions & 1 deletion sale_order_revision/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Sale order revisions</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b0e8b598479388b8dd3c07820ec6ee7d5363bd0420cc2521f8b3041e9a39e3b3
!! source digest: sha256:acade735e80e4d45eb2bd16323b5faa402d223962f79449028812760bb1b0742
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_order_revision"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_order_revision"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>On cancelled orders, you can click on the “New copy of Quotation” button. This
Expand Down Expand Up @@ -428,6 +428,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Raf Ven &lt;<a class="reference external" href="mailto:raf.ven&#64;dynapps.be">raf.ven&#64;dynapps.be</a>&gt;</li>
<li>Jeroen Evens &lt;<a class="reference external" href="mailto:jeroen.evens&#64;dynapps.be">jeroen.evens&#64;dynapps.be</a>&gt;</li>
<li>Kitti U. &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
<li>Daniel Reis &lt;<a class="reference external" href="mailto:dreis&#64;opensourceintegrators.com">dreis&#64;opensourceintegrators.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
24 changes: 23 additions & 1 deletion sale_order_revision/tests/test_sale_order_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,33 @@ def setUpClass(cls):
super().setUpClass()
cls.revision_model = cls.env["sale.order"]
cls.partner = cls.env["res.partner"].create({"name": "Mr Odoo"})
cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.product = cls.env["product.product"].create(
{"name": "Test product", "invoice_policy": "order"}
)

def _create_tester(self):
sale_form = Form(self.revision_model)
sale_form.partner_id = self.partner
with sale_form.order_line.new() as line_form:
line_form.product_id = self.product
line_form.product_uom_qty = 10
line_form.price_unit = 10
return sale_form.save()

def _create_sale_invoice(self, sale):
SaleInv = self.env["sale.advance.payment.inv"].with_context(active_ids=sale.ids)
popup = SaleInv.create({"advance_payment_method": "delivered"})
popup.create_invoices()

def test_action_cancel_create_revision(self):
sale = self._create_tester()
sale.action_confirm()
self._create_sale_invoice(sale)
sale.action_cancel_create_revision()
self.assertEqual(sale.state, "cancel", "Original SO was cancelled")
self.assertTrue(sale.current_revision_id, "A new SO version was created")
self.assertEqual(
sale.current_revision_id.invoice_ids,
sale.invoice_ids,
"The Sale Order revision keeps a link to the original invoices",
)
6 changes: 6 additions & 0 deletions sale_order_revision/view/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
string="New Revision of Quotation"
type="object"
/>
<button
name="action_cancel_create_revision"
states="sale"
string="New Revision"
type="object"
/>
</xpath>
<xpath expr="//button[@name='action_view_invoice']" position="after">
<button
Expand Down
1 change: 1 addition & 0 deletions sale_order_revision_stock/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENERATED
2 changes: 2 additions & 0 deletions sale_order_revision_stock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
15 changes: 15 additions & 0 deletions sale_order_revision_stock/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Sale order revisions keep Deliveries",
"summary": "New revisions keep the link to Delivery Orders",
"version": "14.0.1.0.0",
"category": "Sale Management",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"depends": ["sale_order_revision", "stock"],
"installable": True,
"auto_install": True,
}
3 changes: 3 additions & 0 deletions sale_order_revision_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import sale_order
20 changes: 20 additions & 0 deletions sale_order_revision_stock/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


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

def create_revision(self):
# Extends base_revision module
action = super().create_revision()
# Keep links to Stock Moves on the new Sale Order
old_so = self
new_so = self.current_revision_id
new_so.procurement_group_id.sale_id = old_so
new_so.picking_ids = old_so.picking_ids
for old_line, new_line in zip(old_so.order_line, new_so.order_line):
new_line.move_ids = old_line.move_ids
return action
1 change: 1 addition & 0 deletions sale_order_revision_stock/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Daniel Reis <dreis@opensourceintegrators.com>
1 change: 1 addition & 0 deletions sale_order_revision_stock/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The revision Sales Order preserves the link to the related Stock Moves.
1 change: 1 addition & 0 deletions sale_order_revision_stock/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See instructions for the "Sale Order Revision" module.
3 changes: 3 additions & 0 deletions sale_order_revision_stock/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

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

from odoo.addons.sale_order_revision.tests import test_sale_order_revision


class TestSaleOrderRevisionStock(test_sale_order_revision.TestSaleOrderRevision):
def test_revision_keeps_stock(self):
sale = self._create_tester()
sale.action_confirm()
self._create_sale_invoice(sale)
sale.action_cancel_create_revision()
self.assertEqual(
sale.current_revision_id.picking_ids,
sale.picking_ids,
"The Sale Order revision keeps a link to the original Stock Moves",
)
6 changes: 6 additions & 0 deletions setup/sale_order_revision_stock/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)