From 56a0d481caf736dc455f2ebafd1c7ec9b06bfa06 Mon Sep 17 00:00:00 2001 From: ernesto Date: Thu, 19 Sep 2019 13:04:31 -0400 Subject: [PATCH] [ADD] stock_product_pack: new module --- stock_product_pack/README.rst | 110 +++++ stock_product_pack/__init__.py | 2 + stock_product_pack/__manifest__.py | 24 + stock_product_pack/i18n/es.po | 22 + stock_product_pack/models/__init__.py | 3 + stock_product_pack/models/product_product.py | 37 ++ stock_product_pack/readme/CONFIGURE.rst | 6 + stock_product_pack/readme/CONTRIBUTORS.rst | 5 + stock_product_pack/readme/DESCRIPTION.rst | 2 + stock_product_pack/readme/USAGE.rst | 8 + .../static/description/index.html | 452 ++++++++++++++++++ stock_product_pack/tests/__init__.py | 3 + .../tests/test_stock_product_pack.py | 80 ++++ 13 files changed, 754 insertions(+) create mode 100644 stock_product_pack/README.rst create mode 100644 stock_product_pack/__init__.py create mode 100644 stock_product_pack/__manifest__.py create mode 100644 stock_product_pack/i18n/es.po create mode 100644 stock_product_pack/models/__init__.py create mode 100644 stock_product_pack/models/product_product.py create mode 100644 stock_product_pack/readme/CONFIGURE.rst create mode 100644 stock_product_pack/readme/CONTRIBUTORS.rst create mode 100644 stock_product_pack/readme/DESCRIPTION.rst create mode 100644 stock_product_pack/readme/USAGE.rst create mode 100644 stock_product_pack/static/description/index.html create mode 100644 stock_product_pack/tests/__init__.py create mode 100644 stock_product_pack/tests/test_stock_product_pack.py diff --git a/stock_product_pack/README.rst b/stock_product_pack/README.rst new file mode 100644 index 00000000..856de3a6 --- /dev/null +++ b/stock_product_pack/README.rst @@ -0,0 +1,110 @@ +================== +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/12.0/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-12-0/product-pack-12-0-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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to get the right available *On Hand* and *Forecasted* +quantities of the packs. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +#. Go to *Inventory -> Master Data -> Product*, create a product and check + "Is Pack?" field, then set the products has to include in the Pack. +#. Set type of product pack. + + +Usage +===== + +To use this module, you need to: + +#. Go to *Inventory -> Operations -> Transfers* and create transfer related to + components of a Pack 'X'. +#. Then go to *Inventory -> Master Data -> Product*, find the Pack 'X' and you + will see in the smart buttons that show *On Hand* and *Forecasted* the + quantities based on the *On Hand* and *Forecasted* quantities of + its components. That is the minimum quantities of its components. + +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 +~~~~~~~ + +* NaN·tic +* ADHOC SA +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + * Sergio Teruel + +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-ernestotejeda| image:: https://github.com/ernestotejeda.png?size=40px + :target: https://github.com/ernestotejeda + :alt: ernestotejeda + +Current `maintainer `__: + +|maintainer-ernestotejeda| + +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/stock_product_pack/__init__.py b/stock_product_pack/__init__.py new file mode 100644 index 00000000..cb45f271 --- /dev/null +++ b/stock_product_pack/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/stock_product_pack/__manifest__.py b/stock_product_pack/__manifest__.py new file mode 100644 index 00000000..81689daf --- /dev/null +++ b/stock_product_pack/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2019 NaN (http://www.nan-tic.com) - Àngel Àlvarez +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Stock product Pack', + 'version': '12.0.1.0.0', + 'category': 'Warehouse', + 'summary': 'This module allows you to get the right available quantities ' + 'of the packs', + 'website': 'https://github.com/OCA/product-pack', + 'author': 'NaN·tic, ' + 'ADHOC SA, ' + 'Tecnativa, ' + 'Odoo Community Association (OCA)', + 'maintainers': ['ernestotejeda'], + 'license': 'AGPL-3', + 'depends': [ + 'product_pack', + 'stock', + ], + 'installable': True, + 'auto_install': True, + 'application': False, +} diff --git a/stock_product_pack/i18n/es.po b/stock_product_pack/i18n/es.po new file mode 100644 index 00000000..15ebbb44 --- /dev/null +++ b/stock_product_pack/i18n/es.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_product_pack +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-09-18 14:54+0000\n" +"PO-Revision-Date: 2019-09-18 14:54+0000\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: stock_product_pack +#: model:ir.model,name:stock_product_pack.model_product_product +msgid "Product" +msgstr "Producto" + diff --git a/stock_product_pack/models/__init__.py b/stock_product_pack/models/__init__.py new file mode 100644 index 00000000..586a7eff --- /dev/null +++ b/stock_product_pack/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import product_product diff --git a/stock_product_pack/models/product_product.py b/stock_product_pack/models/product_product.py new file mode 100644 index 00000000..f7c75a69 --- /dev/null +++ b/stock_product_pack/models/product_product.py @@ -0,0 +1,37 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models +import math + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + def _compute_quantities_dict( + self, lot_id, owner_id, package_id, + from_date=False, to_date=False): + res = super()._compute_quantities_dict( + lot_id, owner_id, package_id, from_date=from_date, to_date=to_date) + packs = self.filtered('pack_ok') + for product in packs.with_context(prefetch_fields=False): + pack_qty_available = [] + pack_virtual_available = [] + for subproduct in product.pack_line_ids: + subproduct_stock = subproduct.product_id + sub_qty = subproduct.quantity + if sub_qty: + pack_qty_available.append(math.floor( + subproduct_stock.qty_available / sub_qty)) + pack_virtual_available.append(math.floor( + subproduct_stock.virtual_available / sub_qty)) + res[product.id] = { + 'qty_available': ( + pack_qty_available and min(pack_qty_available) or False), + 'incoming_qty': 0, + 'outgoing_qty': 0, + 'virtual_available': ( + pack_virtual_available and + min(pack_virtual_available) or False), + } + return res diff --git a/stock_product_pack/readme/CONFIGURE.rst b/stock_product_pack/readme/CONFIGURE.rst new file mode 100644 index 00000000..15821106 --- /dev/null +++ b/stock_product_pack/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +To configure this module, you need to: + +#. Go to *Inventory -> Master Data -> Product*, create a product and check + "Is Pack?" field, then set the products has to include in the Pack. +#. Set type of product pack. + diff --git a/stock_product_pack/readme/CONTRIBUTORS.rst b/stock_product_pack/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..0c711025 --- /dev/null +++ b/stock_product_pack/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + * Sergio Teruel diff --git a/stock_product_pack/readme/DESCRIPTION.rst b/stock_product_pack/readme/DESCRIPTION.rst new file mode 100644 index 00000000..f9333607 --- /dev/null +++ b/stock_product_pack/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows you to get the right available *On Hand* and *Forecasted* +quantities of the packs. diff --git a/stock_product_pack/readme/USAGE.rst b/stock_product_pack/readme/USAGE.rst new file mode 100644 index 00000000..db8b69e5 --- /dev/null +++ b/stock_product_pack/readme/USAGE.rst @@ -0,0 +1,8 @@ +To use this module, you need to: + +#. Go to *Inventory -> Operations -> Transfers* and create transfer related to + components of a Pack 'X'. +#. Then go to *Inventory -> Master Data -> Product*, find the Pack 'X' and you + will see in the smart buttons that show *On Hand* and *Forecasted* the + quantities based on the *On Hand* and *Forecasted* quantities of + its components. That is the minimum quantities of its components. diff --git a/stock_product_pack/static/description/index.html b/stock_product_pack/static/description/index.html new file mode 100644 index 00000000..40faa7ac --- /dev/null +++ b/stock_product_pack/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Stock product Pack + + + +
+

Stock product Pack

+ + +

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

+

This module allows you to get the right available On Hand and Forecasted +quantities of the packs.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Inventory -> Master Data -> Product, create a product and check +“Is Pack?” field, then set the products has to include in the Pack.
  2. +
  3. Set type of product pack.
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Inventory -> Operations -> Transfers and create transfer related to +components of a Pack ‘X’.
  2. +
  3. Then go to Inventory -> Master Data -> Product, find the Pack ‘X’ and you +will see in the smart buttons that show On Hand and Forecasted the +quantities based on the On Hand and Forecasted quantities of +its components. That is the minimum quantities of its components.
  4. +
+
+
+

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

+
    +
  • NaN·tic
  • +
  • ADHOC SA
  • +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Ernesto Tejeda
    • +
    • Pedro M. Baeza
    • +
    • Sergio Teruel
    • +
    +
  • +
+
+
+

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:

+

ernestotejeda

+

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/stock_product_pack/tests/__init__.py b/stock_product_pack/tests/__init__.py new file mode 100644 index 00000000..21c96b0c --- /dev/null +++ b/stock_product_pack/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_stock_product_pack diff --git a/stock_product_pack/tests/test_stock_product_pack.py b/stock_product_pack/tests/test_stock_product_pack.py new file mode 100644 index 00000000..2c6ff744 --- /dev/null +++ b/stock_product_pack/tests/test_stock_product_pack.py @@ -0,0 +1,80 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import SavepointCase +import logging + +_logger = logging.getLogger(__name__) + + +class TestSaleProductPack(SavepointCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + category_all_id = cls.env.ref('product.product_category_all').id + product_obj = cls.env['product.product'] + cls.pack_dc = cls.env['product.product'].create({ + 'name': 'Pack', + 'type': 'product', + 'pack_ok': True, + 'pack_type': 'detailed', + 'pack_component_price': 'detailed', + 'categ_id': category_all_id, + 'pack_line_ids': [ + (0, 0, { + 'product_id': product_obj.create({ + 'name': 'Component 1', + 'type': 'product', + 'categ_id': category_all_id, + }).id, + 'quantity': 1, + }), + (0, 0, { + 'product_id': product_obj.create({ + 'name': 'Component 2', + 'type': 'product', + 'categ_id': category_all_id, + }).id, + 'quantity': 1, + }), + ] + }) + + def test_compute_quantities_dict(self): + location_id = self.env.ref('stock.stock_location_suppliers').id, + location_dest_id = self.env.ref('stock.stock_location_stock').id, + components = self.pack_dc.pack_line_ids.mapped('product_id') + picking = self.env['stock.picking'].create({ + 'partner_id': self.env.ref('base.res_partner_4').id, + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'location_id': location_id, + 'location_dest_id': location_dest_id, + 'move_lines': [ + (0, 0, { + 'name': 'incoming_move_test_01', + 'product_id': components[0].id, + 'product_uom_qty': 5, + 'product_uom': components[0].uom_id.id, + 'location_id': location_id, + 'location_dest_id': location_dest_id, + }), + (0, 0, { + 'name': 'incoming_move_test_02', + 'product_id': components[1].id, + 'product_uom_qty': 7, + 'product_uom': components[1].uom_id.id, + 'location_id': location_id, + 'location_dest_id': location_dest_id, + }), + ] + }) + picking.action_confirm() + self.assertEqual(self.pack_dc.virtual_available, 5) + self.assertEqual(self.pack_dc.qty_available, 0) + wizard_dict = picking.button_validate() + wizard = self.env[wizard_dict['res_model']].browse( + wizard_dict['res_id']) + wizard.process() + self.assertEqual(self.pack_dc.virtual_available, 5) + self.assertEqual(self.pack_dc.qty_available, 5)