diff --git a/sale_stock_product_pack/README.rst b/sale_stock_product_pack/README.rst new file mode 100644 index 000000000..e30f1a1e4 --- /dev/null +++ b/sale_stock_product_pack/README.rst @@ -0,0 +1,97 @@ +======================= +Sale Stock Product Pack +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c81e7b28f443c2245ae020a601f05690394a2d93dbdcd6da083db3bc63784d4e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--pack-lightgray.png?logo=github + :target: https://github.com/OCA/product-pack/tree/18.0/sale_stock_product_pack + :alt: OCA/product-pack +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-pack-18-0/product-pack-18-0-sale_stock_product_pack + :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/product-pack&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules adds compatibility of product packs with sales and stock +altogether: + +- Correctly compute delivered quantities for the different types of + packs so they can be properly invoiced when the pack is storable. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +- Non detailed packs aren't yet supported by stock_product_pack, so no + support for them either in this module. + +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 `__: + + - Ernesto Tejeda + - Pedro M. Baeza + +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-chienandalu| image:: https://github.com/chienandalu.png?size=40px + :target: https://github.com/chienandalu + :alt: chienandalu + +Current `maintainer `__: + +|maintainer-chienandalu| + +This module is part of the `OCA/product-pack `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_stock_product_pack/__init__.py b/sale_stock_product_pack/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_stock_product_pack/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_stock_product_pack/__manifest__.py b/sale_stock_product_pack/__manifest__.py new file mode 100644 index 000000000..cd46295f2 --- /dev/null +++ b/sale_stock_product_pack/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Stock Product Pack", + "summary": "Compatibility module for packs that are storable products", + "version": "18.0.1.0.0", + "development_status": "Beta", + "category": "Sale", + "website": "https://github.com/OCA/product-pack", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["chienandalu"], + "license": "AGPL-3", + "depends": ["sale_product_pack", "stock_product_pack"], + "data": [], +} diff --git a/sale_stock_product_pack/i18n/sale_stock_product_pack.pot b/sale_stock_product_pack/i18n/sale_stock_product_pack.pot new file mode 100644 index 000000000..3a7a339f2 --- /dev/null +++ b/sale_stock_product_pack/i18n/sale_stock_product_pack.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_stock_product_pack +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: sale_stock_product_pack +#: model:ir.model,name:sale_stock_product_pack.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/sale_stock_product_pack/models/__init__.py b/sale_stock_product_pack/models/__init__.py new file mode 100644 index 000000000..6aacb7531 --- /dev/null +++ b/sale_stock_product_pack/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_stock_product_pack/models/sale_order.py b/sale_stock_product_pack/models/sale_order.py new file mode 100644 index 000000000..02df5ff1b --- /dev/null +++ b/sale_stock_product_pack/models/sale_order.py @@ -0,0 +1,31 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# pylint: disable=W8110 +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _compute_qty_delivered(self): + """Compute pack delivered pack quantites according to its components + deliveries""" + super()._compute_qty_delivered() + main_pack_lines = self.filtered("pack_parent_line_id").mapped( + "pack_parent_line_id" + ) + for line in main_pack_lines.filtered( + lambda x: x.qty_delivered_method == "stock_move" + and x.pack_child_line_ids + and x.product_uom_qty + ): + delivered_packs = [] + # We filter non qty lines of editable packs + for pack_line in line.pack_child_line_ids.filtered("product_uom_qty"): + # If a component isn't delivered, the pack isn't as well + if not pack_line.qty_delivered: + delivered_packs.append(0) + break + qty_per_pack = pack_line.product_uom_qty / line.product_uom_qty + delivered_packs.append(pack_line.qty_delivered / qty_per_pack) + line.qty_delivered = delivered_packs and min(delivered_packs) or 0.0 diff --git a/sale_stock_product_pack/pyproject.toml b/sale_stock_product_pack/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_stock_product_pack/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_stock_product_pack/readme/CONTRIBUTORS.md b/sale_stock_product_pack/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..dc534b9df --- /dev/null +++ b/sale_stock_product_pack/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + - Ernesto Tejeda + - Pedro M. Baeza diff --git a/sale_stock_product_pack/readme/DESCRIPTION.md b/sale_stock_product_pack/readme/DESCRIPTION.md new file mode 100644 index 000000000..114678ae3 --- /dev/null +++ b/sale_stock_product_pack/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This modules adds compatibility of product packs with sales and stock +altogether: + +- Correctly compute delivered quantities for the different types of + packs so they can be properly invoiced when the pack is storable. diff --git a/sale_stock_product_pack/readme/ROADMAP.md b/sale_stock_product_pack/readme/ROADMAP.md new file mode 100644 index 000000000..82508c0b5 --- /dev/null +++ b/sale_stock_product_pack/readme/ROADMAP.md @@ -0,0 +1,2 @@ +- Non detailed packs aren't yet supported by stock_product_pack, so no + support for them either in this module. diff --git a/sale_stock_product_pack/static/description/icon.png b/sale_stock_product_pack/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_stock_product_pack/static/description/icon.png differ diff --git a/sale_stock_product_pack/static/description/index.html b/sale_stock_product_pack/static/description/index.html new file mode 100644 index 000000000..a108014ed --- /dev/null +++ b/sale_stock_product_pack/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Sale Stock Product Pack + + + +
+

Sale Stock Product Pack

+ + +

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

+

This modules adds compatibility of product packs with sales and stock +altogether:

+
    +
  • Correctly compute delivered quantities for the different types of +packs so they can be properly invoiced when the pack is storable.
  • +
+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • Non detailed packs aren’t yet supported by stock_product_pack, so no +support for them either in this module.
  • +
+
+
+

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:
      +
    • Ernesto Tejeda
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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:

+

chienandalu

+

This module is part of the OCA/product-pack project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_stock_product_pack/tests/__init__.py b/sale_stock_product_pack/tests/__init__.py new file mode 100644 index 000000000..e8d23af43 --- /dev/null +++ b/sale_stock_product_pack/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_stock_product_pack diff --git a/sale_stock_product_pack/tests/test_sale_stock_product_pack.py b/sale_stock_product_pack/tests/test_sale_stock_product_pack.py new file mode 100644 index 000000000..cda00fda7 --- /dev/null +++ b/sale_stock_product_pack/tests/test_sale_stock_product_pack.py @@ -0,0 +1,39 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import Form, TransactionCase + + +class TestSaleStockProductPack(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_pack = cls.env.ref( + "product_pack.product_pack_cpu_detailed_components" + ) + cls.product_pack.type = "consu" + cls.product_pack.invoice_policy = "delivery" + cls.product_pack.pack_line_ids.product_id.invoice_policy = "delivery" + sale_form = Form(cls.env["sale.order"]) + sale_form.partner_id = cls.env["res.partner"].create({"name": "Mr. Odoo"}) + with sale_form.order_line.new() as line: + line.product_id = cls.product_pack + line.product_uom_qty = 9 + cls.sale = sale_form.save() + cls.sale.action_confirm() + + def test_delivered_quantities(self): + pack_line = self.sale.order_line.filtered( + lambda x: x.product_id == self.product_pack + ) + self.assertEqual(0, pack_line.qty_delivered) + # Process the picking + for line in self.sale.picking_ids.move_ids.filtered( + lambda x: x.product_id != self.product_pack + ): + line.quantity = line.product_uom_qty + self.sale.picking_ids.move_ids.picked = True + self.sale.picking_ids._action_done() + # All components delivered, all the pack quantities should be so + # TODO: it needs to compute twice. In view it does it fine. + self.sale.order_line.mapped("qty_delivered") + self.assertEqual(9, pack_line.qty_delivered)