diff --git a/sale_mrp_link/README.rst b/sale_mrp_link/README.rst new file mode 100644 index 00000000000..9ba89bff573 --- /dev/null +++ b/sale_mrp_link/README.rst @@ -0,0 +1,96 @@ +============= +Sale MRP Link +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a8cc9864cfee0edae03c514fe82e41ccaa1edd29e79d464fc65092979937cf35 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/18.0/sale_mrp_link + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_mrp_link + :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/sale-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a link between the manufacturing orders and the +associated sale order. A button shown in the form view of sale orders +allow the user to access to the related manufacturing orders. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +The module is incompatible with the following modules: + +- `sale_sourced_by_line `__ +- `sale_stock_picking_blocking_proc_group_by_line `__ +- `sale_delivery_split_date `__ +- `sale_quotation_sourcing `__ + (please note this latter is not migrated yet). + +Please see +https://github.com/OCA/sale-workflow/pull/661#discussion_r214031110 for +further info. + +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 +------- + +* Akretion +* Agile Business Group + +Contributors +------------ + +- Florian da Costa +- Alex Comba +- Juan Humanes + +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. + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_mrp_link/__init__.py b/sale_mrp_link/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_mrp_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_mrp_link/__manifest__.py b/sale_mrp_link/__manifest__.py new file mode 100644 index 00000000000..ad99109c62c --- /dev/null +++ b/sale_mrp_link/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2018 Alex Comba - Agile Business Group +# Copyright 2016-2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Sale MRP Link", + "summary": "Show manufacturing orders generated from sales order", + "version": "18.0.1.0.0", + "development_status": "Production/Stable", + "category": "Sales Management", + "website": "https://github.com/OCA/sale-workflow", + "author": "Akretion, Agile Business Group, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "sale_mrp", + ], + "data": [ + "views/mrp_production.xml", + "views/sale_order.xml", + ], +} diff --git a/sale_mrp_link/i18n/ca.po b/sale_mrp_link/i18n/ca.po new file mode 100644 index 00000000000..6349280ea1a --- /dev/null +++ b/sale_mrp_link/i18n/ca.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-19 17:46+0000\n" +"Last-Translator: Daniel Martinez Vila \n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "Producció" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +msgid "Production Count" +msgstr "Recompte de producció" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +msgid "Production Order" +msgstr "Comanda de producció" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +msgid "Sale Order" +msgstr "Comanda de venda" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "Comanda de venda d'origen" diff --git a/sale_mrp_link/i18n/es.po b/sale_mrp_link/i18n/es.po new file mode 100644 index 00000000000..319540268f5 --- /dev/null +++ b/sale_mrp_link/i18n/es.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-11-23 15:36+0000\n" +"Last-Translator: Jesús Vargas \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "Producción" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +msgid "Production Count" +msgstr "Número de órdenes de producción" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +msgid "Production Order" +msgstr "Orden de producción" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +msgid "Sale Order" +msgstr "Pedido de venta" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "Pedido de venta de origen" diff --git a/sale_mrp_link/i18n/fr.po b/sale_mrp_link/i18n/fr.po new file mode 100644 index 00000000000..3e196429c46 --- /dev/null +++ b/sale_mrp_link/i18n/fr.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-10-01 10:00+0000\n" +"Last-Translator: Yann Papouin \n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "Fabrication" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +msgid "Production Count" +msgstr "Nombre de fabrication" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +msgid "Production Order" +msgstr "Odre de fabrication" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +msgid "Sale Order" +msgstr "Commande client" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "Commande client d'origine" diff --git a/sale_mrp_link/i18n/it.po b/sale_mrp_link/i18n/it.po new file mode 100644 index 00000000000..a5b24859298 --- /dev/null +++ b/sale_mrp_link/i18n/it.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-06-18 15:35+0000\n" +"PO-Revision-Date: 2018-06-18 17:38+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.8.7.1\n" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "Produzione" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +#, fuzzy +msgid "Production Count" +msgstr "Numero ordini di produzione" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +#, fuzzy +msgid "Production Order" +msgstr "Produzione" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +#, fuzzy +msgid "Sale Order" +msgstr "Ordine di vendita" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "SO Origine" + +#~ msgid "Manufacturing Order" +#~ msgstr "Ordine di produzione" + +#~ msgid "More than 1 sale order found for this group" +#~ msgstr "Trovato più di un ordine di vendita per questo gruppo" + +#~ msgid "Procurement" +#~ msgstr "Approvvigionamento" diff --git a/sale_mrp_link/i18n/sale_mrp_link.pot b/sale_mrp_link/i18n/sale_mrp_link.pot new file mode 100644 index 00000000000..afde389f167 --- /dev/null +++ b/sale_mrp_link/i18n/sale_mrp_link.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +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: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +msgid "Production Count" +msgstr "" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +msgid "Sale Order" +msgstr "" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "" + diff --git a/sale_mrp_link/i18n/tr.po b/sale_mrp_link/i18n/tr.po new file mode 100644 index 00000000000..eec0493e25c --- /dev/null +++ b/sale_mrp_link/i18n/tr.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_mrp_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-01-06 10:39+0000\n" +"Last-Translator: Yavuz Avci \n" +"Language-Team: none\n" +"Language: tr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_ids +#: model_terms:ir.ui.view,arch_db:sale_mrp_link.view_order_form +msgid "Production" +msgstr "Üretim" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_sale_order__production_count +msgid "Production Count" +msgstr "Üretim Miktarı" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_mrp_production +msgid "Production Order" +msgstr "Üretim Emri" + +#. module: sale_mrp_link +#: model:ir.model,name:sale_mrp_link.model_sale_order +msgid "Sale Order" +msgstr "Satış Siparişi" + +#. module: sale_mrp_link +#: model:ir.model.fields,field_description:sale_mrp_link.field_mrp_production__sale_order_id +msgid "Source Sale Order" +msgstr "Kaynak Satış Siparişi" diff --git a/sale_mrp_link/models/__init__.py b/sale_mrp_link/models/__init__.py new file mode 100644 index 00000000000..8eea5cb86a9 --- /dev/null +++ b/sale_mrp_link/models/__init__.py @@ -0,0 +1,2 @@ +from . import mrp_production +from . import sale_order diff --git a/sale_mrp_link/models/mrp_production.py b/sale_mrp_link/models/mrp_production.py new file mode 100644 index 00000000000..270db5d62d8 --- /dev/null +++ b/sale_mrp_link/models/mrp_production.py @@ -0,0 +1,37 @@ +# Copyright 2018 Alex Comba - Agile Business Group +# Copyright 2016-2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + sale_order_id = fields.Many2one( + comodel_name="sale.order", string="Source Sale Order" + ) + + @api.model_create_multi + def create(self, vals_list): + for values in vals_list: + if "origin" in values: + # Checking first if this comes from a 'sale.order' + sale_id = self.env["sale.order"].browse(values.get("sale_order_id")) + if not sale_id: + sale_id = self.env["sale.order"].search( + [("name", "=", values["origin"])], limit=1 + ) + if sale_id: + values["sale_order_id"] = sale_id.id + if sale_id.client_order_ref: + values["origin"] = sale_id.client_order_ref + else: + # Checking if this production comes from a route + production_id = self.env["mrp.production"].search( + [("name", "=", values["origin"])] + ) + # If so, use the 'sale_order_id' from the parent production + values["sale_order_id"] = production_id.sale_order_id.id + + return super().create(vals_list) diff --git a/sale_mrp_link/models/sale_order.py b/sale_mrp_link/models/sale_order.py new file mode 100644 index 00000000000..11155dcb63b --- /dev/null +++ b/sale_mrp_link/models/sale_order.py @@ -0,0 +1,27 @@ +# Copyright 2018 Alex Comba - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + production_ids = fields.One2many("mrp.production", "sale_order_id") + production_count = fields.Integer(compute="_compute_production_count", store=True) + + @api.depends("production_ids") + def _compute_production_count(self): + for sale in self: + sale.production_count = len(sale.production_ids) + + def action_view_production(self): + action = self.env.ref("mrp.mrp_production_action").read()[0] + if self.production_count > 1: + action["domain"] = [("id", "in", self.production_ids.ids)] + else: + action["views"] = [ + (self.env.ref("mrp.mrp_production_form_view").id, "form") + ] + action["res_id"] = self.production_ids.id + return action diff --git a/sale_mrp_link/pyproject.toml b/sale_mrp_link/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_mrp_link/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_mrp_link/readme/CONTRIBUTORS.md b/sale_mrp_link/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..f03d1ec553d --- /dev/null +++ b/sale_mrp_link/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Florian da Costa \ +- Alex Comba \ +- Juan Humanes \ diff --git a/sale_mrp_link/readme/DESCRIPTION.md b/sale_mrp_link/readme/DESCRIPTION.md new file mode 100644 index 00000000000..1f8f2a72229 --- /dev/null +++ b/sale_mrp_link/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module adds a link between the manufacturing orders and the +associated sale order. A button shown in the form view of sale orders +allow the user to access to the related manufacturing orders. diff --git a/sale_mrp_link/readme/ROADMAP.md b/sale_mrp_link/readme/ROADMAP.md new file mode 100644 index 00000000000..aaf593eaea2 --- /dev/null +++ b/sale_mrp_link/readme/ROADMAP.md @@ -0,0 +1,11 @@ +The module is incompatible with the following modules: + +- [sale_sourced_by_line](https://github.com/OCA/sale-workflow/tree/10.0/sale_sourced_by_line) +- [sale_stock_picking_blocking_proc_group_by_line](https://github.com/OCA/sale-workflow/tree/10.0/sale_stock_picking_blocking_proc_group_by_line) +- [sale_delivery_split_date](https://github.com/OCA/sale-workflow/tree/10.0/sale_delivery_split_date) +- [sale_quotation_sourcing](https://github.com/OCA/sale-workflow/blob/10.0/sale_quotation_sourcing) + (please note this latter is not migrated yet). + +Please see + +for further info. diff --git a/sale_mrp_link/static/description/icon.png b/sale_mrp_link/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_mrp_link/static/description/icon.png differ diff --git a/sale_mrp_link/static/description/index.html b/sale_mrp_link/static/description/index.html new file mode 100644 index 00000000000..6fa9e448f5f --- /dev/null +++ b/sale_mrp_link/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +Sale MRP Link + + + + + + diff --git a/sale_mrp_link/tests/__init__.py b/sale_mrp_link/tests/__init__.py new file mode 100644 index 00000000000..2da62b02a87 --- /dev/null +++ b/sale_mrp_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_sale_link diff --git a/sale_mrp_link/tests/test_mrp_sale_link.py b/sale_mrp_link/tests/test_mrp_sale_link.py new file mode 100644 index 00000000000..226ebc6dd21 --- /dev/null +++ b/sale_mrp_link/tests/test_mrp_sale_link.py @@ -0,0 +1,93 @@ +# Copyright 2018 Alex Comba - Agile Business Group +# Copyright 2016-2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command +from odoo.tests.common import TransactionCase + + +class TestSaleMrpLink(TransactionCase): + def setUp(self): + super().setUp() + self.partner = self.env.ref("base.res_partner_2") + self.warehouse = self.env.ref("stock.warehouse0") + route_manufacture = self.warehouse.manufacture_pull_id.route_id + route_mto = self.warehouse.mto_pull_id.route_id + route_mto.active = True + self.product_a = self._create_product( + "Product A", route_ids=[Command.set([route_manufacture.id, route_mto.id])] + ) + self.product_b = self._create_product( + "Product B", route_ids=[Command.set([route_manufacture.id, route_mto.id])] + ) + self.product_c = self._create_product("Product C", route_ids=[Command.clear()]) + self.product_d = self._create_product("Product D", route_ids=[Command.clear()]) + + def _create_bom(self, template): + return self.env["mrp.bom"].create( + {"product_tmpl_id": template.id, "type": "normal"} + ) + + def _create_bom_line(self, bom, product, qty): + self.env["mrp.bom.line"].create( + {"bom_id": bom.id, "product_id": product.id, "product_qty": qty} + ) + + def _create_product(self, name, route_ids): + return self.env["product.product"].create( + {"name": name, "type": "consu", "is_storable": True, "route_ids": route_ids} + ) + + def _create_sale_order(self, partner, client_ref): + return self.env["sale.order"].create( + {"partner_id": partner.id, "client_order_ref": client_ref} + ) + + def _create_sale_order_line(self, sale_order, product, qty, price): + self.env["sale.order.line"].create( + { + "order_id": sale_order.id, + "product_id": product.id, + "price_unit": price, + "product_uom_qty": qty, + } + ) + + def test_sale_to_only_one_mo(self): + """Check manufactured order is linked to the sale order.""" + bom = self._create_bom(self.product_a.product_tmpl_id) + self._create_bom_line(bom, self.product_c, 1) + so = self._create_sale_order(self.partner, "SO1") + self._create_sale_order_line(so, self.product_a, 1, 10.0) + so.action_confirm() + mo = self.env["mrp.production"].search([("sale_order_id", "=", so.id)]) + self.assertEqual(len(mo), 1) + action = so.action_view_production() + res_id = action["res_id"] + self.assertEqual(res_id, mo.id) + self.assertEqual(len(mo), so.production_count) + self.assertEqual(so.client_order_ref, mo.origin) + + def test_sale_to_several_mo(self): + """Check manufactured orders are linked to the sale order.""" + bom_b = self._create_bom(self.product_b.product_tmpl_id) + self._create_bom_line(bom_b, self.product_d, 1) + bom_a = self._create_bom(self.product_a.product_tmpl_id) + self._create_bom_line(bom_a, self.product_c, 1) + self._create_bom_line(bom_a, self.product_b, 1) + so = self._create_sale_order(self.partner, "SO2") + self._create_sale_order_line(so, self.product_a, 1, 10.0) + so.action_confirm() + mo = self.env["mrp.production"].search( + [("sale_order_id", "=", so.id)], + order="id asc", # To have a deterministic order + ) + self.assertEqual(len(mo), 2) + action = so.action_view_production() + mo_ids = action.get("domain")[0][2] + self.assertListEqual(mo.ids, mo_ids) + self.assertEqual(len(mo), so.production_count) + # The first MO will be the one that comes from the SO, the other one + # will have the first MO as its origin. + self.assertEqual(so.client_order_ref, mo[0].origin) + self.assertEqual(mo[1].origin, mo[0].name) diff --git a/sale_mrp_link/views/mrp_production.xml b/sale_mrp_link/views/mrp_production.xml new file mode 100644 index 00000000000..aec49e0b838 --- /dev/null +++ b/sale_mrp_link/views/mrp_production.xml @@ -0,0 +1,28 @@ + + + + + mrp.production + + + + + + + + + + mrp.production + + + + + + + + diff --git a/sale_mrp_link/views/sale_order.xml b/sale_mrp_link/views/sale_order.xml new file mode 100644 index 00000000000..9b0b224efed --- /dev/null +++ b/sale_mrp_link/views/sale_order.xml @@ -0,0 +1,28 @@ + + + + + sale.order.form + sale.order + + + + + + + +