diff --git a/purchase_order_archive/README.rst b/purchase_order_archive/README.rst new file mode 100644 index 00000000000..eca06b2f37d --- /dev/null +++ b/purchase_order_archive/README.rst @@ -0,0 +1,118 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +====================== +Purchase Order Archive +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:be2c7e116bf5f8c40f23589fb9e482aaacd56855c77aba59f8d06d399f91a327 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/19.0/purchase_order_archive + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-19-0/purchase-workflow-19-0-purchase_order_archive + :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/purchase-workflow&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +On a system with a high volume of purchases, the number of purchase +orders displayed in the list view can become huge. This module allows to +archive Purchase Orders that are in status Locked or Cancelled. + +If a purchase order is archived, it will be hidden from the purchase +orders list view. + +This module only depends on module purchase, but it could be used in +combination with OCA module 'record_archiver' in order to automatically +archive old purchase orders. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To archive purchase orders, you need to: + +1. Open the tree view of purchase orders. +2. Select a purchase order (in status Locked or Cancelled) you want to + archive. +3. Click on Action > Archive. Confirm. +4. The purchase order is now archived. + +To unarchive purchase orders, you need to: + +1. Open the tree view of purchase orders. +2. In the filter box select the Archived filter. The list of archived + purchase orders will be displayed. +3. Select the purchase order (in status Locked or Cancelled) you want to + restore to Active. +4. Click on Action > Unarchive. +5. The purchase order is now active. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Onestein + +Contributors +------------ + +- Andrea Stirpe +- Christihan Laurel +- `Binhex `__: + + - Mario Luis + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_archive/__init__.py b/purchase_order_archive/__init__.py new file mode 100644 index 00000000000..31660d6a965 --- /dev/null +++ b/purchase_order_archive/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/purchase_order_archive/__manifest__.py b/purchase_order_archive/__manifest__.py new file mode 100644 index 00000000000..0d69304b4b0 --- /dev/null +++ b/purchase_order_archive/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2017-2020 Onestein () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Order Archive", + "summary": "Archive Purchase Orders", + "author": "Onestein, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/purchase-workflow", + "category": "Purchases", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "depends": ["purchase"], + "data": ["views/purchase_order.xml"], + "installable": True, +} diff --git a/purchase_order_archive/i18n/es.po b/purchase_order_archive/i18n/es.po new file mode 100644 index 00000000000..7b3b20d33b0 --- /dev/null +++ b/purchase_order_archive/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_archive +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-08-21 13:51+0000\n" +"PO-Revision-Date: 2026-04-19 09:31+0000\n" +"Last-Translator: Ed-Spain \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: purchase_order_archive +#: model:ir.model.fields,field_description:purchase_order_archive.field_purchase_order__active +msgid "Active" +msgstr "Activo" + +#. module: purchase_order_archive +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.purchase_order_archive_form +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.view_purchase_order_archive_filter +msgid "Archived" +msgstr "Archivado" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "Only 'Locked' or 'Canceled' orders can be archived" +msgstr "Solo se pueden archivar los pedidos 'Bloqueados' o 'Cancelados'" + +#. module: purchase_order_archive +#: model:ir.model,name:purchase_order_archive.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "" +"This record is currently archived and cannot have its state modified. Please " +"unarchive the record to make changes. " +msgstr "" +"Este registro está actualmente archivado y no se puede modificar su estado. " +"Por favor, desarchive el registro para realizar cambios. " + +#~ msgid "Display Name" +#~ msgstr "Nombre mostrado" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificación el" diff --git a/purchase_order_archive/i18n/it.po b/purchase_order_archive/i18n/it.po new file mode 100644 index 00000000000..24eb4bda627 --- /dev/null +++ b/purchase_order_archive/i18n/it.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_archive +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-09 11:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: purchase_order_archive +#: model:ir.model.fields,field_description:purchase_order_archive.field_purchase_order__active +msgid "Active" +msgstr "Attivo" + +#. module: purchase_order_archive +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.purchase_order_archive_form +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.view_purchase_order_archive_filter +msgid "Archived" +msgstr "In archivio" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "Only 'Locked' or 'Canceled' orders can be archived" +msgstr "Solo ordini 'Bloccati' o 'Annullati' possono essere archiviati" + +#. module: purchase_order_archive +#: model:ir.model,name:purchase_order_archive.model_purchase_order +msgid "Purchase Order" +msgstr "Ordine di acquisto" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "" +"This record is currently archived and cannot have its state modified. Please " +"unarchive the record to make changes. " +msgstr "" +"Questo record attualmente è archiviato e non se ne può modificare lo stato. " +"Disattivare l'archiviazione per poterlo modificare. " diff --git a/purchase_order_archive/i18n/pt_BR.po b/purchase_order_archive/i18n/pt_BR.po new file mode 100644 index 00000000000..47ea351a3dc --- /dev/null +++ b/purchase_order_archive/i18n/pt_BR.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_archive +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" + +#. module: purchase_order_archive +#: model:ir.model.fields,field_description:purchase_order_archive.field_purchase_order__active +msgid "Active" +msgstr "" + +#. module: purchase_order_archive +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.purchase_order_archive_form +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.view_purchase_order_archive_filter +msgid "Archived" +msgstr "" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "Only 'Locked' or 'Canceled' orders can be archived" +msgstr "" + +#. module: purchase_order_archive +#: model:ir.model,name:purchase_order_archive.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "" +"This record is currently archived and cannot have its state modified. Please" +" unarchive the record to make changes. " +msgstr "" diff --git a/purchase_order_archive/i18n/purchase_order_archive.pot b/purchase_order_archive/i18n/purchase_order_archive.pot new file mode 100644 index 00000000000..c487ac4efac --- /dev/null +++ b/purchase_order_archive/i18n/purchase_order_archive.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_archive +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_order_archive +#: model:ir.model.fields,field_description:purchase_order_archive.field_purchase_order__active +msgid "Active" +msgstr "" + +#. module: purchase_order_archive +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.purchase_order_archive_form +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.view_purchase_order_archive_filter +msgid "Archived" +msgstr "" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "Only 'Locked' or 'Canceled' orders can be archived" +msgstr "" + +#. module: purchase_order_archive +#: model:ir.model,name:purchase_order_archive.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "" +"This record is currently archived and cannot have its state modified. Please" +" unarchive the record to make changes. " +msgstr "" diff --git a/purchase_order_archive/i18n/zh_CN.po b/purchase_order_archive/i18n/zh_CN.po new file mode 100644 index 00000000000..e8fcf2077f9 --- /dev/null +++ b/purchase_order_archive/i18n/zh_CN.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_archive +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-23 13:13+0000\n" +"Last-Translator: Dong \n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.10\n" + +#. module: purchase_order_archive +#: model:ir.model.fields,field_description:purchase_order_archive.field_purchase_order__active +msgid "Active" +msgstr "有效" + +#. module: purchase_order_archive +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.purchase_order_archive_form +#: model_terms:ir.ui.view,arch_db:purchase_order_archive.view_purchase_order_archive_filter +msgid "Archived" +msgstr "已归档" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "Only 'Locked' or 'Canceled' orders can be archived" +msgstr "只允许“已锁定”或“已取消”的订单归档" + +#. module: purchase_order_archive +#: model:ir.model,name:purchase_order_archive.model_purchase_order +msgid "Purchase Order" +msgstr "采购订单" + +#. module: purchase_order_archive +#. odoo-python +#: code:addons/purchase_order_archive/models/purchase_order.py:0 +msgid "" +"This record is currently archived and cannot have its state modified. Please " +"unarchive the record to make changes. " +msgstr "" diff --git a/purchase_order_archive/models/__init__.py b/purchase_order_archive/models/__init__.py new file mode 100644 index 00000000000..9b3b3d418ee --- /dev/null +++ b/purchase_order_archive/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import purchase_order diff --git a/purchase_order_archive/models/purchase_order.py b/purchase_order_archive/models/purchase_order.py new file mode 100644 index 00000000000..09348d3a322 --- /dev/null +++ b/purchase_order_archive/models/purchase_order.py @@ -0,0 +1,29 @@ +# Copyright 2017-2020 Onestein () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + active = fields.Boolean(default=True) + + def action_archive(self): + if self.filtered(lambda po: po.state != "cancel" and not po.locked): + raise UserError( + self.env._("Only 'Locked' or 'Canceled' orders can be archived") + ) + return super().action_archive() + + @api.constrains("state", "locked") + def _check_state(self): + for rec in self: + if not rec.active: + raise UserError( + self.env._( + "This record is currently archived and cannot have its state " + "modified. Please unarchive the record to make changes. " + ) + ) diff --git a/purchase_order_archive/pyproject.toml b/purchase_order_archive/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_order_archive/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_order_archive/readme/CONTRIBUTORS.md b/purchase_order_archive/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..f1458f5f39c --- /dev/null +++ b/purchase_order_archive/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Andrea Stirpe \<\> +- Christihan Laurel \<\> +- [Binhex](https://binhex.cloud/): + - Mario Luis \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/purchase_order_archive/readme/DESCRIPTION.md b/purchase_order_archive/readme/DESCRIPTION.md new file mode 100644 index 00000000000..0a0148b26a0 --- /dev/null +++ b/purchase_order_archive/readme/DESCRIPTION.md @@ -0,0 +1,10 @@ +On a system with a high volume of purchases, the number of purchase +orders displayed in the list view can become huge. This module allows to +archive Purchase Orders that are in status Locked or Cancelled. + +If a purchase order is archived, it will be hidden from the purchase +orders list view. + +This module only depends on module purchase, but it could be used in +combination with OCA module 'record_archiver' in order to automatically +archive old purchase orders. diff --git a/purchase_order_archive/readme/USAGE.md b/purchase_order_archive/readme/USAGE.md new file mode 100644 index 00000000000..c03e18fd1f0 --- /dev/null +++ b/purchase_order_archive/readme/USAGE.md @@ -0,0 +1,17 @@ +To archive purchase orders, you need to: + +1. Open the tree view of purchase orders. +2. Select a purchase order (in status Locked or Cancelled) you want to + archive. +3. Click on Action \> Archive. Confirm. +4. The purchase order is now archived. + +To unarchive purchase orders, you need to: + +1. Open the tree view of purchase orders. +2. In the filter box select the Archived filter. The list of archived + purchase orders will be displayed. +3. Select the purchase order (in status Locked or Cancelled) you want + to restore to Active. +4. Click on Action \> Unarchive. +5. The purchase order is now active. diff --git a/purchase_order_archive/setup/purchase_order_archive/odoo/addons/purchase_order_archive b/purchase_order_archive/setup/purchase_order_archive/odoo/addons/purchase_order_archive new file mode 100644 index 00000000000..e4567f2d15d --- /dev/null +++ b/purchase_order_archive/setup/purchase_order_archive/odoo/addons/purchase_order_archive @@ -0,0 +1 @@ +../../../../purchase_order_archive diff --git a/purchase_order_archive/setup/purchase_order_archive/setup.py b/purchase_order_archive/setup/purchase_order_archive/setup.py new file mode 100644 index 00000000000..00a90304a19 --- /dev/null +++ b/purchase_order_archive/setup/purchase_order_archive/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=["setuptools-odoo"], + odoo_addon=True, +) diff --git a/purchase_order_archive/static/description/icon.png b/purchase_order_archive/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_archive/static/description/icon.png differ diff --git a/purchase_order_archive/static/description/index.html b/purchase_order_archive/static/description/index.html new file mode 100644 index 00000000000..07e0bffd532 --- /dev/null +++ b/purchase_order_archive/static/description/index.html @@ -0,0 +1,467 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Purchase Order Archive

+ +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

On a system with a high volume of purchases, the number of purchase +orders displayed in the list view can become huge. This module allows to +archive Purchase Orders that are in status Locked or Cancelled.

+

If a purchase order is archived, it will be hidden from the purchase +orders list view.

+

This module only depends on module purchase, but it could be used in +combination with OCA module ‘record_archiver’ in order to automatically +archive old purchase orders.

+

Table of contents

+ +
+

Usage

+

To archive purchase orders, you need to:

+
    +
  1. Open the tree view of purchase orders.
  2. +
  3. Select a purchase order (in status Locked or Cancelled) you want to +archive.
  4. +
  5. Click on Action > Archive. Confirm.
  6. +
  7. The purchase order is now archived.
  8. +
+

To unarchive purchase orders, you need to:

+
    +
  1. Open the tree view of purchase orders.
  2. +
  3. In the filter box select the Archived filter. The list of archived +purchase orders will be displayed.
  4. +
  5. Select the purchase order (in status Locked or Cancelled) you want to +restore to Active.
  6. +
  7. Click on Action > Unarchive.
  8. +
  9. The purchase order is now active.
  10. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Onestein
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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/purchase-workflow project on GitHub.

+

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

+
+
+
+
+ + diff --git a/purchase_order_archive/tests/__init__.py b/purchase_order_archive/tests/__init__.py new file mode 100644 index 00000000000..86e703fc5a8 --- /dev/null +++ b/purchase_order_archive/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_purchase_order_archive diff --git a/purchase_order_archive/tests/test_purchase_order_archive.py b/purchase_order_archive/tests/test_purchase_order_archive.py new file mode 100644 index 00000000000..82b8ce80c6a --- /dev/null +++ b/purchase_order_archive/tests/test_purchase_order_archive.py @@ -0,0 +1,75 @@ +# Copyright 2017 ForgeFlow, S.L. +# Copyright 2017 Luxim d.o.o. +# Copyright 2017 Matmoz d.o.o. +# Copyright 2017 Deneroteam. +# Copyright 2017 Serpent Consulting Services Pvt. Ltd. +# Copyright 2017 Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import Command +from odoo.exceptions import UserError + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +class TestPurchaseOrderArchive(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.product_a + cls.partner = cls.partner_a + cls.po_vals = { + "partner_id": cls.partner.id, + "order_line": [ + Command.create( + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_qty": 1.0, + "product_uom_id": cls.product.uom_id.id, + "price_unit": 121.0, + } + ) + ], + } + cls.po_draft = cls.env["purchase.order"].create(cls.po_vals) + cls.po_sent = cls.env["purchase.order"].create(cls.po_vals) + cls.po_sent.write({"state": "sent"}) + cls.po_to_approve = cls.env["purchase.order"].create(cls.po_vals) + cls.po_to_approve.write({"state": "to approve"}) + cls.po_purchase = cls.env["purchase.order"].create(cls.po_vals) + cls.po_purchase.button_confirm() + cls.po_done = cls.env["purchase.order"].create(cls.po_vals) + cls.po_done.button_confirm() + cls.po_done.button_lock() + cls.po_cancel = cls.env["purchase.order"].create(cls.po_vals) + cls.po_cancel.button_cancel() + + def test_archive(self): + with self.assertRaisesRegex( + UserError, "Only 'Locked' or 'Canceled' orders can be archived" + ): + self.po_draft.action_archive() + with self.assertRaisesRegex( + UserError, "Only 'Locked' or 'Canceled' orders can be archived" + ): + self.po_sent.action_archive() + with self.assertRaisesRegex( + UserError, "Only 'Locked' or 'Canceled' orders can be archived" + ): + self.po_to_approve.action_archive() + with self.assertRaisesRegex( + UserError, "Only 'Locked' or 'Canceled' orders can be archived" + ): + self.po_purchase.action_archive() + self.po_done.action_archive() + self.assertFalse(self.po_done.active) + self.po_cancel.action_archive() + self.assertFalse(self.po_cancel.active) + + def test_check_state_constraint(self): + """Test that archived orders cannot have their state changed""" + self.po_done.action_archive() + self.assertFalse(self.po_done.active) + with self.assertRaisesRegex(UserError, "This record is currently archived"): + self.po_done.state = "purchase" diff --git a/purchase_order_archive/views/purchase_order.xml b/purchase_order_archive/views/purchase_order.xml new file mode 100644 index 00000000000..ba413ce78c7 --- /dev/null +++ b/purchase_order_archive/views/purchase_order.xml @@ -0,0 +1,36 @@ + + + + + purchase.order + + + + + + + + + + + + purchase.order + + + + + + + + +