diff --git a/maintenance_purchase_stock/README.rst b/maintenance_purchase_stock/README.rst new file mode 100644 index 000000000..2377de305 --- /dev/null +++ b/maintenance_purchase_stock/README.rst @@ -0,0 +1,79 @@ +========================== +Maintenance Purchase Stock +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9b4e0b44d941b38aadf91a2912f84cf907a7e32f5e5573d36779fd044fa0f7f9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmaintenance-lightgray.png?logo=github + :target: https://github.com/OCA/maintenance/tree/18.0/maintenance_purchase_stock + :alt: OCA/maintenance +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/maintenance-18-0/maintenance-18-0-maintenance_purchase_stock + :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/maintenance&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adapt the module "Maintenance Purchase" to create the equipments at +product reception + +**Table of contents** + +.. contents:: + :local: + +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 + + - Christian Ramos + +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/maintenance `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/maintenance_purchase_stock/__init__.py b/maintenance_purchase_stock/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/maintenance_purchase_stock/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/maintenance_purchase_stock/__manifest__.py b/maintenance_purchase_stock/__manifest__.py new file mode 100644 index 000000000..7bd7ad96b --- /dev/null +++ b/maintenance_purchase_stock/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2025 Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Maintenance Purchase Stock", + "summary": """ + Create Equipments when recieving purchased products""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/maintenance", + "depends": [ + "maintenance_purchase", + "purchase_stock", + ], + "data": [], + "demo": [], +} diff --git a/maintenance_purchase_stock/i18n/es.po b/maintenance_purchase_stock/i18n/es.po new file mode 100644 index 000000000..4441a05f3 --- /dev/null +++ b/maintenance_purchase_stock/i18n/es.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_purchase +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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.17\n" + +#. module: maintenance_purchase_stock +#: model:ir.model,name:maintenance_purchase_stock.model_purchase_order +msgid "Purchase Order" +msgstr "Orden de Compra" + +#. module: maintenance_purchase_stock +#: model:ir.model,name:maintenance_purchase_stock.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Línea de Orden de Compra" diff --git a/maintenance_purchase_stock/i18n/maintenance_purchase_stock.pot b/maintenance_purchase_stock/i18n/maintenance_purchase_stock.pot new file mode 100644 index 000000000..979e38e6e --- /dev/null +++ b/maintenance_purchase_stock/i18n/maintenance_purchase_stock.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_purchase_stock +# +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: maintenance_purchase_stock +#: model:ir.model,name:maintenance_purchase_stock.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: maintenance_purchase_stock +#: model:ir.model,name:maintenance_purchase_stock.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" diff --git a/maintenance_purchase_stock/models/__init__.py b/maintenance_purchase_stock/models/__init__.py new file mode 100644 index 000000000..9f0353064 --- /dev/null +++ b/maintenance_purchase_stock/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order diff --git a/maintenance_purchase_stock/models/purchase_order.py b/maintenance_purchase_stock/models/purchase_order.py new file mode 100644 index 000000000..ed67387b0 --- /dev/null +++ b/maintenance_purchase_stock/models/purchase_order.py @@ -0,0 +1,28 @@ +# Copyright 2025 Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def _get_lines_to_create_equipments(self): + return ( + super() + ._get_lines_to_create_equipments() + .filtered(lambda x: x.qty_received > len(x.equipment_ids)) + ) + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _qty_to_create_equipments(self): + return int(self.qty_received - len(self.equipment_ids)) + + @api.depends("move_ids.state", "move_ids.product_uom", "move_ids.quantity") + def _compute_qty_received(self): + res = super()._compute_qty_received() + self.order_id._create_equipments() + return res diff --git a/maintenance_purchase_stock/pyproject.toml b/maintenance_purchase_stock/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/maintenance_purchase_stock/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/maintenance_purchase_stock/readme/CONTRIBUTORS.md b/maintenance_purchase_stock/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..060fc5f38 --- /dev/null +++ b/maintenance_purchase_stock/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Tecnativa + - Christian Ramos diff --git a/maintenance_purchase_stock/readme/DESCRIPTION.md b/maintenance_purchase_stock/readme/DESCRIPTION.md new file mode 100644 index 000000000..bf8486ae0 --- /dev/null +++ b/maintenance_purchase_stock/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Adapt the module "Maintenance Purchase" to create the equipments +at product reception diff --git a/maintenance_purchase_stock/static/description/icon.png b/maintenance_purchase_stock/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/maintenance_purchase_stock/static/description/icon.png differ diff --git a/maintenance_purchase_stock/static/description/index.html b/maintenance_purchase_stock/static/description/index.html new file mode 100644 index 000000000..4960ffbb5 --- /dev/null +++ b/maintenance_purchase_stock/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Maintenance Purchase Stock + + + +
+

Maintenance Purchase Stock

+ + +

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

+

Adapt the module “Maintenance Purchase” to create the equipments at +product reception

+

Table of contents

+ +
+

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
      +
    • Christian Ramos
    • +
    +
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/maintenance_purchase_stock/tests/__init__.py b/maintenance_purchase_stock/tests/__init__.py new file mode 100644 index 000000000..2eb753c46 --- /dev/null +++ b/maintenance_purchase_stock/tests/__init__.py @@ -0,0 +1 @@ +from . import test_maintenance_purchase_stock diff --git a/maintenance_purchase_stock/tests/test_maintenance_purchase_stock.py b/maintenance_purchase_stock/tests/test_maintenance_purchase_stock.py new file mode 100644 index 000000000..e8a8ee6ec --- /dev/null +++ b/maintenance_purchase_stock/tests/test_maintenance_purchase_stock.py @@ -0,0 +1,126 @@ +# Copyright 2025 Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon + + +class TestMaintenancePurchaseStock(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.Equipment = cls.env["maintenance.equipment"] + cls.EquipmentCategory = cls.env["maintenance.equipment.category"] + cls.MaintenanceEquipmentCategory = cls.env["maintenance.equipment.category"] + cls.PurchaseOrder = cls.env["purchase.order"] + cls.PurchaseOrderLine = cls.env["purchase.order.line"] + cls.ProductCategory = cls.env["product.category"] + cls.ProductProduct = cls.env["product.product"] + cls.ResPartner = cls.env["res.partner"] + + cls.partner = cls.ResPartner.create( + { + "name": "partner", + } + ) + uom_unit = cls.env.ref("uom.product_uom_unit") + cls.maintenance_equipment_category1 = cls.MaintenanceEquipmentCategory.create( + {"name": "My Maintenance Equipment Category 1"} + ) + cls.maintenance_equipment_category2 = cls.MaintenanceEquipmentCategory.create( + {"name": "My Maintenance Equipment Category 2"} + ) + cls.product_category01 = cls.ProductCategory.create( + { + "name": "My Product Category 1", + "equipment_category_ids": [ + Command.set( + [ + cls.maintenance_equipment_category1.id, + cls.maintenance_equipment_category2.id, + ] + ) + ], + } + ) + cls.product_category02 = cls.ProductCategory.create( + { + "name": "My Product Category 2", + "equipment_category_ids": [ + Command.set([cls.maintenance_equipment_category2.id]) + ], + } + ) + cls.product_order_maintenance = cls.ProductProduct.create( + { + "name": "My Product", + "standard_price": 235.0, + "list_price": 280.0, + "type": "consu", + "uom_id": uom_unit.id, + "uom_po_id": uom_unit.id, + "purchase_method": "purchase", + "default_code": "PROD_ORDER", + "taxes_id": False, + "maintenance_ok": True, + "categ_id": cls.product_category01.id, + } + ) + cls.product_order_no_maintenance = cls.ProductProduct.create( + { + "name": "My Product", + "standard_price": 235.0, + "list_price": 280.0, + "type": "consu", + "uom_id": uom_unit.id, + "uom_po_id": uom_unit.id, + "purchase_method": "purchase", + "default_code": "PROD_ORDER", + "taxes_id": False, + "categ_id": cls.product_category02.id, + } + ) + cls.purchase_order = cls.PurchaseOrder.with_context( + tracking_disable=True + ).create( + { + "partner_id": cls.partner.id, + } + ) + PurchaseOrderLine = cls.PurchaseOrderLine + cls.purchase_line_order01 = PurchaseOrderLine.create( + { + "name": cls.product_order_maintenance.name, + "product_id": cls.product_order_maintenance.id, + "product_qty": 10.0, + "product_uom": cls.product_order_maintenance.uom_id.id, + "price_unit": cls.product_order_maintenance.list_price, + "order_id": cls.purchase_order.id, + "taxes_id": False, + } + ) + cls.purchase_line_order02 = PurchaseOrderLine.create( + { + "name": cls.product_order_no_maintenance.name, + "product_id": cls.product_order_no_maintenance.id, + "product_qty": 10.0, + "product_uom": cls.product_order_no_maintenance.uom_id.id, + "price_unit": cls.product_order_no_maintenance.list_price, + "order_id": cls.purchase_order.id, + "taxes_id": False, + } + ) + + def test_equipment_count(self): + self.purchase_order.button_approve() + self.assertEqual(self.purchase_order.equipment_count, 0) + self.assertEqual(self.purchase_line_order01.equipment_count, 0) + self.assertEqual(self.purchase_line_order02.equipment_count, 0) + self.purchase_order.picking_ids.button_validate() + self.purchase_order.order_line._compute_qty_received() + self.purchase_order.order_line._compute_equipment_count() + self.purchase_order._compute_equipment_count() + self.assertEqual(self.purchase_order.equipment_count, 10) + self.assertEqual(self.purchase_line_order01.equipment_count, 10) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..9ccdd820c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-maintenance_purchase @ git+https://github.com/OCA/maintenance.git@refs/pull/536/head#subdirectory=maintenance_purchase