diff --git a/mrp_analytic_cost_material/README.rst b/mrp_analytic_cost_material/README.rst new file mode 100644 index 000000000..be43e94fa --- /dev/null +++ b/mrp_analytic_cost_material/README.rst @@ -0,0 +1,90 @@ +====================================== +Manufacturing Materials Analytic Costs +====================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_analytic_cost_material + :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_analytic_cost_material + :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| + +Manufacturing costs are only generated when a Manufacturing Order is closed. + +This feature allows to track costs while the manufacturing is in progress. +This is done for raw materials used, by generating Analytic Items when the stock is reserved. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use: + +* On the Manufacturing Order, set the Analytic Account to use. This may correspond to a Project. +* On Manufacturing Orders, when a stock reservation is triggered, Analytic Items are automatically generated . + +To analyze costs: + +* Go to Manufacturing > Reports > Analytic Items. The cost data is available there and can be used for analysis. +* At Project > Dashboard, "Project Overview" form, a summary of the costs for the corresponding Analytic Account is presented. + +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 +* Chandresh Thakkar + +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_analytic_cost_material/__init__.py b/mrp_analytic_cost_material/__init__.py new file mode 100644 index 000000000..d4e814652 --- /dev/null +++ b/mrp_analytic_cost_material/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_analytic_cost_material/__manifest__.py b/mrp_analytic_cost_material/__manifest__.py new file mode 100644 index 000000000..3babe9e4e --- /dev/null +++ b/mrp_analytic_cost_material/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Manufacturing Materials Analytic Costs", + "summary": "Track raw material costs as Analytic Items during the \ + manufacturing process", + "version": "14.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", "account"], + "data": ["views/account_analytic_line_view.xml", "views/mrp_production_views.xml"], + "maintainer": "dreispt", + "development_status": "Alpha", + "installable": True, +} diff --git a/mrp_analytic_cost_material/models/__init__.py b/mrp_analytic_cost_material/models/__init__.py new file mode 100644 index 000000000..b4221a567 --- /dev/null +++ b/mrp_analytic_cost_material/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_analytic_line +from . import mrp_production diff --git a/mrp_analytic_cost_material/models/account_analytic_line.py b/mrp_analytic_cost_material/models/account_analytic_line.py new file mode 100644 index 000000000..b9fc0a87f --- /dev/null +++ b/mrp_analytic_cost_material/models/account_analytic_line.py @@ -0,0 +1,22 @@ +# 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" + + stock_move_id = fields.Many2one( + "stock.move", + string="Related Stock Move", + ) + manufacturing_order_id = fields.Many2one( + "mrp.production", + string="Related Manufacturing Order", + ) + product_category_id = fields.Many2one( + related="product_id.categ_id", + string="Product Category", + store=True, + ) diff --git a/mrp_analytic_cost_material/models/mrp_production.py b/mrp_analytic_cost_material/models/mrp_production.py new file mode 100644 index 000000000..c9017349d --- /dev/null +++ b/mrp_analytic_cost_material/models/mrp_production.py @@ -0,0 +1,44 @@ +# Copyright (C) 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + def _prepare_material_analytic_line(self): + self.ensure_one() + order = self.raw_material_production_id + return { + "name": self.product_id.default_code or "", + "account_id": order.analytic_account_id.id or False, + "ref": order.name, + "unit_amount": self.product_uom_qty, + "company_id": order.company_id.id, + "manufacturing_order_id": order.id, + "product_id": self.product_id.id or False, + "stock_move_id": self.id, + } + + def generate_analytic_line(self): + """Generate Analytic Lines Manually.""" + # FIXME: this is a placeholder for final logic + # TODO: when should Analytic Items generation be triggered? + # TODO: what to do if prevous items were already generated? + AnalyticLine = self.env["account.analytic.line"].sudo() + order_raw_moves = self.mapped("move_raw_ids") + existing_items = AnalyticLine.search( + [("stock_move_id ", "in", order_raw_moves.ids)] + ) + for order in self.filtered("analytic_account_id"): + for line in order.move_raw_ids: + line_vals = line._prepare_material_analytic_line() + if line in existing_items: + analytic_line = existing_items.filter( + lambda x: x.stock_move_id == line + ) + analytic_line.write(line_vals) + else: + analytic_line = AnalyticLine.create(line_vals) + analytic_line.on_change_unit_amount() diff --git a/mrp_analytic_cost_material/readme/CONTRIBUTORS.rst b/mrp_analytic_cost_material/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..edcb34a12 --- /dev/null +++ b/mrp_analytic_cost_material/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Open Source Integrators `: + + * Daniel Reis + * Chandresh Thakkar diff --git a/mrp_analytic_cost_material/readme/DESCRIPTION.rst b/mrp_analytic_cost_material/readme/DESCRIPTION.rst new file mode 100644 index 000000000..29b809945 --- /dev/null +++ b/mrp_analytic_cost_material/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Manufacturing costs are only generated when a Manufacturing Order is closed. + +This feature allows to track costs while the manufacturing is in progress. +This is done for raw materials used, by generating Analytic Items when the stock is reserved. diff --git a/mrp_analytic_cost_material/readme/USAGE.rst b/mrp_analytic_cost_material/readme/USAGE.rst new file mode 100644 index 000000000..9fd13862b --- /dev/null +++ b/mrp_analytic_cost_material/readme/USAGE.rst @@ -0,0 +1,9 @@ +To use: + +* On the Manufacturing Order, set the Analytic Account to use. This may correspond to a Project. +* On Manufacturing Orders, when a stock reservation is triggered, Analytic Items are automatically generated . + +To analyze costs: + +* Go to Manufacturing > Reports > Analytic Items. The cost data is available there and can be used for analysis. +* At Project > Dashboard, "Project Overview" form, a summary of the costs for the corresponding Analytic Account is presented. diff --git a/mrp_analytic_cost_material/views/account_analytic_line_view.xml b/mrp_analytic_cost_material/views/account_analytic_line_view.xml new file mode 100644 index 000000000..9d44d7c4e --- /dev/null +++ b/mrp_analytic_cost_material/views/account_analytic_line_view.xml @@ -0,0 +1,56 @@ + + + + account.analytic.line.custom.form + account.analytic.line + + + + + + + + + + + + + account.analytic.line.custom.filter + account.analytic.line + + + + + + + + + + + Analytic Items + account.analytic.line + tree,form + {'search_default_related-mo': True} + + + diff --git a/mrp_analytic_cost_material/views/mrp_production_views.xml b/mrp_analytic_cost_material/views/mrp_production_views.xml new file mode 100644 index 000000000..4e09e562d --- /dev/null +++ b/mrp_analytic_cost_material/views/mrp_production_views.xml @@ -0,0 +1,18 @@ + + + + custom.mrp.production.form + mrp.production + + + +