diff --git a/mrp_subcontracting_purchase_link/README.rst b/mrp_subcontracting_purchase_link/README.rst new file mode 100644 index 00000000000..d305181010f --- /dev/null +++ b/mrp_subcontracting_purchase_link/README.rst @@ -0,0 +1,88 @@ +=================================================== +Link Purchase Order Line to Subcontract Productions +=================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:074986a18935844303cc29216277c6fd630f383750f4ef24800ab0cf07c6a4c3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/14.0/mrp_subcontracting_purchase_link + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_subcontracting_purchase_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/manufacture&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module does the following: + +- Extends _prepare_subcontract_mo_vals() and adds the purchase order line reference to the subcontracted manufacturing orders. +- Adds an action button in the purchase order form view to open related subcontracted manufacturing orders. + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `Quartile Limited `__: + + * Yoshi Tashiro + * Tim Lai + +* `ForgeFlow `__: + + * Thiago Mulero + * Jordi Ballester + +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/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_subcontracting_purchase_link/__init__.py b/mrp_subcontracting_purchase_link/__init__.py new file mode 100644 index 00000000000..cc6b6354ad8 --- /dev/null +++ b/mrp_subcontracting_purchase_link/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/mrp_subcontracting_purchase_link/__manifest__.py b/mrp_subcontracting_purchase_link/__manifest__.py new file mode 100644 index 00000000000..fe9aa6e1220 --- /dev/null +++ b/mrp_subcontracting_purchase_link/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": "Link Purchase Order Line to Subcontract Productions", + "version": "15.0.1.0.0", + "category": "Manufacturing", + "license": "LGPL-3", + "author": "Quartile Limited, ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "depends": ["mrp_subcontracting_purchase"], + "data": ["views/purchase_order_views.xml", "views/mrp_production_views.xml"], + "post_init_hook": "post_init_hook", + "installable": True, +} diff --git a/mrp_subcontracting_purchase_link/hooks.py b/mrp_subcontracting_purchase_link/hooks.py new file mode 100644 index 00000000000..e1a1394f40e --- /dev/null +++ b/mrp_subcontracting_purchase_link/hooks.py @@ -0,0 +1,39 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +import logging + +_logger = logging.getLogger(__name__) + + +def update_po_line_in_mrp_production(cr): + """ """ + _logger.info("Updating PO line in MRP production") + cr.execute( + """ + UPDATE mrp_production + SET + purchase_line_id = Q.purchase_line_id, + purchase_order_id = Q.purchase_id + FROM ( + SELECT po_sm.purchase_line_id, mo_sm.production_id, po.id as purchase_id + FROM stock_move as po_sm + INNER JOIN stock_move_move_rel as rel + ON rel.move_dest_id = po_sm.id + INNER JOIN stock_move as mo_sm + ON mo_sm.id = rel.move_orig_id + INNER JOIN purchase_order_line as pol + ON pol.id = po_sm.purchase_line_id + INNER JOIN purchase_order as po + ON po.id = pol.order_id + where po_sm.is_subcontract = true + AND po_sm.purchase_line_id is not null + AND mo_sm.production_id is not null + ) AS Q + WHERE mrp_production.id = Q.production_id + """ + ) + + +def post_init_hook(cr, registry): + update_po_line_in_mrp_production(cr) diff --git a/mrp_subcontracting_purchase_link/i18n/es.po b/mrp_subcontracting_purchase_link/i18n/es.po new file mode 100644 index 00000000000..c7796ade59d --- /dev/null +++ b/mrp_subcontracting_purchase_link/i18n/es.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-23 00:01+0000\n" +"Last-Translator: Ivorra78 \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 4.17\n" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__id +msgid "ID" +msgstr "ID" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_mrp_production +msgid "Production Order" +msgstr "Orden de Producción" + +#. module: mrp_subcontracting_purchase_link +#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_purchase_link.purchase_order_form +msgid "Productions" +msgstr "Producciones" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_purchase_order +msgid "Purchase Order" +msgstr "Orden de Compra" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_count +msgid "Subcontract Production Count" +msgstr "Recuento de la Producción Subcontratada" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_ids +msgid "Subcontract Production Orders" +msgstr "Órdenes de Fabricación de Subcontratas" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_order_id +msgid "Subcontract Purchase Order" +msgstr "Orden de Compra de Subcontratación" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_line_id +msgid "Subcontract Purchase Order Line" +msgstr "Línea de Orden de Compra de Subcontratación" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_stock_picking +msgid "Transfer" +msgstr "Transferencia" diff --git a/mrp_subcontracting_purchase_link/i18n/it.po b/mrp_subcontracting_purchase_link/i18n/it.po new file mode 100644 index 00000000000..c32b496e9b3 --- /dev/null +++ b/mrp_subcontracting_purchase_link/i18n/it.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-03-08 22:23+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\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.14.1\n" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__id +msgid "ID" +msgstr "ID" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_mrp_production +msgid "Production Order" +msgstr "Ordine di produzione" + +#. module: mrp_subcontracting_purchase_link +#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_purchase_link.purchase_order_form +msgid "Productions" +msgstr "Produzioni" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_purchase_order +msgid "Purchase Order" +msgstr "Ordine di acquisto" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_count +msgid "Subcontract Production Count" +msgstr "Conteggio produzione terzisti" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_ids +msgid "Subcontract Production Orders" +msgstr "Ordini produzione terzisti" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_order_id +msgid "Subcontract Purchase Order" +msgstr "Ordine produzione terzisti" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_line_id +msgid "Subcontract Purchase Order Line" +msgstr "Riga ordine acquisto terzista" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_stock_picking +msgid "Transfer" +msgstr "Trasferimento" diff --git a/mrp_subcontracting_purchase_link/i18n/ja.po b/mrp_subcontracting_purchase_link/i18n/ja.po new file mode 100644 index 00000000000..977f9d9eae6 --- /dev/null +++ b/mrp_subcontracting_purchase_link/i18n/ja.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-10-13 08:00+0000\n" +"PO-Revision-Date: 2020-10-13 08:00+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__id +msgid "ID" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_mrp_production +msgid "Production Order" +msgstr "製造" + +#. module: mrp_subcontracting_purchase_link +#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_purchase_link.purchase_order_form +msgid "Productions" +msgstr "製造" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_purchase_order +msgid "Purchase Order" +msgstr "購買オーダ" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_count +msgid "Subcontract Production Count" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_ids +msgid "Subcontract Production Orders" +msgstr "製造" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_order_id +msgid "Subcontract Purchase Order" +msgstr "外注加工購買オーダ" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_line_id +msgid "Subcontract Purchase Order Line" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_stock_picking +msgid "Transfer" +msgstr "運送" diff --git a/mrp_subcontracting_purchase_link/i18n/mrp_subcontracting_purchase_link.pot b/mrp_subcontracting_purchase_link/i18n/mrp_subcontracting_purchase_link.pot new file mode 100644 index 00000000000..8dbfce0db94 --- /dev/null +++ b/mrp_subcontracting_purchase_link/i18n/mrp_subcontracting_purchase_link.pot @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__id +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking__id +msgid "ID" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_stock_picking____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_purchase_link.purchase_order_form +msgid "Productions" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_count +msgid "Subcontract Production Count" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_purchase_order__subcontract_production_ids +msgid "Subcontract Production Orders" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_order_id +msgid "Subcontract Purchase Order" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model.fields,field_description:mrp_subcontracting_purchase_link.field_mrp_production__purchase_line_id +msgid "Subcontract Purchase Order Line" +msgstr "" + +#. module: mrp_subcontracting_purchase_link +#: model:ir.model,name:mrp_subcontracting_purchase_link.model_stock_picking +msgid "Transfer" +msgstr "" diff --git a/mrp_subcontracting_purchase_link/models/__init__.py b/mrp_subcontracting_purchase_link/models/__init__.py new file mode 100644 index 00000000000..5a805a40f5e --- /dev/null +++ b/mrp_subcontracting_purchase_link/models/__init__.py @@ -0,0 +1,3 @@ +from . import mrp_production +from . import purchase_order +from . import stock_picking diff --git a/mrp_subcontracting_purchase_link/models/mrp_production.py b/mrp_subcontracting_purchase_link/models/mrp_production.py new file mode 100644 index 00000000000..7b7be5851af --- /dev/null +++ b/mrp_subcontracting_purchase_link/models/mrp_production.py @@ -0,0 +1,20 @@ +# Copyright 2020 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + purchase_order_id = fields.Many2one( + "purchase.order", + "Subcontract Purchase Order", + readonly=True, + related="purchase_line_id.order_id", + store=True, + ) + + purchase_line_id = fields.Many2one( + "purchase.order.line", "Subcontract Purchase Order Line", readonly=True + ) diff --git a/mrp_subcontracting_purchase_link/models/purchase_order.py b/mrp_subcontracting_purchase_link/models/purchase_order.py new file mode 100644 index 00000000000..f3ff3c41f93 --- /dev/null +++ b/mrp_subcontracting_purchase_link/models/purchase_order.py @@ -0,0 +1,38 @@ +# Copyright 2020 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + subcontract_production_count = fields.Integer( + compute="_compute_subcontract_production_count" + ) + + subcontract_production_ids = fields.One2many( + "mrp.production", + "purchase_order_id", + "Subcontract Production Orders", + readonly=True, + ) + + def action_view_mrp(self): + productions = self.subcontract_production_ids + xmlid = "mrp.mrp_production_action" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + if len(productions) > 1: + action["domain"] = [("id", "in", productions.ids)] + elif len(productions) == 1: + action["views"] = [ + (self.env.ref("mrp.mrp_production_form_view").id, "form") + ] + action["res_id"] = productions.ids[0] + else: + action = {"type": "ir.actions.act_window_close"} + return action + + def _compute_subcontract_production_count(self): + for order in self: + order.subcontract_production_count = len(order.subcontract_production_ids) diff --git a/mrp_subcontracting_purchase_link/models/stock_picking.py b/mrp_subcontracting_purchase_link/models/stock_picking.py new file mode 100644 index 00000000000..46c3738ed86 --- /dev/null +++ b/mrp_subcontracting_purchase_link/models/stock_picking.py @@ -0,0 +1,14 @@ +# Copyright 2020 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _prepare_subcontract_mo_vals(self, subcontract_move, bom): + vals = super()._prepare_subcontract_mo_vals(subcontract_move, bom) + if subcontract_move.purchase_line_id: + vals["purchase_line_id"] = subcontract_move.purchase_line_id.id + return vals diff --git a/mrp_subcontracting_purchase_link/readme/CONTRIBUTORS.rst b/mrp_subcontracting_purchase_link/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..5de285c7425 --- /dev/null +++ b/mrp_subcontracting_purchase_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,9 @@ +* `Quartile Limited `__: + + * Yoshi Tashiro + * Tim Lai + +* `ForgeFlow `__: + + * Thiago Mulero + * Jordi Ballester diff --git a/mrp_subcontracting_purchase_link/readme/DESCRIPTION.rst b/mrp_subcontracting_purchase_link/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..8e40f40d075 --- /dev/null +++ b/mrp_subcontracting_purchase_link/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module does the following: + +- Extends _prepare_subcontract_mo_vals() and adds the purchase order line reference to the subcontracted manufacturing orders. +- Adds an action button in the purchase order form view to open related subcontracted manufacturing orders. diff --git a/mrp_subcontracting_purchase_link/static/description/icon.png b/mrp_subcontracting_purchase_link/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/mrp_subcontracting_purchase_link/static/description/icon.png differ diff --git a/mrp_subcontracting_purchase_link/static/description/index.html b/mrp_subcontracting_purchase_link/static/description/index.html new file mode 100644 index 00000000000..42d15b22756 --- /dev/null +++ b/mrp_subcontracting_purchase_link/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Link Purchase Order Line to Subcontract Productions + + + + + + diff --git a/mrp_subcontracting_purchase_link/tests/__init__.py b/mrp_subcontracting_purchase_link/tests/__init__.py new file mode 100644 index 00000000000..34dc8cc6e2c --- /dev/null +++ b/mrp_subcontracting_purchase_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_subcontracting_purchase_link diff --git a/mrp_subcontracting_purchase_link/tests/test_mrp_subcontracting_purchase_link.py b/mrp_subcontracting_purchase_link/tests/test_mrp_subcontracting_purchase_link.py new file mode 100644 index 00000000000..ea2929a4cd1 --- /dev/null +++ b/mrp_subcontracting_purchase_link/tests/test_mrp_subcontracting_purchase_link.py @@ -0,0 +1,72 @@ +# Copyright 2020 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields +from odoo.tests import tagged + +from ...mrp_subcontracting.tests.common import TestMrpSubcontractingCommon + + +@tagged("post_install", "-at_install") +class TestMrpSubcontractingPurchaseLink(TestMrpSubcontractingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def _create_sub_po(self, products): + po = self.env["purchase.order"].create( + { + "partner_id": self.subcontractor_partner1.id, + "order_line": [ + ( + 0, + 0, + { + "name": product.name, + "product_id": product.id, + "product_qty": 5.0, + "product_uom": product.uom_id.id, + "price_unit": 10, + "date_planned": fields.Datetime.now(), + }, + ) + for product in products + ], + } + ) + po.button_confirm() + return po + + def test_01_prepare_subcontract_mo_vals(self): + purchase_order = self._create_sub_po(self.finished) + for picking in purchase_order.picking_ids: + for move in picking.move_lines: + self.assertEqual( + picking._prepare_subcontract_mo_vals( + move, move._get_subcontract_bom() + )["purchase_line_id"], + purchase_order.order_line.id, + ) + + def test_02_compute_subcontract_production_count(self): + purchase_order1 = self._create_sub_po(self.finished) + purchase_order2 = self._create_sub_po(self.finished + self.finished) + self.assertEqual(purchase_order1.subcontract_production_count, 1) + self.assertEqual(purchase_order2.subcontract_production_count, 2) + + def test_03_action_view_mrp(self): + purchase_order1 = self._create_sub_po(self.finished) + purchase_order2 = self._create_sub_po(self.finished + self.finished) + action = purchase_order1.action_view_mrp() + self.assertEqual( + action["views"], [(self.env.ref("mrp.mrp_production_form_view").id, "form")] + ) + self.assertEqual( + action["res_id"], + purchase_order1.subcontract_production_ids[0].id, + ) + action = purchase_order2.action_view_mrp() + self.assertEqual( + action["domain"], + [("id", "in", purchase_order2.subcontract_production_ids.ids)], + ) diff --git a/mrp_subcontracting_purchase_link/views/mrp_production_views.xml b/mrp_subcontracting_purchase_link/views/mrp_production_views.xml new file mode 100644 index 00000000000..04467c1b1c1 --- /dev/null +++ b/mrp_subcontracting_purchase_link/views/mrp_production_views.xml @@ -0,0 +1,14 @@ + + + + mrp.production.form + mrp.production + + + + + + + + + diff --git a/mrp_subcontracting_purchase_link/views/purchase_order_views.xml b/mrp_subcontracting_purchase_link/views/purchase_order_views.xml new file mode 100644 index 00000000000..dc52596e294 --- /dev/null +++ b/mrp_subcontracting_purchase_link/views/purchase_order_views.xml @@ -0,0 +1,27 @@ + + + + purchase.order.form + purchase.order + + + + + + + + diff --git a/setup/mrp_subcontracting_purchase_link/odoo/addons/mrp_subcontracting_purchase_link b/setup/mrp_subcontracting_purchase_link/odoo/addons/mrp_subcontracting_purchase_link new file mode 120000 index 00000000000..41f80b1ef87 --- /dev/null +++ b/setup/mrp_subcontracting_purchase_link/odoo/addons/mrp_subcontracting_purchase_link @@ -0,0 +1 @@ +../../../../mrp_subcontracting_purchase_link \ No newline at end of file diff --git a/setup/mrp_subcontracting_purchase_link/setup.py b/setup/mrp_subcontracting_purchase_link/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/mrp_subcontracting_purchase_link/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)