diff --git a/mrp_account_analytic/README.rst b/mrp_account_analytic/README.rst new file mode 100644 index 000000000..cf2ea838b --- /dev/null +++ b/mrp_account_analytic/README.rst @@ -0,0 +1,102 @@ +============================ +Manufacturing Analytic Items +============================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/14.0/mrp_account_analytic + :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_account_analytic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Generates Analytic Items during manufacturing operations. + +When raw materials are consumed or work center time is recorded, +Analytic Items are created, capturing the corresponding quantity and cost. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use: + +* On the *Manufacturing Order*, *Miscellaneous* tab, set the Analytic Account to use. + This may correspond to a Project. + +On Manufacturing Orders, Analytic Items are automatically generated when: + + * Raw materials are consumed, or + * Time is spent on Operations. + +To analyze costs: + +* Go to *Manufacturing > Reports > Analytic Items*. + The cost data is available there and can be used for analysis. + +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 +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* Daniel Reis + +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-dreispt| image:: https://github.com/dreispt.png?size=40px + :target: https://github.com/dreispt + :alt: dreispt + +Current `maintainer `__: + +|maintainer-dreispt| + +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_account_analytic/__init__.py b/mrp_account_analytic/__init__.py new file mode 100644 index 000000000..bb83730e9 --- /dev/null +++ b/mrp_account_analytic/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_account_analytic/__manifest__.py b/mrp_account_analytic/__manifest__.py new file mode 100644 index 000000000..c4b19a61d --- /dev/null +++ b/mrp_account_analytic/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Manufacturing Analytic Items", + "summary": "Consuming raw materials and operations generated Analytic Items", + "version": "15.0.1.0.1", + "category": "Manufacturing", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "license": "AGPL-3", + "depends": ["mrp_analytic"], + "data": [ + "views/account_analytic_line_view.xml", + ], + "installable": True, + "maintainers": ["dreispt"], + "development_status": "Beta", +} diff --git a/mrp_account_analytic/i18n/hr.po b/mrp_account_analytic/i18n/hr.po new file mode 100644 index 000000000..e3143609f --- /dev/null +++ b/mrp_account_analytic/i18n/hr.po @@ -0,0 +1,98 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_account_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-08-22 21:07+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: mrp_account_analytic +#: model:ir.actions.act_window,name:mrp_account_analytic.action_new_mrp_analytic_items +#: model:ir.ui.menu,name:mrp_account_analytic.custom_account_analytic_line_menu +msgid "Analytic Items" +msgstr "Analitičke stavke" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_account_analytic_line +msgid "Analytic Line" +msgstr "Stavka analitike" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__display_name +msgid "Display Name" +msgstr "Prikazani naziv" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__id +msgid "ID" +msgstr "ID" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_form_ext +msgid "Manufacture" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Order" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Orders" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__manufacturing_order_id +msgid "Related Manufacturing Order" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__stock_move_id +msgid "Related Stock Move" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__workorder_id +msgid "Work Order" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_mrp_workcenter_productivity +msgid "Workcenter Productivity Log" +msgstr "" diff --git a/mrp_account_analytic/i18n/it.po b/mrp_account_analytic/i18n/it.po new file mode 100644 index 000000000..dc216b739 --- /dev/null +++ b/mrp_account_analytic/i18n/it.po @@ -0,0 +1,97 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_account_analytic +# +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: mrp_account_analytic +#: model:ir.actions.act_window,name:mrp_account_analytic.action_new_mrp_analytic_items +#: model:ir.ui.menu,name:mrp_account_analytic.custom_account_analytic_line_menu +msgid "Analytic Items" +msgstr "Elementi analitica" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_account_analytic_line +msgid "Analytic Line" +msgstr "Riga analitica" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__id +msgid "ID" +msgstr "ID" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_form_ext +msgid "Manufacture" +msgstr "Produzione" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Order" +msgstr "Ordine di produzione" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Orders" +msgstr "Ordini di produzione" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Movimenti prodotto (riga movimento di magazzino)" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__manufacturing_order_id +msgid "Related Manufacturing Order" +msgstr "Ordine di produzione relativo" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__stock_move_id +msgid "Related Stock Move" +msgstr "Movimento di magazzino relativo" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__workorder_id +msgid "Work Order" +msgstr "Ordine di lavoro" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_mrp_workcenter_productivity +msgid "Workcenter Productivity Log" +msgstr "Registro produttività centro di lavoro" diff --git a/mrp_account_analytic/i18n/mrp_account_analytic.pot b/mrp_account_analytic/i18n/mrp_account_analytic.pot new file mode 100644 index 000000000..eba544b35 --- /dev/null +++ b/mrp_account_analytic/i18n/mrp_account_analytic.pot @@ -0,0 +1,94 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_account_analytic +# +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_account_analytic +#: model:ir.actions.act_window,name:mrp_account_analytic.action_new_mrp_analytic_items +#: model:ir.ui.menu,name:mrp_account_analytic.custom_account_analytic_line_menu +msgid "Analytic Items" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_account_analytic_line +msgid "Analytic Line" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__display_name +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move__id +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line__id +msgid "ID" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_mrp_workcenter_productivity____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move____last_update +#: model:ir.model.fields,field_description:mrp_account_analytic.field_stock_move_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_form_ext +msgid "Manufacture" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Order" +msgstr "" + +#. module: mrp_account_analytic +#: model_terms:ir.ui.view,arch_db:mrp_account_analytic.custom_account_analytic_line_filter_view +msgid "Manufacturing Orders" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__manufacturing_order_id +msgid "Related Manufacturing Order" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__stock_move_id +msgid "Related Stock Move" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model.fields,field_description:mrp_account_analytic.field_account_analytic_line__workorder_id +msgid "Work Order" +msgstr "" + +#. module: mrp_account_analytic +#: model:ir.model,name:mrp_account_analytic.model_mrp_workcenter_productivity +msgid "Workcenter Productivity Log" +msgstr "" diff --git a/mrp_account_analytic/models/__init__.py b/mrp_account_analytic/models/__init__.py new file mode 100644 index 000000000..853b1a022 --- /dev/null +++ b/mrp_account_analytic/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_analytic_line +from . import mrp_workorder +from . import stock_move diff --git a/mrp_account_analytic/models/account_analytic_line.py b/mrp_account_analytic/models/account_analytic_line.py new file mode 100644 index 000000000..dc2c90b4f --- /dev/null +++ b/mrp_account_analytic/models/account_analytic_line.py @@ -0,0 +1,21 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + manufacturing_order_id = fields.Many2one( + "mrp.production", + string="Related Manufacturing Order", + ) + stock_move_id = fields.Many2one( + "stock.move", + string="Related Stock Move", + ) + workorder_id = fields.Many2one( + "mrp.workorder", + string="Work Order", + ) diff --git a/mrp_account_analytic/models/mrp_workorder.py b/mrp_account_analytic/models/mrp_workorder.py new file mode 100644 index 000000000..a581b494f --- /dev/null +++ b/mrp_account_analytic/models/mrp_workorder.py @@ -0,0 +1,46 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class MrpWorkcenterProductivity(models.Model): + _inherit = "mrp.workcenter.productivity" + + def _prepare_mrp_workorder_analytic_item(self): + """ + Prepare additional values for Analytic Items created. + For compatibility with analytic_activity_cost + """ + self.ensure_one() + return { + "name": "{} / {}".format(self.production_id.name, self.workorder_id.name), + "account_id": self.production_id.analytic_account_id.id, + "date": fields.Date.today(), + "company_id": self.company_id.id, + "manufacturing_order_id": self.production_id.id, + "workorder_id": self.workorder_id.id, + "unit_amount": self.duration / 60, # convert minutes to hours + "amount": -self.duration / 60 * self.workcenter_id.costs_hour, + } + + def generate_mrp_work_analytic_line(self): + AnalyticLine = self.env["account.analytic.line"].sudo() + for timelog in self: + line_vals = timelog._prepare_mrp_workorder_analytic_item() + analytic_line = AnalyticLine.create(line_vals) + analytic_line.on_change_unit_amount() + + @api.model + def create(self, vals): + timelog = super().create(vals) + if vals.get("date_end"): + timelog.generate_mrp_work_analytic_line() + return timelog + + def write(self, vals): + res = super().write(vals) + if vals.get("date_end"): + self.generate_mrp_work_analytic_line() + return res diff --git a/mrp_account_analytic/models/stock_move.py b/mrp_account_analytic/models/stock_move.py new file mode 100644 index 000000000..b42f7a2ce --- /dev/null +++ b/mrp_account_analytic/models/stock_move.py @@ -0,0 +1,82 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _prepare_mrp_raw_material_analytic_line(self): + """ + Prepare additional values for Analytic Items created. + """ + self.ensure_one() + move = self + mrp_order = move.raw_material_production_id + return { + "date": move.date, + "name": "{} / {}".format(mrp_order.name, move.product_id.display_name), + "ref": mrp_order.name, + "account_id": mrp_order.analytic_account_id.id, + "manufacturing_order_id": mrp_order.id, + "company_id": mrp_order.company_id.id, + "stock_move_id": move.id, + "product_id": move.product_id.id, + "unit_amount": move.quantity_done, + } + + def generate_mrp_raw_analytic_line(self): + """ + Generate Analytic Lines. + One Analytic Item for each Stock Move line. + If the Stock Move is updated, the existing Analytic Item is updated. + """ + AnalyticLine = self.env["account.analytic.line"].sudo() + existing_items = AnalyticLine.search([("stock_move_id", "in", self.ids)]) + for move in self.filtered("raw_material_production_id.analytic_account_id"): + line_vals = move._prepare_mrp_raw_material_analytic_line() + if move in existing_items.mapped("stock_move_id"): + analytic_line = existing_items.filtered( + lambda x: x.stock_move_id == move + ) + analytic_line.write(line_vals) + analytic_line.on_change_unit_amount() + elif line_vals.get("unit_amount"): + analytic_line = AnalyticLine.create(line_vals) + analytic_line.on_change_unit_amount() + + def write(self, vals): + """When material is consumed, generate Analytic Items""" + res = super().write(vals) + if vals.get("quantity_done"): + self.generate_mrp_raw_analytic_line() + return res + + @api.model + def create(self, vals): + qty_done = vals.get("quantity_done") + res = super().create(vals) + if qty_done: + res.generate_mrp_raw_analytic_line() + return res + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def write(self, vals): + qty_done = vals.get("qty_done") + res = super().write(vals) + if qty_done: + self.mapped("move_id").generate_mrp_raw_analytic_line() + return res + + @api.model + def create(self, vals): + qty_done = vals.get("qty_done") + res = super().create(vals) + if qty_done: + res.mapped("move_id").generate_mrp_raw_analytic_line() + return res diff --git a/mrp_account_analytic/readme/CONTRIBUTORS.rst b/mrp_account_analytic/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..837de373e --- /dev/null +++ b/mrp_account_analytic/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Daniel Reis diff --git a/mrp_account_analytic/readme/DESCRIPTION.rst b/mrp_account_analytic/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ec216c918 --- /dev/null +++ b/mrp_account_analytic/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Generates Analytic Items during manufacturing operations. + +When raw materials are consumed or work center time is recorded, +Analytic Items are created, capturing the corresponding quantity and cost. diff --git a/mrp_account_analytic/readme/USAGE.rst b/mrp_account_analytic/readme/USAGE.rst new file mode 100644 index 000000000..0f5e2348c --- /dev/null +++ b/mrp_account_analytic/readme/USAGE.rst @@ -0,0 +1,14 @@ +To use: + +* On the *Manufacturing Order*, *Miscellaneous* tab, set the Analytic Account to use. + This may correspond to a Project. + +On Manufacturing Orders, Analytic Items are automatically generated when: + + * Raw materials are consumed, or + * Time is spent on Operations. + +To analyze costs: + +* Go to *Manufacturing > Reports > Analytic Items*. + The cost data is available there and can be used for analysis. diff --git a/mrp_account_analytic/static/description/icon.png b/mrp_account_analytic/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_account_analytic/static/description/icon.png differ diff --git a/mrp_account_analytic/static/description/index.html b/mrp_account_analytic/static/description/index.html new file mode 100644 index 000000000..1fec49bb6 --- /dev/null +++ b/mrp_account_analytic/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Manufacturing Analytic Items + + + +
+

Manufacturing Analytic Items

+ + +

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

+

Generates Analytic Items during manufacturing operations.

+

When raw materials are consumed or work center time is recorded, +Analytic Items are created, capturing the corresponding quantity and cost.

+

Table of contents

+ +
+

Usage

+

To use:

+
    +
  • On the Manufacturing Order, Miscellaneous tab, set the Analytic Account to use. +This may correspond to a Project.
  • +
+

On Manufacturing Orders, Analytic Items are automatically generated when:

+
+
    +
  • Raw materials are consumed, or
  • +
  • Time is spent on Operations.
  • +
+
+

To analyze costs:

+
    +
  • Go to Manufacturing > Reports > Analytic Items. +The cost data is available there and can be used for analysis.
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+ +
+

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:

+

dreispt

+

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_account_analytic/tests/__init__.py b/mrp_account_analytic/tests/__init__.py new file mode 100644 index 000000000..2b58ade96 --- /dev/null +++ b/mrp_account_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_analytic diff --git a/mrp_account_analytic/tests/test_mrp_analytic.py b/mrp_account_analytic/tests/test_mrp_analytic.py new file mode 100644 index 000000000..3f3969b64 --- /dev/null +++ b/mrp_account_analytic/tests/test_mrp_analytic.py @@ -0,0 +1,116 @@ +from odoo.tests import Form, common + + +class TestMRP(common.TransactionCase): + """ + Create a Manufacturing Order, with Raw Materials and Operations. + Consuming raw materials generates or updates Analytic Items. + Working on Operations generates or updates Analytic Items. + """ + + def setUp(self): + super().setUp() + # Analytic Account + self.analytic_1 = self.env["account.analytic.account"].create({"name": "Job 1"}) + # Work Center + self.mrp_workcenter_1 = self.env["mrp.workcenter"].create( + { + "name": "Assembly Line", + "costs_hour": 40, + } + ) + # Products + self.product_lemonade = self.env["product.product"].create( + { + "name": "Lemonade", + "type": "product", + "standard_price": 20, + } + ) + self.product_lemon = self.env["product.product"].create( + { + "name": "Lemon", + "type": "product", + "standard_price": 1, + } + ) + # BOM + self.mrp_bom_lemonade = self.env["mrp.bom"].create( + { + "product_tmpl_id": self.product_lemonade.product_tmpl_id.id, + "operation_ids": [ + ( + 0, + 0, + { + "workcenter_id": self.mrp_workcenter_1.id, + "name": "Squeeze Lemons", + "time_cycle": 15, + }, + ), + ], + } + ) + self.mrp_bom_lemonade.write( + { + "bom_line_ids": [ + ( + 0, + 0, + { + "product_id": self.product_lemon.id, + "product_qty": 4, + }, + ) + ] + } + ) + # MO + mo_create_form = Form(self.env["mrp.production"]) + mo_create_form.product_id = self.product_lemonade + mo_create_form.bom_id = self.mrp_bom_lemonade + mo_create_form.product_qty = 1 + self.mo_lemonade = mo_create_form.save() + self.mo_lemonade.analytic_account_id = self.analytic_1 + self.mo_lemonade.action_confirm() + + def test_100_one_step_produce(self): + # Form edit the MO and Save + mo_form = Form(self.mo_lemonade) + mo_form.qty_producing = 1 + mo_lemonade = mo_form.save() + # Set 15 minutes to work time and "Mark As Done" + mo_lemonade.workorder_ids.duration = 15 + mo_lemonade.button_mark_done() + + analytic_items = self.env["account.analytic.line"].search( + [("manufacturing_order_id", "=", mo_lemonade.id)] + ) + # Expected (4 * 1.00) + (0.25 * 40.00) => 14.00 + analytic_qty = sum(analytic_items.mapped("unit_amount")) + self.assertEqual(analytic_qty, 4.25, "Expected Analytic Items total quantity") + analytic_amount = sum(analytic_items.mapped("amount")) + self.assertEqual( + analytic_amount, -14.00, "Expected Analytic Items total amount" + ) + + def test_110_two_step_produce(self): + # Consume some raw material + self.mo_lemonade.move_raw_ids.write({"quantity_done": 1}) + self.mo_lemonade.move_raw_ids.write({"quantity_done": 2}) + self.mo_lemonade.move_raw_ids.write({"quantity_done": 4}) + # Work on operations up to 15 minutes + self.mo_lemonade.workorder_ids.write({"duration": 5}) + self.mo_lemonade.workorder_ids.write({"duration": 10}) + self.mo_lemonade.workorder_ids.write({"duration": 15}) + + analytic_items = self.env["account.analytic.line"].search( + [("manufacturing_order_id", "=", self.mo_lemonade.id)] + ) + # Expected (4 * 1.00) + (0.25 * 40.00) => 14.00 + analytic_qty = sum(analytic_items.mapped("unit_amount")) + self.assertEqual(analytic_qty, 4.25, "Expected Analytic Items total quantity") + analytic_amount = sum(analytic_items.mapped("amount")) + self.assertEqual( + analytic_amount, -14.00, "Expected Analytic Items total amount" + ) diff --git a/mrp_account_analytic/views/account_analytic_line_view.xml b/mrp_account_analytic/views/account_analytic_line_view.xml new file mode 100644 index 000000000..7fde329a8 --- /dev/null +++ b/mrp_account_analytic/views/account_analytic_line_view.xml @@ -0,0 +1,70 @@ + + + + + account.analytic.line.custom.tree + account.analytic.line + + + + + + + + + + + + + + account.analytic.line.custom.form + account.analytic.line + + + + + + + + + + + + + account.analytic.line.custom.filter + account.analytic.line + + + + + + + + + + + Analytic Items + account.analytic.line + tree,kanban,form,graph,pivot + + + {'search_default_filter_is_related_to_mo': True} + + + + diff --git a/setup/mrp_account_analytic/odoo/addons/mrp_account_analytic b/setup/mrp_account_analytic/odoo/addons/mrp_account_analytic new file mode 120000 index 000000000..d39786be8 --- /dev/null +++ b/setup/mrp_account_analytic/odoo/addons/mrp_account_analytic @@ -0,0 +1 @@ +../../../../mrp_account_analytic \ No newline at end of file diff --git a/setup/mrp_account_analytic/setup.py b/setup/mrp_account_analytic/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_account_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)