From 75173d9a079e55e098020726fc3032de088a6695 Mon Sep 17 00:00:00 2001 From: chaule97 Date: Fri, 28 Jun 2024 16:59:33 +0700 Subject: [PATCH] [ADD] purchase_date_planned_manual_container_deposit_product: When date_planned is set manually, prevent calculation of the field upon PO confirmation --- .../README.rst | 92 ++++ .../__init__.py | 1 + .../__manifest__.py | 19 + .../models/__init__.py | 1 + .../models/purchase_order.py | 14 + .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 3 + .../readme/USAGE.rst | 9 + .../static/description/index.html | 437 ++++++++++++++++++ .../tests/__init__.py | 1 + ...lanned_manual_container_deposit_product.py | 55 +++ ...e_planned_manual_container_deposit_product | 1 + .../setup.py | 6 + 13 files changed, 641 insertions(+) create mode 100644 purchase_date_planned_manual_container_deposit_product/README.rst create mode 100644 purchase_date_planned_manual_container_deposit_product/__init__.py create mode 100644 purchase_date_planned_manual_container_deposit_product/__manifest__.py create mode 100644 purchase_date_planned_manual_container_deposit_product/models/__init__.py create mode 100644 purchase_date_planned_manual_container_deposit_product/models/purchase_order.py create mode 100644 purchase_date_planned_manual_container_deposit_product/readme/CONTRIBUTORS.rst create mode 100644 purchase_date_planned_manual_container_deposit_product/readme/DESCRIPTION.rst create mode 100644 purchase_date_planned_manual_container_deposit_product/readme/USAGE.rst create mode 100644 purchase_date_planned_manual_container_deposit_product/static/description/index.html create mode 100644 purchase_date_planned_manual_container_deposit_product/tests/__init__.py create mode 100644 purchase_date_planned_manual_container_deposit_product/tests/test_purchase_date_planned_manual_container_deposit_product.py create mode 120000 setup/purchase_date_planned_manual_container_deposit_product/odoo/addons/purchase_date_planned_manual_container_deposit_product create mode 100644 setup/purchase_date_planned_manual_container_deposit_product/setup.py diff --git a/purchase_date_planned_manual_container_deposit_product/README.rst b/purchase_date_planned_manual_container_deposit_product/README.rst new file mode 100644 index 00000000000..f31d86e39df --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/README.rst @@ -0,0 +1,92 @@ +====================================================== +Purchase Date Planned Manual Container Deposit Product +====================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:096a81afacd9b853ef576065aea83f9d832947fdf5d82dc030006591e710d643 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_date_planned_manual_container_deposit_product + :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-16-0/purchase-workflow-16-0-purchase_date_planned_manual_container_deposit_product + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module makes the system to always respect the planned (or scheduled) +date set by the user in PO when choose product with packaging container deposit. + + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To test this module you could follow below: + +#. Go to 'Purchase' and create a purchase order. +#. Select any vendor +#. Add new PO Line with product with container deposit associated +#. Enter Expected Arrival (date_planned) in future +#. Confirm PO +#. Expected Arrival is preserved + + +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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Chau Le + + +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_date_planned_manual_container_deposit_product/__init__.py b/purchase_date_planned_manual_container_deposit_product/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_date_planned_manual_container_deposit_product/__manifest__.py b/purchase_date_planned_manual_container_deposit_product/__manifest__.py new file mode 100644 index 00000000000..92a478fa3a3 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Date Planned Manual Container Deposit Product", + "summary": """Glue module between purchase_date_planned_manual + and purchase_product_packaging_container_deposit""", + "version": "16.0.1.0.0", + "author": "Camptocamp, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/purchase-workflow", + "category": "Purchase Management", + "depends": [ + "purchase_date_planned_manual", + "purchase_product_packaging_container_deposit", + ], + "license": "AGPL-3", + "installable": True, + "application": False, + "auto_install": True, +} diff --git a/purchase_date_planned_manual_container_deposit_product/models/__init__.py b/purchase_date_planned_manual_container_deposit_product/models/__init__.py new file mode 100644 index 00000000000..9f03530643d --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order diff --git a/purchase_date_planned_manual_container_deposit_product/models/purchase_order.py b/purchase_date_planned_manual_container_deposit_product/models/purchase_order.py new file mode 100644 index 00000000000..7900f6909f9 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/models/purchase_order.py @@ -0,0 +1,14 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def prepare_deposit_container_line(self, product, qty): + values = super().prepare_deposit_container_line(product, qty) + if self.date_planned: + values["date_planned"] = self.date_planned + + return values diff --git a/purchase_date_planned_manual_container_deposit_product/readme/CONTRIBUTORS.rst b/purchase_date_planned_manual_container_deposit_product/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..9e237da57c2 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Chau Le + diff --git a/purchase_date_planned_manual_container_deposit_product/readme/DESCRIPTION.rst b/purchase_date_planned_manual_container_deposit_product/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f6ffc53dd79 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module makes the system to always respect the planned (or scheduled) +date set by the user in PO when choose product with packaging container deposit. + diff --git a/purchase_date_planned_manual_container_deposit_product/readme/USAGE.rst b/purchase_date_planned_manual_container_deposit_product/readme/USAGE.rst new file mode 100644 index 00000000000..598930afe92 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/readme/USAGE.rst @@ -0,0 +1,9 @@ +To test this module you could follow below: + +#. Go to 'Purchase' and create a purchase order. +#. Select any vendor +#. Add new PO Line with product with container deposit associated +#. Enter Expected Arrival (date_planned) in future +#. Confirm PO +#. Expected Arrival is preserved + diff --git a/purchase_date_planned_manual_container_deposit_product/static/description/index.html b/purchase_date_planned_manual_container_deposit_product/static/description/index.html new file mode 100644 index 00000000000..d64b0743055 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +Purchase Date Planned Manual Container Deposit Product + + + +
+

Purchase Date Planned Manual Container Deposit Product

+ + +

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

+

This module makes the system to always respect the planned (or scheduled) +date set by the user in PO when choose product with packaging container deposit.

+

Table of contents

+ +
+

Usage

+

To test this module you could follow below:

+
    +
  1. Go to ‘Purchase’ and create a purchase order.
  2. +
  3. Select any vendor
  4. +
  5. Add new PO Line with product with container deposit associated
  6. +
  7. Enter Expected Arrival (date_planned) in future
  8. +
  9. Confirm PO
  10. +
  11. Expected Arrival is preserved
  12. +
+
+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

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_date_planned_manual_container_deposit_product/tests/__init__.py b/purchase_date_planned_manual_container_deposit_product/tests/__init__.py new file mode 100644 index 00000000000..6a21a7a8678 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_date_planned_manual_container_deposit_product diff --git a/purchase_date_planned_manual_container_deposit_product/tests/test_purchase_date_planned_manual_container_deposit_product.py b/purchase_date_planned_manual_container_deposit_product/tests/test_purchase_date_planned_manual_container_deposit_product.py new file mode 100644 index 00000000000..3d5ff91fa81 --- /dev/null +++ b/purchase_date_planned_manual_container_deposit_product/tests/test_purchase_date_planned_manual_container_deposit_product.py @@ -0,0 +1,55 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from datetime import datetime, timedelta + +from odoo import Command + +from odoo.addons.product_packaging_container_deposit.tests.common import Common + +time_formate = "%Y-%m-%d %H:%M:%S" + + +class TestDatePlannedManualContainerDepositProduct(Common): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.order_model = cls.env["purchase.order"] + + cls.next_week_time = datetime.now() + timedelta(days=7) + + cls.order = cls.order_model.create( + { + "company_id": cls.env.company.id, + "partner_id": cls.env.ref("base.res_partner_12").id, + "state": "draft", + "date_planned": cls.next_week_time, + "order_line": [ + Command.create( + { + "name": cls.product_a.name, + "product_id": cls.product_a.id, + "product_qty": 50, + "date_planned": cls.next_week_time, + } + ), + ], + } + ) + + def test_do_not_change_date_planned_if_order_confirm(self): + for order_line in self.order.order_line: + order_line.write({"price_unit": 120.0}) + + self.order.button_confirm() + self.assertEqual( + self.order.date_planned.strftime(time_formate), + self.next_week_time.strftime(time_formate), + "The date_planned of the PO should not be updated again after order confirm.", + ) + + for order_line in self.order.order_line: + self.assertEqual( + order_line.date_planned.strftime(time_formate), + self.next_week_time.strftime(time_formate), + "The date_planned of the order line should match the date_planned of PO.", + ) diff --git a/setup/purchase_date_planned_manual_container_deposit_product/odoo/addons/purchase_date_planned_manual_container_deposit_product b/setup/purchase_date_planned_manual_container_deposit_product/odoo/addons/purchase_date_planned_manual_container_deposit_product new file mode 120000 index 00000000000..ad961cc1861 --- /dev/null +++ b/setup/purchase_date_planned_manual_container_deposit_product/odoo/addons/purchase_date_planned_manual_container_deposit_product @@ -0,0 +1 @@ +../../../../purchase_date_planned_manual_container_deposit_product \ No newline at end of file diff --git a/setup/purchase_date_planned_manual_container_deposit_product/setup.py b/setup/purchase_date_planned_manual_container_deposit_product/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_date_planned_manual_container_deposit_product/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)