diff --git a/mrp_subcontracting_analytic/README.rst b/mrp_subcontracting_analytic/README.rst new file mode 100644 index 0000000000..8e88400496 --- /dev/null +++ b/mrp_subcontracting_analytic/README.rst @@ -0,0 +1,78 @@ +=========================== +MRP Subcontracting Analytic +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Faccount--analytic-lightgray.png?logo=github + :target: https://github.com/OCA/account-analytic/tree/16.0/mrp_subcontracting_analytic + :alt: OCA/account-analytic +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-analytic-16-0/account-analytic-16-0-mrp_subcontracting_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/87/16.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Propagates the analytic distribution of subcontracting receipt stock move to the +corresponding field of related manufacturing order. + +This module depends on other OCA modules, stock_analytic and mrp_production_analytic. + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited + +Contributors +~~~~~~~~~~~~ + +* `Quartile `__: + + * Yoshi Tashiro + +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/account-analytic `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_subcontracting_analytic/__init__.py b/mrp_subcontracting_analytic/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mrp_subcontracting_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_subcontracting_analytic/__manifest__.py b/mrp_subcontracting_analytic/__manifest__.py new file mode 100644 index 0000000000..68834c2b6a --- /dev/null +++ b/mrp_subcontracting_analytic/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "MRP Subcontracting Analytic", + "version": "16.0.1.0.0", + "author": "Quartile Limited, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-analytic", + "category": "Manufacturing/Manufacturing", + "license": "AGPL-3", + "depends": [ + "mrp_subcontracting", + "mrp_stock_analytic", + ], + "installable": True, +} diff --git a/mrp_subcontracting_analytic/models/__init__.py b/mrp_subcontracting_analytic/models/__init__.py new file mode 100644 index 0000000000..a33bde1e87 --- /dev/null +++ b/mrp_subcontracting_analytic/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_move +from . import stock_picking diff --git a/mrp_subcontracting_analytic/models/stock_move.py b/mrp_subcontracting_analytic/models/stock_move.py new file mode 100644 index 0000000000..b961221803 --- /dev/null +++ b/mrp_subcontracting_analytic/models/stock_move.py @@ -0,0 +1,23 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + analytic_distribution = fields.Json(inverse="_inverse_analytic_distribution") + + def _inverse_analytic_distribution(self): + for move in self: + if not move.is_subcontract: + continue + production = self.search( + [ + ("product_id", "=", move.product_id.id), + ("move_dest_ids", "=", move.id), + ] + ).production_id + if production: + production.analytic_distribution = move.analytic_distribution diff --git a/mrp_subcontracting_analytic/models/stock_picking.py b/mrp_subcontracting_analytic/models/stock_picking.py new file mode 100644 index 0000000000..6172c702c6 --- /dev/null +++ b/mrp_subcontracting_analytic/models/stock_picking.py @@ -0,0 +1,13 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +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) + vals["analytic_distribution"] = subcontract_move.analytic_distribution + return vals diff --git a/mrp_subcontracting_analytic/readme/CONTRIBUTORS.rst b/mrp_subcontracting_analytic/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..8cc932beb9 --- /dev/null +++ b/mrp_subcontracting_analytic/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Quartile `__: + + * Yoshi Tashiro diff --git a/mrp_subcontracting_analytic/readme/DESCRIPTION.rst b/mrp_subcontracting_analytic/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..5a9d650c4b --- /dev/null +++ b/mrp_subcontracting_analytic/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Propagates the analytic distribution of subcontracting receipt stock move to the +corresponding field of related manufacturing order. + +This module depends on other OCA modules, stock_analytic and mrp_production_analytic. diff --git a/mrp_subcontracting_analytic/static/description/index.html b/mrp_subcontracting_analytic/static/description/index.html new file mode 100644 index 0000000000..32c595af98 --- /dev/null +++ b/mrp_subcontracting_analytic/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +MRP Subcontracting Analytic + + + +
+

MRP Subcontracting Analytic

+ + +

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

+

Propagates the analytic distribution of subcontracting receipt stock move to the +corresponding field of related manufacturing order.

+

This module depends on other OCA modules, stock_analytic and mrp_production_analytic.

+

Table of contents

+ +
+

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

+
    +
  • Quartile Limited
  • +
+
+
+

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/account-analytic project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mrp_subcontracting_analytic/tests/__init__.py b/mrp_subcontracting_analytic/tests/__init__.py new file mode 100644 index 0000000000..65a3b3ce93 --- /dev/null +++ b/mrp_subcontracting_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_subcontracting_analytic diff --git a/mrp_subcontracting_analytic/tests/test_mrp_subcontracting_analytic.py b/mrp_subcontracting_analytic/tests/test_mrp_subcontracting_analytic.py new file mode 100644 index 0000000000..02dc87c149 --- /dev/null +++ b/mrp_subcontracting_analytic/tests/test_mrp_subcontracting_analytic.py @@ -0,0 +1,44 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import Form, tagged + +from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon + + +@tagged("post_install", "-at_install") +class TestMrpSubcontractingAnalytic(TestMrpSubcontractingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.analytic_distribution = dict( + {str(cls.env.ref("analytic.analytic_agrolait").id): 100.0} + ) + + def test_propagate_analytic_distribution(self): + # Create a receipt picking from subcontractor + picking_form = Form(self.env["stock.picking"]) + picking_form.picking_type_id = self.env.ref("stock.picking_type_in") + picking_form.partner_id = self.subcontractor_partner1 + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.finished + move.product_uom_qty = 1 + picking_receipt = picking_form.save() + receipt_move = picking_receipt.move_ids + receipt_move.analytic_distribution = self.analytic_distribution + picking_receipt.action_confirm() + production = ( + self.env["stock.move"] + .search( + [ + ("product_id", "=", receipt_move.product_id.id), + ("move_dest_ids", "=", receipt_move.id), + ] + ) + .production_id + ) + self.assertEqual( + production.analytic_distribution, receipt_move.analytic_distribution + ) + receipt_move.analytic_distribution = False + self.assertEqual(production.analytic_distribution, False) diff --git a/setup/mrp_subcontracting_analytic/odoo/addons/mrp_subcontracting_analytic b/setup/mrp_subcontracting_analytic/odoo/addons/mrp_subcontracting_analytic new file mode 120000 index 0000000000..683e3e111e --- /dev/null +++ b/setup/mrp_subcontracting_analytic/odoo/addons/mrp_subcontracting_analytic @@ -0,0 +1 @@ +../../../../mrp_subcontracting_analytic \ No newline at end of file diff --git a/setup/mrp_subcontracting_analytic/setup.py b/setup/mrp_subcontracting_analytic/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mrp_subcontracting_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)