diff --git a/account_move_line_mrp_info/README.rst b/account_move_line_mrp_info/README.rst new file mode 100644 index 000000000..eeaacf198 --- /dev/null +++ b/account_move_line_mrp_info/README.rst @@ -0,0 +1,87 @@ +========================== +Account Move Line Mrp Info +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:16dc4b397b258cadf401a8e7a1d5602329edf1025b208952ba257d5f1801a2cb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/15.0/account_move_line_mrp_info + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-account_move_line_mrp_info + :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=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the manufacturing orders and unbuild orders to the account move lines that it generates. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* The stock manager can check the journal items by accessing to 'Manufacturing > + Operations > Manufacturing Orders> Journal Items' and 'Manufacturing > + Operations > Unbuild Orders> Journal Items. + +* A user belonging to the group 'Show Full Accounting Features' can review the + details of a move that is associated to a journal item through + 'Invoicing > Accounting > Journal Entries (or Journal items)'. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Nuria Xifre Martin + +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/account_move_line_mrp_info/__init__.py b/account_move_line_mrp_info/__init__.py new file mode 100644 index 000000000..01aac13a6 --- /dev/null +++ b/account_move_line_mrp_info/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models +from .hooks import pre_init_hook diff --git a/account_move_line_mrp_info/__manifest__.py b/account_move_line_mrp_info/__manifest__.py new file mode 100644 index 000000000..0296ed3ab --- /dev/null +++ b/account_move_line_mrp_info/__manifest__.py @@ -0,0 +1,18 @@ +# © 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Account Move Line Mrp Info", + "version": "15.0.1.0.0", + "author": "ForgeFlow," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacture", + "depends": ["account_move_line_stock_info", "mrp"], + "installable": True, + "pre_init_hook": "pre_init_hook", + "license": "AGPL-3", + "data": [ + "security/ir.model.access.csv", + "views/account_move_line_view.xml", + "views/mrp_production_view.xml", + ], +} diff --git a/account_move_line_mrp_info/hooks.py b/account_move_line_mrp_info/hooks.py new file mode 100644 index 000000000..bcb4d1f15 --- /dev/null +++ b/account_move_line_mrp_info/hooks.py @@ -0,0 +1,51 @@ +import logging + +from psycopg2 import sql + + +def pre_init_hook(cr): + """Precreate move_type and fill with appropriate values to prevent + a MemoryError when the ORM attempts to call its compute method on a large + amount of preexisting moves. Note that the order of the mapping is + important as one move can have move lines on accounts of multiple types + and the move type is set in the order of precedence.""" + logger = logging.getLogger(__name__) + logger.info("Add mrp_info") + cr.execute( + "ALTER TABLE account_move_line ADD COLUMN IF NOT EXISTS mrp_production_id INTEGER" + ) + query = sql.SQL( + """ + with q2 as ( + select aml.id as account_move_id, + coalesce(sm.production_id,sm.raw_material_production_id) as mrp_id + from account_move_line aml + inner join stock_move sm + on sm.id=aml.stock_move_id + where coalesce(sm.production_id,sm.raw_material_production_id) is not null) + update account_move_line + set mrp_production_id = q2.mrp_id + from q2 + where q2.account_move_id=account_move_line.id; + """ + ) + cr.execute(query) + cr.execute( + "ALTER TABLE account_move_line ADD COLUMN IF NOT EXISTS unbuild_id INTEGER" + ) + query = sql.SQL( + """ + with q2 as ( + select aml.id as account_move_id, + sm.unbuild_id as unb_id + from account_move_line aml + inner join stock_move sm + on sm.id=aml.stock_move_id + where sm.unbuild_id is not null) + update account_move_line + set unbuild_id = q2.unb_id + from q2 + where q2.account_move_id=account_move_line.id; + """ + ) + cr.execute(query) diff --git a/account_move_line_mrp_info/i18n/account_move_line_mrp_info.pot b/account_move_line_mrp_info/i18n/account_move_line_mrp_info.pot new file mode 100644 index 000000000..9ae36a5a6 --- /dev/null +++ b/account_move_line_mrp_info/i18n/account_move_line_mrp_info.pot @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_mrp_info +# +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: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__account_move_line_ids +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__account_move_line_ids +msgid "Account Move Line" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__display_name +msgid "Display Name" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__id +msgid "ID" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.actions.act_window,name:account_move_line_mrp_info.action_view_journal_items +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_production_form_view +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_unbuild_form_view +msgid "Journal Items" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__mrp_production_id +msgid "Manufacturing Order" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: account_move_line_mrp_info +#: model_terms:ir.actions.act_window,help:account_move_line_mrp_info.action_view_journal_items +msgid "There's no journal item yet" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_unbuild +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__unbuild_id +msgid "Unbuild Order" +msgstr "" diff --git a/account_move_line_mrp_info/i18n/ca.po b/account_move_line_mrp_info/i18n/ca.po new file mode 100644 index 000000000..3d5eaeae8 --- /dev/null +++ b/account_move_line_mrp_info/i18n/ca.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_mrp_info +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\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" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__account_move_line_ids +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__account_move_line_ids +msgid "Account Move Line" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__display_name +msgid "Display Name" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__id +msgid "ID" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.actions.act_window,name:account_move_line_mrp_info.action_view_journal_items +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_production_form_view +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_unbuild_form_view +msgid "Journal Items" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__mrp_production_id +msgid "Manufacturing Order" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: account_move_line_mrp_info +#: model_terms:ir.actions.act_window,help:account_move_line_mrp_info.action_view_journal_items +msgid "There's no journal item yet" +msgstr "" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_unbuild +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__unbuild_id +msgid "Unbuild Order" +msgstr "" diff --git a/account_move_line_mrp_info/i18n/es.po b/account_move_line_mrp_info/i18n/es.po new file mode 100644 index 000000000..6350ba444 --- /dev/null +++ b/account_move_line_mrp_info/i18n/es.po @@ -0,0 +1,77 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_mrp_info +# +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: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__account_move_line_ids +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__account_move_line_ids +msgid "Account Move Line" +msgstr "Línea de movimiento de cuenta" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__display_name +msgid "Display Name" +msgstr "Mostrar nombre" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_account_move_line +msgid "Journal Item" +msgstr "Elemento de diario" + +#. module: account_move_line_mrp_info +#: model:ir.actions.act_window,name:account_move_line_mrp_info.action_view_journal_items +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_production_form_view +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_unbuild_form_view +msgid "Journal Items" +msgstr "Artículos Diarios" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__mrp_production_id +msgid "Manufacturing Order" +msgstr "Orden de Manufactura" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_production +msgid "Production Order" +msgstr "Orden de Producción" + +#. module: account_move_line_mrp_info +#: model_terms:ir.actions.act_window,help:account_move_line_mrp_info.action_view_journal_items +msgid "There's no journal item yet" +msgstr "Aún no hay ningún artículo en el diario" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_unbuild +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__unbuild_id +msgid "Unbuild Order" +msgstr "Orden de desestructuración" diff --git a/account_move_line_mrp_info/i18n/it.po b/account_move_line_mrp_info/i18n/it.po new file mode 100644 index 000000000..83ec1c00f --- /dev/null +++ b/account_move_line_mrp_info/i18n/it.po @@ -0,0 +1,77 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_mrp_info +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-12-22 13:44+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: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__account_move_line_ids +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__account_move_line_ids +msgid "Account Move Line" +msgstr "Riga movimento contabile" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__display_name +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production__id +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild__id +msgid "ID" +msgstr "ID" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_account_move_line +msgid "Journal Item" +msgstr "Movimento contabile" + +#. module: account_move_line_mrp_info +#: model:ir.actions.act_window,name:account_move_line_mrp_info.action_view_journal_items +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_production_form_view +#: model_terms:ir.ui.view,arch_db:account_move_line_mrp_info.mrp_unbuild_form_view +msgid "Journal Items" +msgstr "Movimenti contabili" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_production____last_update +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_mrp_unbuild____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: account_move_line_mrp_info +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__mrp_production_id +msgid "Manufacturing Order" +msgstr "Ordine di produzione" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_production +msgid "Production Order" +msgstr "Ordine di produzione" + +#. module: account_move_line_mrp_info +#: model_terms:ir.actions.act_window,help:account_move_line_mrp_info.action_view_journal_items +msgid "There's no journal item yet" +msgstr "Non ci sono ancora movimenti contabili" + +#. module: account_move_line_mrp_info +#: model:ir.model,name:account_move_line_mrp_info.model_mrp_unbuild +#: model:ir.model.fields,field_description:account_move_line_mrp_info.field_account_move_line__unbuild_id +msgid "Unbuild Order" +msgstr "Ordine di smontaggio" diff --git a/account_move_line_mrp_info/models/__init__.py b/account_move_line_mrp_info/models/__init__.py new file mode 100644 index 000000000..1865fc612 --- /dev/null +++ b/account_move_line_mrp_info/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import account_move_line +from . import mrp_production diff --git a/account_move_line_mrp_info/models/account_move_line.py b/account_move_line_mrp_info/models/account_move_line.py new file mode 100644 index 000000000..85cc95a18 --- /dev/null +++ b/account_move_line_mrp_info/models/account_move_line.py @@ -0,0 +1,39 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + mrp_production_id = fields.Many2one( + comodel_name="mrp.production", + string="Manufacturing Order", + compute="_compute_mrp_production", + store=True, + ) + unbuild_id = fields.Many2one( + comodel_name="mrp.unbuild", + string="Unbuild Order", + compute="_compute_mrp_unbuild", + store=True, + ) + + @api.depends("stock_move_id") + def _compute_mrp_production(self): + for rec in self: + if rec.stock_move_id.production_id: + rec.mrp_production_id = rec.stock_move_id.production_id.id + elif rec.stock_move_id.raw_material_production_id: + rec.mrp_production_id = rec.stock_move_id.raw_material_production_id.id + else: + rec.mrp_production_id = False + + @api.depends("stock_move_id") + def _compute_mrp_unbuild(self): + for rec in self: + if rec.stock_move_id.unbuild_id: + rec.unbuild_id = rec.stock_move_id.unbuild_id.id + else: + rec.unbuild_id = False diff --git a/account_move_line_mrp_info/models/mrp_production.py b/account_move_line_mrp_info/models/mrp_production.py new file mode 100644 index 000000000..1eb47f978 --- /dev/null +++ b/account_move_line_mrp_info/models/mrp_production.py @@ -0,0 +1,57 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from ast import literal_eval + +from odoo import fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + account_move_line_ids = fields.One2many( + comodel_name="account.move.line", inverse_name="mrp_production_id", copy=False + ) + + def view_journal_items(self): + self.ensure_one() + domain = [ + ( + "id", + "in", + (self.account_move_line_ids).ids, + ) + ] + action = self.env["ir.actions.act_window"]._for_xml_id( + "account_move_line_mrp_info.action_view_journal_items" + ) + context = literal_eval(action["context"]) + context.update(self.env.context) + context["no_at_date"] = True + context["search_default_group_by_product_id"] = False + return dict(action, domain=domain, context=context) + + +class MrpUnbuild(models.Model): + _inherit = "mrp.unbuild" + + account_move_line_ids = fields.One2many( + comodel_name="account.move.line", inverse_name="unbuild_id", copy=False + ) + + def view_journal_items(self): + self.ensure_one() + domain = [ + ( + "id", + "in", + (self.account_move_line_ids).ids, + ) + ] + action = self.env["ir.actions.act_window"]._for_xml_id( + "account_move_line_mrp_info.action_view_journal_items" + ) + context = literal_eval(action["context"]) + context.update(self.env.context) + context["no_at_date"] = True + context["search_default_group_by_product_id"] = False + return dict(action, domain=domain, context=context) diff --git a/account_move_line_mrp_info/readme/CONTRIBUTORS.rst b/account_move_line_mrp_info/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3eeb31a71 --- /dev/null +++ b/account_move_line_mrp_info/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Nuria Xifre Martin diff --git a/account_move_line_mrp_info/readme/DESCRIPTION.rst b/account_move_line_mrp_info/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ae70eee65 --- /dev/null +++ b/account_move_line_mrp_info/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the manufacturing orders and unbuild orders to the account move lines that it generates. diff --git a/account_move_line_mrp_info/readme/USAGE.rst b/account_move_line_mrp_info/readme/USAGE.rst new file mode 100644 index 000000000..bb46abe35 --- /dev/null +++ b/account_move_line_mrp_info/readme/USAGE.rst @@ -0,0 +1,7 @@ +* The stock manager can check the journal items by accessing to 'Manufacturing > + Operations > Manufacturing Orders> Journal Items' and 'Manufacturing > + Operations > Unbuild Orders> Journal Items. + +* A user belonging to the group 'Show Full Accounting Features' can review the + details of a move that is associated to a journal item through + 'Invoicing > Accounting > Journal Entries (or Journal items)'. diff --git a/account_move_line_mrp_info/security/ir.model.access.csv b/account_move_line_mrp_info/security/ir.model.access.csv new file mode 100644 index 000000000..32b1ebde7 --- /dev/null +++ b/account_move_line_mrp_info/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_move_line, account.move.line,account.model_account_move_line,stock.group_stock_manager,1,0,0,0 +access_mrp_production_account_invoice,mrp.production account invoice,mrp.model_mrp_production,account.group_account_invoice,1,0,0,0 +access_mrp_production_account_user,mrp.production account user,mrp.model_mrp_production,account.group_account_user,1,0,0,0 +access_mrp_production_account_manager,mrp.production account user,mrp.model_mrp_production,account.group_account_manager,1,0,0,0 diff --git a/account_move_line_mrp_info/static/description/icon.png b/account_move_line_mrp_info/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_line_mrp_info/static/description/icon.png differ diff --git a/account_move_line_mrp_info/static/description/index.html b/account_move_line_mrp_info/static/description/index.html new file mode 100644 index 000000000..6b5ab5983 --- /dev/null +++ b/account_move_line_mrp_info/static/description/index.html @@ -0,0 +1,433 @@ + + + + + + +Account Move Line Mrp Info + + + +
+

Account Move Line Mrp Info

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

This module adds the manufacturing orders and unbuild orders to the account move lines that it generates.

+

Table of contents

+ +
+

Usage

+
    +
  • The stock manager can check the journal items by accessing to ‘Manufacturing > +Operations > Manufacturing Orders> Journal Items’ and ‘Manufacturing > +Operations > Unbuild Orders> Journal Items.
  • +
  • A user belonging to the group ‘Show Full Accounting Features’ can review the +details of a move that is associated to a journal item through +‘Invoicing > Accounting > Journal Entries (or Journal items)’.
  • +
+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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.

+

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/account_move_line_mrp_info/tests/__init__.py b/account_move_line_mrp_info/tests/__init__.py new file mode 100644 index 000000000..aedc757e3 --- /dev/null +++ b/account_move_line_mrp_info/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_journal_items diff --git a/account_move_line_mrp_info/tests/test_mrp_journal_items.py b/account_move_line_mrp_info/tests/test_mrp_journal_items.py new file mode 100644 index 000000000..a63c49a05 --- /dev/null +++ b/account_move_line_mrp_info/tests/test_mrp_journal_items.py @@ -0,0 +1,159 @@ +from odoo.tests import Form + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestMrpOrder(TestMrpCommon): + def setUp(self): + super(TestMrpOrder, self).setUp() + self.stock_location = self.env.ref("stock.stock_location_stock") + self.env.ref("base.group_user").write( + {"implied_ids": [(4, self.env.ref("stock.group_production_lot").id)]} + ) + + def test_mrp_with_journal_items(self): + """This test creates a Manufacturing orderand then check if the + Journal Items button links to the journal items of the order. + """ + journal_items_before_production = self.env["account.move.line"].search([]).ids + + mo, bom, p_final, p1, p2 = self.generate_mo() + account = self.env["account.account"].create( + { + "name": "Test Account", + "code": "TestAccount1", + "user_type_id": self.env.ref("account.data_account_type_payable").id, + "reconcile": True, + } + ) + location = self.env["stock.location"].search([("usage", "=", "production")]) + location.valuation_in_account_id = account.id + location.valuation_out_account_id = account.id + pc = self.env["product.category"].create( + { + "name": "Category test", + "property_valuation": "real_time", + "property_cost_method": "fifo", + } + ) + p1.categ_id = pc.id + p1.standard_price = 10 + p2.categ_id = pc.id + p2.standard_price = 5 + p_final.categ_id = pc.id + + self.env["stock.quant"]._update_available_quantity(p1, self.stock_location, 100) + self.env["stock.quant"]._update_available_quantity(p2, self.stock_location, 5) + mo.action_assign() + + mo_form = Form(mo) + mo_form.qty_producing = 5.0 + mo = mo_form.save() + mo.button_mark_done() + + journal_items_after_production = self.env["account.move.line"].search([]).ids + + result = mo.view_journal_items() + domain = result["domain"] + mo_journal_items = list(domain[0][2]) + difference_journal_items = list( + set(journal_items_after_production) - set(journal_items_before_production) + ) + mo_journal_items.sort() + difference_journal_items.sort() + + self.assertTrue( + difference_journal_items, + "There should be new journal items after doing the manufacturing order", + ) + self.assertEqual( + result["res_model"], + "account.move.line", + "You should access to the model account.move.line", + ) + self.assertEqual( + difference_journal_items, + mo_journal_items, + "You should have as domain the ids of the journal items", + ) + + +class TestUnbuild(TestMrpCommon): + def setUp(self): + super(TestUnbuild, self).setUp() + self.stock_location = self.env.ref("stock.stock_location_stock") + self.env.ref("base.group_user").write( + {"implied_ids": [(4, self.env.ref("stock.group_production_lot").id)]} + ) + + def test_unbuild_with_journal_items(self): + """This test creates an Unbuild order from a Manufacturing order and then check if the + Journal Items button links to the journal items of the order. + """ + + mo, bom, p_final, p1, p2 = self.generate_mo() + account = self.env["account.account"].create( + { + "name": "Test Account", + "code": "TestAccount2", + "user_type_id": self.env.ref("account.data_account_type_payable").id, + "reconcile": True, + } + ) + location = self.env["stock.location"].search([("usage", "=", "production")]) + location.valuation_in_account_id = account.id + location.valuation_out_account_id = account.id + pc = self.env["product.category"].create( + { + "name": "Category test", + "property_valuation": "real_time", + "property_cost_method": "fifo", + } + ) + p1.categ_id = pc.id + p1.standard_price = 10 + p2.categ_id = pc.id + p2.standard_price = 5 + p_final.categ_id = pc.id + + self.env["stock.quant"]._update_available_quantity(p1, self.stock_location, 100) + self.env["stock.quant"]._update_available_quantity(p2, self.stock_location, 5) + mo.action_assign() + + mo_form = Form(mo) + mo_form.qty_producing = 5.0 + mo = mo_form.save() + mo.button_mark_done() + journal_items_before_unbuild = self.env["account.move.line"].search([]).ids + + x = Form(self.env["mrp.unbuild"]) + x.product_id = p_final + x.bom_id = bom + x.product_qty = 5 + unbuild = x.save() + unbuild.action_unbuild() + journal_items_after_unbuild = self.env["account.move.line"].search([]).ids + + result = unbuild.view_journal_items() + domain = result["domain"] + unbuild_journal_items = domain[0][2] + difference_journal_items = list( + set(journal_items_after_unbuild) - set(journal_items_before_unbuild) + ) + unbuild_journal_items.sort() + difference_journal_items.sort() + + self.assertTrue( + difference_journal_items, + "There should be new journal items after doing the unbuild", + ) + self.assertEqual( + result["res_model"], + "account.move.line", + "You should access to the model account.move.line", + ) + self.assertEqual( + difference_journal_items, + unbuild_journal_items, + "You should have as domain the ids of the journal items", + ) diff --git a/account_move_line_mrp_info/views/account_move_line_view.xml b/account_move_line_mrp_info/views/account_move_line_view.xml new file mode 100644 index 000000000..44d690cd2 --- /dev/null +++ b/account_move_line_mrp_info/views/account_move_line_view.xml @@ -0,0 +1,15 @@ + + + + account.move.line.form + account.move.line + + + + + + + + + + diff --git a/account_move_line_mrp_info/views/mrp_production_view.xml b/account_move_line_mrp_info/views/mrp_production_view.xml new file mode 100644 index 000000000..6bfaf88d5 --- /dev/null +++ b/account_move_line_mrp_info/views/mrp_production_view.xml @@ -0,0 +1,50 @@ + + + + Journal Items + ir.actions.act_window + account.move.line + tree,form + +

+ There's no journal item yet +

+
+
+ + + mrp.production + + + +