diff --git a/setup/stock_packaging/.eggs/README.txt b/setup/stock_packaging/.eggs/README.txt new file mode 100644 index 000000000..5d0166882 --- /dev/null +++ b/setup/stock_packaging/.eggs/README.txt @@ -0,0 +1,6 @@ +This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. + +This directory caches those eggs to prevent repeated downloads. + +However, it is safe to delete this directory. + diff --git a/setup/stock_packaging/odoo/addons/stock_packaging b/setup/stock_packaging/odoo/addons/stock_packaging new file mode 120000 index 000000000..4dfa1b2d0 --- /dev/null +++ b/setup/stock_packaging/odoo/addons/stock_packaging @@ -0,0 +1 @@ +../../../../stock_packaging/ \ No newline at end of file diff --git a/setup/stock_packaging/setup.py b/setup/stock_packaging/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_packaging/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_packaging/README.rst b/stock_packaging/README.rst new file mode 100644 index 000000000..c484b2b71 --- /dev/null +++ b/stock_packaging/README.rst @@ -0,0 +1,84 @@ +=============== +Stock Packaging +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_packaging + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_packaging + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules allows to propagate the product packaging through +the stock moves. + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laetita Gangloff +* Laurent Mignon +* Denis Roussel + +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-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_packaging/__init__.py b/stock_packaging/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_packaging/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_packaging/__manifest__.py b/stock_packaging/__manifest__.py new file mode 100644 index 000000000..e77648a16 --- /dev/null +++ b/stock_packaging/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Stock Packaging', + 'summary': """ + Allows to propagate packaging through stock flows""", + 'version': '12.0.1.0.0', + 'license': 'AGPL-3', + 'development_status': 'Beta', + 'maintainers': ['rousseldenis'], + 'website': 'https://github.com/OCA/stock-logistics-workflow', + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'depends': [ + 'stock', + 'packaging_uom', + ], + 'data': [ + 'views/stock_rule.xml', + ], +} diff --git a/stock_packaging/models/__init__.py b/stock_packaging/models/__init__.py new file mode 100644 index 000000000..144c5d760 --- /dev/null +++ b/stock_packaging/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_move +from . import stock_rule diff --git a/stock_packaging/models/stock_move.py b/stock_packaging/models/stock_move.py new file mode 100644 index 000000000..8d846781d --- /dev/null +++ b/stock_packaging/models/stock_move.py @@ -0,0 +1,17 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockMove(models.Model): + + _inherit = 'stock.move' + + def _prepare_procurement_values(self): + vals = super()._prepare_procurement_values() + if self.product_packaging and \ + self.rule_id and \ + self.rule_id.propagate_product_packaging: + vals.update({'product_packaging': self.product_packaging.id}) + return vals diff --git a/stock_packaging/models/stock_rule.py b/stock_packaging/models/stock_rule.py new file mode 100644 index 000000000..b5592e654 --- /dev/null +++ b/stock_packaging/models/stock_rule.py @@ -0,0 +1,38 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockRule(models.Model): + + _inherit = 'stock.rule' + + propagate_product_packaging = fields.Boolean( + default=True, + ) + + def _get_stock_move_values( + self, product_id, product_qty, product_uom, location_id, name, + origin, values, group_id): + """ + If stock rule has propagate_product_packaging enabled, update + stock move with it. + :param product_id: + :param product_qty: + :param product_uom: + :param location_id: + :param name: + :param origin: + :param values: + :param group_id: + :return: + """ + res = super()._get_stock_move_values( + product_id, product_qty, product_uom, location_id, name, origin, + values, group_id) + if 'product_packaging' in values: + res.update({ + 'product_packaging': values.get('product_packaging') + }) + return res diff --git a/stock_packaging/readme/CONTRIBUTORS.rst b/stock_packaging/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2fc8b941a --- /dev/null +++ b/stock_packaging/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Laetita Gangloff +* Laurent Mignon +* Denis Roussel diff --git a/stock_packaging/readme/DESCRIPTION.rst b/stock_packaging/readme/DESCRIPTION.rst new file mode 100644 index 000000000..986e4378e --- /dev/null +++ b/stock_packaging/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This modules allows to propagate the product packaging through +the stock moves. diff --git a/stock_packaging/readme/HISTORY.rst b/stock_packaging/readme/HISTORY.rst new file mode 100644 index 000000000..e69de29bb diff --git a/stock_packaging/readme/USAGE.rst b/stock_packaging/readme/USAGE.rst new file mode 100644 index 000000000..e69de29bb diff --git a/stock_packaging/static/description/icon.png b/stock_packaging/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_packaging/static/description/icon.png differ diff --git a/stock_packaging/static/description/index.html b/stock_packaging/static/description/index.html new file mode 100644 index 000000000..bdc50e4e7 --- /dev/null +++ b/stock_packaging/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Stock Packaging + + + +
+

Stock Packaging

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This modules allows to propagate the product packaging through +the stock moves.

+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

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:

+

rousseldenis

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_packaging/tests/__init__.py b/stock_packaging/tests/__init__.py new file mode 100644 index 000000000..e3340c397 --- /dev/null +++ b/stock_packaging/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_packaging diff --git a/stock_packaging/tests/test_stock_packaging.py b/stock_packaging/tests/test_stock_packaging.py new file mode 100644 index 000000000..0af32818f --- /dev/null +++ b/stock_packaging/tests/test_stock_packaging.py @@ -0,0 +1,197 @@ +# Copyright 2015-2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import odoo.tests.common as common + + +class TestStockMove(common.TransactionCase): + + def setUp(self): + """ Create a packaging with uom product_uom_dozen on + * product_product_3 (uom is product_uom_unit) + """ + super(TestStockMove, self).setUp() + self.location_customers = self.env.ref( + 'stock.stock_location_customers') + self.location_out = self.env.ref('stock.stock_location_output') + self.product = self.env.ref('product.product_product_3') + self.product_packaging_dozen = self.env['product.packaging'].create({ + 'product_id': self.product.id, + 'uom_id': self.env.ref('uom.product_uom_dozen').id, + 'name': 'dozen', + }) + self.product_packaging_dozen.product_id.lst_price = 45 + + vals = { + 'name': 'ROUTE 1', + 'sequence': 1, + 'product_selectable': True, + } + self.route = self.env['stock.location.route'].create(vals) + + vals = { + 'name': 'OUT => Customer', + 'action': 'pull', + 'location_id': self.location_customers.id, + 'location_src_id': self.location_out.id, + 'procure_method': 'make_to_order', + 'route_id': self.route.id, + 'picking_type_id': self.ref('stock.picking_type_out'), + 'propagate_product_packaging': True, + } + + self.rule = self.env['stock.rule'].create(vals) + + vals = { + 'name': 'Stock => OUT', + 'action': 'pull', + 'location_id': self.location_out.id, + 'location_src_id': self.ref('stock.stock_location_stock'), + 'procure_method': 'make_to_stock', + 'route_id': self.route.id, + 'picking_type_id': self.ref('stock.picking_type_internal'), + } + + self.rule_pick = self.env['stock.rule'].create(vals) + + self.env.ref('product.product_product_3').route_ids |= self.route + + vals = { + 'name': 'PROC 1', + } + self.group = self.env['procurement.group'].create(vals) + + def test_stock_move(self): + """ + Set product_packaging product_packaging_dozen + Run a procurement group with product product_3 + Check Procurement contains product packaging + Run Procurement + Check Stock Moves contain product packaging + """ + self.env['procurement.group'].run( + self.product, + 1.0, + self.product_packaging_dozen.uom_id, + self.env.ref('stock.stock_location_customers'), + 'TEST', + 'TEST', + { + 'product_packaging': self.product_packaging_dozen.id, + 'group_id': self.group, + }, + ) + move = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_out.id) + ]) + + self.assertEqual( + 1, + len(move), + "There is no move") + self.assertEqual( + self.product_packaging_dozen, + move.product_packaging, + "The Customer procurement does not contain the product packaging") + # Run Procurement + move._action_done() + # Check Move OUT => Customer + move = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_customers.id) + ]) + self.assertEqual( + 1, + len(move), + "There is no Move OUT") + move = move.picking_id.move_lines.filtered( + lambda m: m.product_id == + self.env.ref('product.product_product_3')) + self.assertEqual( + self.product_packaging_dozen, + move.product_packaging, + "Stock Move OUT does not contains product packaging") + # Check Move STOCK => OUT + picking_stock = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_out.id) + ]).picking_id + self.assertEqual( + 1, + len(picking_stock), + "There is no Picking Stock") + move = picking_stock.move_lines.filtered( + lambda m: m.product_id == + self.env.ref('product.product_product_3')) + self.assertEqual( + self.product_packaging_dozen, + move.product_packaging, + "Stock Move STOCK does not contains product packaging") + + def test_stock_move_no_propagate(self): + """ Change Procurement Rule to no propagate product packaging + Create a sale order line with product product_3 + Set product_packaging product_packaging_dozen + Confirm sale order + Check Procurement contains product packaging + Run Procurement + Check Stock Moves contain product packaging + """ + self.rule.propagate_product_packaging = False + self.env['procurement.group'].run( + self.product, + 1.0, + self.product_packaging_dozen.uom_id, + self.env.ref('stock.stock_location_customers'), + 'TEST', + 'TEST', + { + 'product_packaging': self.product_packaging_dozen.id, + 'group_id': self.group, + }, + ) + move = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_out.id) + ]) + + self.assertEqual( + 1, + len(move), + "There is no move") + self.assertFalse( + move.product_packaging, + "The Customer procurement does not contain the product packaging") + # Run Procurement + move._action_done() + # Check Move OUT => Customer + move = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_customers.id) + ]) + self.assertEqual( + 1, + len(move), + "There is no Move OUT") + move = move.picking_id.move_lines.filtered( + lambda m: m.product_id == + self.env.ref('product.product_product_3')) + self.assertEqual( + self.product_packaging_dozen, + move.product_packaging, + "Stock Move OUT does not contains product packaging") + # Check Move STOCK => OUT + picking_stock = self.env['stock.move'].search([ + ('group_id', '=', self.group.id), + ('location_dest_id', '=', self.location_out.id) + ]).picking_id + self.assertEqual( + 1, + len(picking_stock), + "There is no Picking Stock") + move = picking_stock.move_lines.filtered( + lambda m: m.product_id == + self.env.ref('product.product_product_3')) + self.assertFalse( + move.product_packaging, + "Stock Move STOCK does not contains product packaging") diff --git a/stock_packaging/views/stock_rule.xml b/stock_packaging/views/stock_rule.xml new file mode 100644 index 000000000..6af80e450 --- /dev/null +++ b/stock_packaging/views/stock_rule.xml @@ -0,0 +1,18 @@ + + + + + + + stock.rule.form (in stock_packaging) + stock.rule + + + + + + + + +