diff --git a/setup/stock_picking_report_valued_sale_mrp/odoo/addons/stock_picking_report_valued_sale_mrp b/setup/stock_picking_report_valued_sale_mrp/odoo/addons/stock_picking_report_valued_sale_mrp new file mode 120000 index 0000000..01fd4ce --- /dev/null +++ b/setup/stock_picking_report_valued_sale_mrp/odoo/addons/stock_picking_report_valued_sale_mrp @@ -0,0 +1 @@ +../../../../stock_picking_report_valued_sale_mrp \ No newline at end of file diff --git a/setup/stock_picking_report_valued_sale_mrp/setup.py b/setup/stock_picking_report_valued_sale_mrp/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/stock_picking_report_valued_sale_mrp/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_report_valued_sale_mrp/README.rst b/stock_picking_report_valued_sale_mrp/README.rst new file mode 100644 index 0000000..858d714 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/README.rst @@ -0,0 +1,114 @@ +=================================== +Valued picking linked with MRP Kits +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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--reporting-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_picking_report_valued_sale_mrp + :alt: OCA/stock-logistics-reporting +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_picking_report_valued_sale_mrp + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/151/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of `stock_picking_report_valued` with +compatibility of MRP kits. Now we'll be able to correctly summarize the picking +value related to the selled kit with a relations of components and serials/lots +delivered. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To test this module: + +#. Configure some products with traceability and make them kit components. +#. Sell the kits and go to the stock picking. +#. Print the valued delivery slip: + - The total amount will now be correct. + - The kit components will be summarized in a single kit product line. + +Known issues / Roadmap +====================== + +* Matching selled kits and their delivered components it's quite tricky. There + are two possible approaches to findout from the component how many units + correspond with every whole kit: + + - We could have a link to the original BoM line and guess it from it. This + approach is the one that Odoo has taken in v13 with the sale order line + deliveried quantities computation. The main issue is that if the original + BoM changes then we'd loose the correct units per kit reference. + + - Another aproach (the one in this module) is to compute the component units + per kit matching the sale order line and its related moves demands. But if + the user manually adjust the demand on one model without adjusting it in + the order we'll have an incorrect reference as well. + +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 `_: + + * David Vidal + +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/stock-logistics-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_report_valued_sale_mrp/__init__.py b/stock_picking_report_valued_sale_mrp/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_report_valued_sale_mrp/__manifest__.py b/stock_picking_report_valued_sale_mrp/__manifest__.py new file mode 100644 index 0000000..af7fe8d --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Valued picking linked with MRP Kits", + "summary": "Allow to summarize the picking related with the selled kits", + "version": "13.0.1.0.0", + "development_status": "Beta", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-reporting", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["chienandalu"], + "license": "AGPL-3", + "depends": ["stock_picking_report_valued", "sale_mrp"], + "data": ["report/stock_picking_report_valued.xml"], +} diff --git a/stock_picking_report_valued_sale_mrp/i18n/stock_picking_report_valued_sale_mrp.pot b/stock_picking_report_valued_sale_mrp/i18n/stock_picking_report_valued_sale_mrp.pot new file mode 100644 index 0000000..8d1607f --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/i18n/stock_picking_report_valued_sale_mrp.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_report_valued_sale_mrp +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: stock_picking_report_valued_sale_mrp +#: model:ir.model.fields,field_description:stock_picking_report_valued_sale_mrp.field_stock_move_line__phantom_delivered_qty +msgid "Phantom Delivered Qty" +msgstr "" + +#. module: stock_picking_report_valued_sale_mrp +#: model:ir.model.fields,field_description:stock_picking_report_valued_sale_mrp.field_stock_move_line__phantom_line +msgid "Phantom Line" +msgstr "" + +#. module: stock_picking_report_valued_sale_mrp +#: model:ir.model.fields,field_description:stock_picking_report_valued_sale_mrp.field_stock_move_line__phantom_product_id +msgid "Product Kit" +msgstr "" + +#. module: stock_picking_report_valued_sale_mrp +#: model:ir.model,name:stock_picking_report_valued_sale_mrp.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_picking_report_valued_sale_mrp +#: model:ir.model,name:stock_picking_report_valued_sale_mrp.model_stock_move +msgid "Stock Move" +msgstr "" + diff --git a/stock_picking_report_valued_sale_mrp/models/__init__.py b/stock_picking_report_valued_sale_mrp/models/__init__.py new file mode 100644 index 0000000..f800274 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_move +from . import stock_move_line diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move.py b/stock_picking_report_valued_sale_mrp/models/stock_move.py new file mode 100644 index 0000000..4b459b1 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/models/stock_move.py @@ -0,0 +1,28 @@ +# Copyright 2020 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _get_components_per_kit(self): + """Compute how many kit components were demanded from this line. We + rely on the matching of sale order and pickings demands, but if those + were manually changed, it could lead to inconsistencies""" + self.ensure_one() + sale_line = self.sale_line_id + if ( + not sale_line + or not sale_line.product_id.get_components() + or sale_line.product_id.ids == sale_line.product_id.get_components() + ): + return 0 + component_demand = sum( + sale_line.move_ids.filtered( + lambda x: x.product_id == self.product_id + and not x.origin_returned_move_id + and (x.state != "cancel" or (x.state == "cancel" and x.backorder_id)) + ).mapped("product_uom_qty") + ) + return component_demand / sale_line.product_uom_qty diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move_line.py b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py new file mode 100644 index 0000000..67278c4 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py @@ -0,0 +1,102 @@ +# Copyright 2020 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + phantom_product_id = fields.Many2one( + comodel_name="product.product", + compute="_compute_phantom_product_id", + compute_sudo=True, + string="Product Kit", + readonly=True, + ) + phantom_line = fields.Boolean( + compute="_compute_sale_order_line_fields", compute_sudo=True, + ) + phantom_delivered_qty = fields.Float( + compute="_compute_sale_order_line_fields", compute_sudo=True, + ) + + @api.depends("sale_line") + def _compute_phantom_product_id(self): + """Relate every line with its kit product""" + self.write({"phantom_product_id": False}) + for line in self.filtered( + lambda x: x.sale_line + and x.sale_line.product_id.get_components() + and x.sale_line.product_id.ids != x.sale_line.product_id.get_components() + ): + line.phantom_product_id = line.sale_line.product_id + + def _compute_sale_order_line_fields(self): + """For kits we only want to store the value in one of the move lines to + avoid duplicate the amounts. We also need to recompute the total + amounts according to the corresponding delivered kits""" + super()._compute_sale_order_line_fields() + pickings = self.mapped("picking_id") + kit_lines = pickings.move_line_ids.filtered("phantom_product_id") + pickings.move_line_ids.write( + {"phantom_line": False, "phantom_delivered_qty": 0.0} + ) + for sale_line in kit_lines.mapped("sale_line"): + move_lines = kit_lines.filtered(lambda x: x.sale_line == sale_line) + # Deduct the kit quantity from the first component in the picking. + # If the the kit is partially delivered, this could lead to an + # unacurate value. + phantom_line = move_lines[:1] + if not phantom_line: + continue + price_unit = ( + sale_line.price_subtotal / sale_line.product_uom_qty + if sale_line.product_uom_qty + else sale_line.price_reduce + ) + # Compute how many kits were delivered from the components and + # the original demand. Note that if the qty is edited in the sale + # order this could lead to inconsitencies. + components_per_kit = phantom_line.move_id._get_components_per_kit() + phantom_line_qty_done = sum( + move_lines.filtered( + lambda x: x.product_id == phantom_line.product_id + ).mapped("qty_done") + ) + quantity = phantom_line_qty_done / components_per_kit + taxes = phantom_line.sale_tax_id.compute_all( + price_unit=price_unit, + currency=phantom_line.currency_id, + quantity=quantity, + product=phantom_line.product_id, + partner=sale_line.order_id.partner_shipping_id, + ) + if sale_line.company_id.tax_calculation_rounding_method == ( + "round_globally" + ): + price_tax = sum(t.get("amount", 0.0) for t in taxes.get("taxes", [])) + else: + price_tax = taxes["total_included"] - taxes["total_excluded"] + phantom_line.update( + { + "sale_tax_description": ", ".join( + t.name or t.description for t in phantom_line.sale_tax_id + ), + "sale_price_subtotal": taxes["total_excluded"], + "sale_price_tax": price_tax, + "sale_price_total": taxes["total_included"], + "phantom_line": True, + "phantom_delivered_qty": quantity, + } + ) + # Remove the other lines + redundant_lines = move_lines[1:] + if redundant_lines: + redundant_lines.update( + { + "sale_tax_description": "", + "sale_price_subtotal": 0, + "sale_price_tax": 0, + "sale_price_total": 0, + } + ) diff --git a/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst b/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..1bed2df --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * David Vidal + * Carlos Roca diff --git a/stock_picking_report_valued_sale_mrp/readme/DESCRIPTION.rst b/stock_picking_report_valued_sale_mrp/readme/DESCRIPTION.rst new file mode 100644 index 0000000..2f89d7d --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module extends the functionality of `stock_picking_report_valued` with +compatibility of MRP kits. Now we'll be able to correctly summarize the picking +value related to the selled kit with a relations of components and serials/lots +delivered. diff --git a/stock_picking_report_valued_sale_mrp/readme/ROADMAP.rst b/stock_picking_report_valued_sale_mrp/readme/ROADMAP.rst new file mode 100644 index 0000000..ff53ca0 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/readme/ROADMAP.rst @@ -0,0 +1,13 @@ +* Matching selled kits and their delivered components it's quite tricky. There + are two possible approaches to findout from the component how many units + correspond with every whole kit: + + - We could have a link to the original BoM line and guess it from it. This + approach is the one that Odoo has taken in v13 with the sale order line + deliveried quantities computation. The main issue is that if the original + BoM changes then we'd loose the correct units per kit reference. + + - Another aproach (the one in this module) is to compute the component units + per kit matching the sale order line and its related moves demands. But if + the user manually adjust the demand on one model without adjusting it in + the order we'll have an incorrect reference as well. diff --git a/stock_picking_report_valued_sale_mrp/readme/USAGE.rst b/stock_picking_report_valued_sale_mrp/readme/USAGE.rst new file mode 100644 index 0000000..53cec3f --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/readme/USAGE.rst @@ -0,0 +1,7 @@ +To test this module: + +#. Configure some products with traceability and make them kit components. +#. Sell the kits and go to the stock picking. +#. Print the valued delivery slip: + - The total amount will now be correct. + - The kit components will be summarized in a single kit product line. diff --git a/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml new file mode 100644 index 0000000..60ecdc5 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml @@ -0,0 +1,82 @@ + + + + + + diff --git a/stock_picking_report_valued_sale_mrp/static/description/icon.png b/stock_picking_report_valued_sale_mrp/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/stock_picking_report_valued_sale_mrp/static/description/icon.png differ diff --git a/stock_picking_report_valued_sale_mrp/static/description/index.html b/stock_picking_report_valued_sale_mrp/static/description/index.html new file mode 100644 index 0000000..e02c1ee --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/static/description/index.html @@ -0,0 +1,458 @@ + + + + + + +Valued picking linked with MRP Kits + + + +
+

Valued picking linked with MRP Kits

+ + +

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

+

This module extends the functionality of stock_picking_report_valued with +compatibility of MRP kits. Now we’ll be able to correctly summarize the picking +value related to the selled kit with a relations of components and serials/lots +delivered.

+

Table of contents

+ +
+

Usage

+

To test this module:

+
    +
  1. Configure some products with traceability and make them kit components.
  2. +
  3. Sell the kits and go to the stock picking.
  4. +
  5. Print the valued delivery slip: +- The total amount will now be correct. +- The kit components will be summarized in a single kit product line.
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • Matching selled kits and their delivered components it’s quite tricky. There +are two possible approaches to findout from the component how many units +correspond with every whole kit:
      +
    • We could have a link to the original BoM line and guess it from it. This +approach is the one that Odoo has taken in v13 with the sale order line +deliveried quantities computation. The main issue is that if the original +BoM changes then we’d loose the correct units per kit reference.
    • +
    • Another aproach (the one in this module) is to compute the component units +per kit matching the sale order line and its related moves demands. But if +the user manually adjust the demand on one model without adjusting it in +the order we’ll have an incorrect reference as well.
    • +
    +
  • +
+
+
+

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

+ +
+
+

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/stock-logistics-reporting project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_picking_report_valued_sale_mrp/tests/__init__.py b/stock_picking_report_valued_sale_mrp/tests/__init__.py new file mode 100644 index 0000000..bb8c419 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_picking_report_valued_mrp diff --git a/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py b/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py new file mode 100644 index 0000000..2b13685 --- /dev/null +++ b/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py @@ -0,0 +1,75 @@ +# Copyright 2020 Tecnativa - David Vidal +from odoo.tests import Form + +from odoo.addons.stock_picking_report_valued.tests.test_stock_picking_valued import ( + TestStockPickingValued, +) + + +class TestStockPickingValuedMrp(TestStockPickingValued): + @classmethod + def setUpClass(cls): + """We want to run parent class tests again to ensure everything + works as expected even if no kits are present""" + super().setUpClass() + cls.res_partner = cls.env["res.partner"] + cls.product_product = cls.env["product.product"] + cls.product_kit = cls.product_product.create( + {"name": "Product test 1", "type": "consu"} + ) + cls.product_kit_comp_1 = cls.product_product.create( + {"name": "Product Component 1", "type": "product"} + ) + cls.product_kit_comp_2 = cls.product_product.create( + {"name": "Product Component 2", "type": "product"} + ) + cls.bom = cls.env["mrp.bom"].create( + { + "product_id": cls.product_kit.id, + "product_tmpl_id": cls.product_kit.product_tmpl_id.id, + "type": "phantom", + "bom_line_ids": [ + ( + 0, + 0, + {"product_id": cls.product_kit_comp_1.id, "product_qty": 2}, + ), + ( + 0, + 0, + {"product_id": cls.product_kit_comp_2.id, "product_qty": 4}, + ), + ], + } + ) + cls.product_2 = cls.product_product.create( + {"name": "Product test 2", "type": "product"} + ) + order_form = Form(cls.env["sale.order"]) + order_form.partner_id = cls.partner + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product_kit + line_form.product_uom_qty = 5 + line_form.price_unit = 29.9 + line_form.tax_id.clear() + line_form.tax_id.add(cls.tax10) + cls.sale_order_3 = order_form.save() + cls.sale_order_3.action_confirm() + # Maybe other modules create additional lines in the create + # method in sale.order model, so let's find the correct line. + cls.order_line = cls.sale_order_3.order_line.filtered( + lambda r: r.product_id == cls.product_kit + ) + cls.order_out_picking = cls.sale_order_3.picking_ids + + def test_01_picking_confirmed(self): + for line in self.order_out_picking.move_lines: + line.quantity_done = line.product_uom_qty + self.order_out_picking.button_validate() + self.assertAlmostEqual(self.order_out_picking.amount_untaxed, 149.5) + self.assertAlmostEqual(self.order_out_picking.amount_tax, 14.95) + self.assertAlmostEqual(self.order_out_picking.amount_total, 164.45) + # Run the report to detect hidden errors + self.env.ref("stock.action_report_delivery").render_qweb_html( + self.order_out_picking.ids + )