diff --git a/sale_stock_product_pack/README.rst b/sale_stock_product_pack/README.rst new file mode 100644 index 00000000..7474954f --- /dev/null +++ b/sale_stock_product_pack/README.rst @@ -0,0 +1,93 @@ +======================= +Sale Stock Product Pack +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/13.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-13-0/product-pack-13-0-sale_stock_product_pack + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/286/13.0 + :alt: Try me on Runbot + +|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 smashing 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 00000000..0650744f --- /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 00000000..25ebdf43 --- /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": "16.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 00000000..3a7a339f --- /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 00000000..6aacb753 --- /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 00000000..02df5ff1 --- /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/readme/CONTRIBUTORS.rst b/sale_stock_product_pack/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b31cef32 --- /dev/null +++ b/sale_stock_product_pack/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza diff --git a/sale_stock_product_pack/readme/DESCRIPTION.rst b/sale_stock_product_pack/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e2013009 --- /dev/null +++ b/sale_stock_product_pack/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +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.rst b/sale_stock_product_pack/readme/ROADMAP.rst new file mode 100644 index 00000000..71fa3fc0 --- /dev/null +++ b/sale_stock_product_pack/readme/ROADMAP.rst @@ -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 00000000..3a0328b5 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 00000000..d3b96714 --- /dev/null +++ b/sale_stock_product_pack/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Sale Stock Product Pack + + + +
+

Sale Stock Product Pack

+ + +

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

+

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 smashing 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 00000000..e8d23af4 --- /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 00000000..886cb4e1 --- /dev/null +++ b/sale_stock_product_pack/tests/test_sale_stock_product_pack.py @@ -0,0 +1,38 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import Form, common + + +class TestSaleStockProductPack(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_pack = cls.env.ref( + "product_pack.product_pack_cpu_detailed_components" + ) + cls.product_pack.type = "product" + 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_done = line.product_uom_qty + 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) diff --git a/setup/sale_stock_product_pack/odoo/addons/sale_stock_product_pack b/setup/sale_stock_product_pack/odoo/addons/sale_stock_product_pack new file mode 120000 index 00000000..a433903f --- /dev/null +++ b/setup/sale_stock_product_pack/odoo/addons/sale_stock_product_pack @@ -0,0 +1 @@ +../../../../sale_stock_product_pack \ No newline at end of file diff --git a/setup/sale_stock_product_pack/setup.py b/setup/sale_stock_product_pack/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/sale_stock_product_pack/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)