diff --git a/purchase_order_price_recalculation/README.rst b/purchase_order_price_recalculation/README.rst new file mode 100644 index 00000000000..01808db11b2 --- /dev/null +++ b/purchase_order_price_recalculation/README.rst @@ -0,0 +1,112 @@ +======================================= +Price recalculation in purchases orders +======================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b96bad5fa442c1bdccb6ce70b2cdb6f2ff4a5cda8817f371db225ef010293cb2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/purchase_order_price_recalculation + :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-18-0/purchase-workflow-18-0-purchase_order_price_recalculation + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds one button on purchase orders (below the lines) that: + +- Recalculates the prices of the order lines that contain a product in + them. + +It is launched manually as a button to get the user to decide if he/she +wants to recalculate prices when vendor is changed or after duplicating +a purchase order to update or not purchase information. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Purchase -> Products > Products* and create some record and + set differente prices to vendors in Purchase tab, for example: Vendor + 1: 10 and Vendor 2: 20. +2. Go to *Purchase -> Orders > Requests for Quotation* and create some + record and set Vendor 1. +3. Add a line with the previously created product. +4. The unit price of the product is 10. +5. Change vendor to Vendor 2. +6. Click on the "Update lines info" button. +7. The unit price of the product is 20. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Víctor Martínez + - Pedro M. Baeza + +- `Komit `__: + + - Cai Hoang Huynh + +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. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +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_price_recalculation/__init__.py b/purchase_order_price_recalculation/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_order_price_recalculation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_order_price_recalculation/__manifest__.py b/purchase_order_price_recalculation/__manifest__.py new file mode 100644 index 00000000000..8a1998d0e17 --- /dev/null +++ b/purchase_order_price_recalculation/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Price recalculation in purchases orders", + "version": "18.0.1.0.0", + "category": "Purchase Management", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["purchase"], + "data": ["views/purchase_order_view.xml"], + "maintainers": ["victoralmau"], +} diff --git a/purchase_order_price_recalculation/i18n/es.po b/purchase_order_price_recalculation/i18n/es.po new file mode 100644 index 00000000000..046d0d7ff21 --- /dev/null +++ b/purchase_order_price_recalculation/i18n/es.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_price_recalculation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-05-03 08:04+0000\n" +"PO-Revision-Date: 2022-05-03 10:06+0200\n" +"Last-Translator: \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: \n" +"X-Generator: Poedit 2.3\n" + +#. module: purchase_order_price_recalculation +#: model:ir.model,name:purchase_order_price_recalculation.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "" +"This will update all the line prices based on the vendor currently set. Do " +"you want to continue?" +msgstr "" +"Esto actualizará todos los precios de la línea según el proveedor " +"establecido actualmente. ¿Quiere continuar?" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "Update lines info" +msgstr "Actualizar información de líneas" + +#~ msgid "Display Name" +#~ msgstr "Nombre mostrado" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificación el" diff --git a/purchase_order_price_recalculation/i18n/it.po b/purchase_order_price_recalculation/i18n/it.po new file mode 100644 index 00000000000..5d11fc8fd3e --- /dev/null +++ b/purchase_order_price_recalculation/i18n/it.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_price_recalculation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-03-23 13:24+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 4.14.1\n" + +#. module: purchase_order_price_recalculation +#: model:ir.model,name:purchase_order_price_recalculation.model_purchase_order +msgid "Purchase Order" +msgstr "Ordine di acquisto" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "" +"This will update all the line prices based on the vendor currently set. Do " +"you want to continue?" +msgstr "" +"Questo aggiornerà i prezzi di tutte le righe sulla base del fornitore " +"impostato in questo momento. Vuoi continuare?" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "Update lines info" +msgstr "Aggiorna info righe" + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" diff --git a/purchase_order_price_recalculation/i18n/purchase_order_price_recalculation.pot b/purchase_order_price_recalculation/i18n/purchase_order_price_recalculation.pot new file mode 100644 index 00000000000..984c0a4153f --- /dev/null +++ b/purchase_order_price_recalculation/i18n/purchase_order_price_recalculation.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_price_recalculation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_price_recalculation +#: model:ir.model,name:purchase_order_price_recalculation.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "" +"This will update all the line prices based on the vendor currently set. Do " +"you want to continue?" +msgstr "" + +#. module: purchase_order_price_recalculation +#: model_terms:ir.ui.view,arch_db:purchase_order_price_recalculation.purchase_order_form +msgid "Update lines info" +msgstr "" diff --git a/purchase_order_price_recalculation/models/__init__.py b/purchase_order_price_recalculation/models/__init__.py new file mode 100644 index 00000000000..2eaf7ea0a8b --- /dev/null +++ b/purchase_order_price_recalculation/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import purchase_order diff --git a/purchase_order_price_recalculation/models/purchase_order.py b/purchase_order_price_recalculation/models/purchase_order.py new file mode 100644 index 00000000000..6a8579e3509 --- /dev/null +++ b/purchase_order_price_recalculation/models/purchase_order.py @@ -0,0 +1,13 @@ +# Copyright 2022-2024 Tecnativa - Víctor Martínez +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def update_lines_info(self): + self.ensure_one() + for line in self.order_line: + line._compute_price_unit_and_date_planned_and_name() + return True diff --git a/purchase_order_price_recalculation/pyproject.toml b/purchase_order_price_recalculation/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_order_price_recalculation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_order_price_recalculation/readme/CONTRIBUTORS.md b/purchase_order_price_recalculation/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..6af64d1323d --- /dev/null +++ b/purchase_order_price_recalculation/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://www.tecnativa.com): + - Víctor Martínez + - Pedro M. Baeza +- [Komit](https://komit-consulting.com): + - Cai Hoang Huynh diff --git a/purchase_order_price_recalculation/readme/DESCRIPTION.md b/purchase_order_price_recalculation/readme/DESCRIPTION.md new file mode 100644 index 00000000000..a4fd410bba3 --- /dev/null +++ b/purchase_order_price_recalculation/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module adds one button on purchase orders (below the lines) that: + +- Recalculates the prices of the order lines that contain a product in + them. + +It is launched manually as a button to get the user to decide if he/she +wants to recalculate prices when vendor is changed or after duplicating +a purchase order to update or not purchase information. diff --git a/purchase_order_price_recalculation/readme/USAGE.md b/purchase_order_price_recalculation/readme/USAGE.md new file mode 100644 index 00000000000..dc39a5b2d28 --- /dev/null +++ b/purchase_order_price_recalculation/readme/USAGE.md @@ -0,0 +1,10 @@ +1. Go to *Purchase -\> Products \> Products* and create some record and + set differente prices to vendors in Purchase tab, for example: + Vendor 1: 10 and Vendor 2: 20. +2. Go to *Purchase -\> Orders \> Requests for Quotation* and create + some record and set Vendor 1. +3. Add a line with the previously created product. +4. The unit price of the product is 10. +5. Change vendor to Vendor 2. +6. Click on the "Update lines info" button. +7. The unit price of the product is 20. diff --git a/purchase_order_price_recalculation/static/description/icon.png b/purchase_order_price_recalculation/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_price_recalculation/static/description/icon.png differ diff --git a/purchase_order_price_recalculation/static/description/index.html b/purchase_order_price_recalculation/static/description/index.html new file mode 100644 index 00000000000..bc13d121714 --- /dev/null +++ b/purchase_order_price_recalculation/static/description/index.html @@ -0,0 +1,456 @@ + + + + + +Price recalculation in purchases orders + + + +
+

Price recalculation in purchases orders

+ + +

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

+

This module adds one button on purchase orders (below the lines) that:

+
    +
  • Recalculates the prices of the order lines that contain a product in +them.
  • +
+

It is launched manually as a button to get the user to decide if he/she +wants to recalculate prices when vendor is changed or after duplicating +a purchase order to update or not purchase information.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Purchase -> Products > Products and create some record and +set differente prices to vendors in Purchase tab, for example: Vendor +1: 10 and Vendor 2: 20.
  2. +
  3. Go to Purchase -> Orders > Requests for Quotation and create some +record and set Vendor 1.
  4. +
  5. Add a line with the previously created product.
  6. +
  7. The unit price of the product is 10.
  8. +
  9. Change vendor to Vendor 2.
  10. +
  11. Click on the “Update lines info” button.
  12. +
  13. The unit price of the product is 20.
  14. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
  • Komit:
      +
    • Cai Hoang Huynh
    • +
    +
  • +
+
+
+

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.

+

Current maintainer:

+

victoralmau

+

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_price_recalculation/tests/__init__.py b/purchase_order_price_recalculation/tests/__init__.py new file mode 100644 index 00000000000..3f6b4227301 --- /dev/null +++ b/purchase_order_price_recalculation/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import test_purchase_order_price_recalculation diff --git a/purchase_order_price_recalculation/tests/test_purchase_order_price_recalculation.py b/purchase_order_price_recalculation/tests/test_purchase_order_price_recalculation.py new file mode 100644 index 00000000000..ea03e85d59f --- /dev/null +++ b/purchase_order_price_recalculation/tests/test_purchase_order_price_recalculation.py @@ -0,0 +1,52 @@ +# Copyright 2022-2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo.tests import Form + +from odoo.addons.base.tests.common import BaseCommon + + +class TestPurchaseOrderPriceRecalculation(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_a = cls.env["res.partner"].create({"name": "Test partner A"}) + cls.partner_b = cls.env["res.partner"].create({"name": "Test partner B"}) + cls.product = cls.env["product.product"].create( + { + "name": "Test product", + "seller_ids": [ + (0, 0, {"partner_id": cls.partner_a.id, "price": 10}), + (0, 0, {"partner_id": cls.partner_b.id, "price": 20}), + ], + } + ) + cls.order = cls._create_order(cls, cls.partner_a) + + def _create_order(self, partner): + order_form = Form(self.env["purchase.order"]) + order_form.partner_id = partner + with order_form.order_line.new() as line_form: + line_form.product_id = self.product + line_form.product_qty = 1 + return order_form.save() + + def test_order_update_lines_info(self): + product_line = self.order.order_line + self.assertEqual(product_line.price_unit, 10) + # Test form + order_form = Form(self.order) + order_form.partner_id = self.partner_b + # Update partner + self.order.partner_id = self.partner_b + self.assertEqual(product_line.price_unit, 20) + + def test_sale_order_update_lines_after_vendor_price_change(self): + product_line = self.order.order_line + self.assertEqual(product_line.price_unit, 10) + # Change vendor price + self.product.seller_ids.filtered( + lambda s: s.partner_id == self.partner_a + ).write({"price": 15}) + self.order.update_lines_info() + self.assertEqual(product_line.price_unit, 15) diff --git a/purchase_order_price_recalculation/views/purchase_order_view.xml b/purchase_order_price_recalculation/views/purchase_order_view.xml new file mode 100644 index 00000000000..a0b89af8ea6 --- /dev/null +++ b/purchase_order_price_recalculation/views/purchase_order_view.xml @@ -0,0 +1,19 @@ + + + + purchase.order + + + + + +