From 42c19862c143bea4cef31a006b5b6225402c2572 Mon Sep 17 00:00:00 2001 From: Chandresh Thakkar Date: Tue, 15 Dec 2020 02:17:43 +0530 Subject: [PATCH 1/4] [ADD] Added new module to track the cost of raw materials. --- mrp_analytic_cost_material/README.rst | 90 +++++++++++++++++++ mrp_analytic_cost_material/__init__.py | 4 + mrp_analytic_cost_material/__manifest__.py | 16 ++++ mrp_analytic_cost_material/models/__init__.py | 4 + .../models/account_analytic_line.py | 22 +++++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 4 + mrp_analytic_cost_material/readme/USAGE.rst | 9 ++ .../views/account_analytic_line_view.xml | 56 ++++++++++++ oca_dependencies.txt | 2 + .../odoo/addons/mrp_analytic_cost_material | 1 + setup/mrp_analytic_cost_material/setup.py | 6 ++ 12 files changed, 216 insertions(+) create mode 100644 mrp_analytic_cost_material/README.rst create mode 100644 mrp_analytic_cost_material/__init__.py create mode 100644 mrp_analytic_cost_material/__manifest__.py create mode 100644 mrp_analytic_cost_material/models/__init__.py create mode 100644 mrp_analytic_cost_material/models/account_analytic_line.py create mode 100644 mrp_analytic_cost_material/readme/CONTRIBUTORS.rst create mode 100644 mrp_analytic_cost_material/readme/DESCRIPTION.rst create mode 100644 mrp_analytic_cost_material/readme/USAGE.rst create mode 100644 mrp_analytic_cost_material/views/account_analytic_line_view.xml create mode 120000 setup/mrp_analytic_cost_material/odoo/addons/mrp_analytic_cost_material create mode 100644 setup/mrp_analytic_cost_material/setup.py 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..b1cc58596 --- /dev/null +++ b/mrp_analytic_cost_material/__manifest__.py @@ -0,0 +1,16 @@ +# 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"], + "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..35345e57a --- /dev/null +++ b/mrp_analytic_cost_material/models/__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 account_analytic_line 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/readme/CONTRIBUTORS.rst b/mrp_analytic_cost_material/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..88e8811fe --- /dev/null +++ b/mrp_analytic_cost_material/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* 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/oca_dependencies.txt b/oca_dependencies.txt index ca3c726ba..b71fa7b14 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,3 @@ # See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt + +account-analytic diff --git a/setup/mrp_analytic_cost_material/odoo/addons/mrp_analytic_cost_material b/setup/mrp_analytic_cost_material/odoo/addons/mrp_analytic_cost_material new file mode 120000 index 000000000..27645af9d --- /dev/null +++ b/setup/mrp_analytic_cost_material/odoo/addons/mrp_analytic_cost_material @@ -0,0 +1 @@ +../../../../mrp_analytic_cost_material \ No newline at end of file diff --git a/setup/mrp_analytic_cost_material/setup.py b/setup/mrp_analytic_cost_material/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_analytic_cost_material/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From bf3163431fff54d65275f7d140e6bc8eebb3e965 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Thu, 17 Dec 2020 11:33:01 +0000 Subject: [PATCH 2/4] [REF] mrp_analytic_cost_material: add maintainer and Alpha development status --- mrp_analytic_cost_material/__manifest__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mrp_analytic_cost_material/__manifest__.py b/mrp_analytic_cost_material/__manifest__.py index b1cc58596..7e04de5df 100644 --- a/mrp_analytic_cost_material/__manifest__.py +++ b/mrp_analytic_cost_material/__manifest__.py @@ -12,5 +12,7 @@ "license": "AGPL-3", "depends": ["mrp_analytic", "account"], "data": ["views/account_analytic_line_view.xml"], + "maintainer": "dreispt", + "development_status": "Alpha", "installable": True, } From ca073e4bde05cca3113e15efc4d9829557988e3b Mon Sep 17 00:00:00 2001 From: Chandresh Thakkar Date: Wed, 30 Dec 2020 02:41:31 +0530 Subject: [PATCH 3/4] [ADD] Business logic to add analytic lines on stock reservation. --- mrp_analytic_cost_material/__manifest__.py | 2 +- mrp_analytic_cost_material/models/__init__.py | 1 + .../models/mrp_production.py | 26 +++++++++++++++++++ .../views/mrp_production_views.xml | 18 +++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 mrp_analytic_cost_material/models/mrp_production.py create mode 100644 mrp_analytic_cost_material/views/mrp_production_views.xml diff --git a/mrp_analytic_cost_material/__manifest__.py b/mrp_analytic_cost_material/__manifest__.py index 7e04de5df..3babe9e4e 100644 --- a/mrp_analytic_cost_material/__manifest__.py +++ b/mrp_analytic_cost_material/__manifest__.py @@ -11,7 +11,7 @@ "website": "https://github.com/OCA/manufacture", "license": "AGPL-3", "depends": ["mrp_analytic", "account"], - "data": ["views/account_analytic_line_view.xml"], + "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 index 35345e57a..b4221a567 100644 --- a/mrp_analytic_cost_material/models/__init__.py +++ b/mrp_analytic_cost_material/models/__init__.py @@ -2,3 +2,4 @@ # 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/mrp_production.py b/mrp_analytic_cost_material/models/mrp_production.py new file mode 100644 index 000000000..4d3e6471a --- /dev/null +++ b/mrp_analytic_cost_material/models/mrp_production.py @@ -0,0 +1,26 @@ +# 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 generate_analytic_line(self): + """Generate Analytic Lines Manually.""" + for order in self: + AccountAnalyticLine = self.env["account.analytic.line"].sudo() + for line in order.move_raw_ids: + line_vals = { + "name": line.product_id.default_code or "", + "account_id": order.analytic_account_id.id or False, + "ref": order.name, + "unit_amount": line.product_uom_qty, + "company_id": order.company_id.id, + "manufacturing_order_id": order.id, + "product_id": line.product_id.id or False, + "stock_move_id": line.raw_material_production_id.id, + } + analytic_line = AccountAnalyticLine.create(line_vals) + analytic_line.on_change_unit_amount() 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..294299a64 --- /dev/null +++ b/mrp_analytic_cost_material/views/mrp_production_views.xml @@ -0,0 +1,18 @@ + + + + custom.mrp.production.form + mrp.production + + + +