diff --git a/account_asset_transfer_operating_unit/README.rst b/account_asset_transfer_operating_unit/README.rst new file mode 100644 index 0000000000..e25a07c451 --- /dev/null +++ b/account_asset_transfer_operating_unit/README.rst @@ -0,0 +1,82 @@ +================================ +Asset Transfer - Operating Units +================================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/15.0/account_asset_transfer_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-account_asset_transfer_operating_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/213/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds information about an operating unit to an asset transfer process. +Additionally, it will create a move that follows the operating unit specified in the asset transfer. + +**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 +~~~~~~~ + +* Ecosoft + +Contributors +~~~~~~~~~~~~ + +* Saran Lim. + +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-Saran440| image:: https://github.com/Saran440.png?size=40px + :target: https://github.com/Saran440 + :alt: Saran440 + +Current `maintainer `__: + +|maintainer-Saran440| + +This module is part of the `OCA/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_asset_transfer_operating_unit/__init__.py b/account_asset_transfer_operating_unit/__init__.py new file mode 100644 index 0000000000..14cd1b0579 --- /dev/null +++ b/account_asset_transfer_operating_unit/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard diff --git a/account_asset_transfer_operating_unit/__manifest__.py b/account_asset_transfer_operating_unit/__manifest__.py new file mode 100644 index 0000000000..c0ed825aaa --- /dev/null +++ b/account_asset_transfer_operating_unit/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Asset Transfer - Operating Units", + "summary": "Add operating unit to asset transfer", + "version": "15.0.1.0.0", + "license": "AGPL-3", + "depends": ["account_asset_transfer", "account_asset_operating_unit"], + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/operating-unit", + "category": "Accounting & Finance", + "data": ["wizard/account_asset_transfer.xml"], + "installable": True, + "auto_install": True, + "maintainers": ["Saran440"], + "development_status": "Alpha", +} diff --git a/account_asset_transfer_operating_unit/readme/CONTRIBUTORS.rst b/account_asset_transfer_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..cc6b23102b --- /dev/null +++ b/account_asset_transfer_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Saran Lim. diff --git a/account_asset_transfer_operating_unit/readme/DESCRIPTION.rst b/account_asset_transfer_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..893749ad2e --- /dev/null +++ b/account_asset_transfer_operating_unit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds information about an operating unit to an asset transfer process. +Additionally, it will create a move that follows the operating unit specified in the asset transfer. diff --git a/account_asset_transfer_operating_unit/static/description/index.html b/account_asset_transfer_operating_unit/static/description/index.html new file mode 100644 index 0000000000..b2504c699e --- /dev/null +++ b/account_asset_transfer_operating_unit/static/description/index.html @@ -0,0 +1,422 @@ + + + + + + +Asset Transfer - Operating Units + + + +
+

Asset Transfer - Operating Units

+ + +

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

+

This module adds information about an operating unit to an asset transfer process. +Additionally, it will create a move that follows the operating unit specified in the asset transfer.

+

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

+
    +
  • Ecosoft
  • +
+
+
+

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.

+

Current maintainer:

+

Saran440

+

This module is part of the OCA/operating-unit project on GitHub.

+

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

+
+
+
+ + diff --git a/account_asset_transfer_operating_unit/tests/__init__.py b/account_asset_transfer_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..05f7ca9e7e --- /dev/null +++ b/account_asset_transfer_operating_unit/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_asset_transfer_operating_unit diff --git a/account_asset_transfer_operating_unit/tests/test_asset_transfer_operating_unit.py b/account_asset_transfer_operating_unit/tests/test_asset_transfer_operating_unit.py new file mode 100644 index 0000000000..0abd5a4dd0 --- /dev/null +++ b/account_asset_transfer_operating_unit/tests/test_asset_transfer_operating_unit.py @@ -0,0 +1,64 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests import tagged +from odoo.tests.common import Form + +from odoo.addons.account_asset_operating_unit.tests.test_account_asset_operating_unit import ( + TestAccountAssetOperatingUnit, +) + + +@tagged("post_install", "-at_install") +class TestAssetTransferOperatingUnit(TestAccountAssetOperatingUnit): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Journal + cls.journal_misc_transfer = cls.env["account.journal"].search( + [("company_id", "=", cls.env.company.id), ("type", "=", "general")], limit=1 + ) + + def test_01_asset_transfer_auc_to_asset(self): + """Create AUC and then transfer to normal asset class, + I expect a new journal entry will be created""" + self.asset1.method_number = 0 + self.asset1.validate() + self.asset1.invalidate_cache() + # can_transfer = True after validate + self.assertTrue(list(set(self.asset1.mapped("can_transfer")))[0]) + + # Create Asset Transfer + with Form( + self.env["account.asset.transfer"].with_context(active_ids=self.asset1.ids) + ) as t: + t.transfer_journal_id = self.journal_misc_transfer + with t.to_asset_ids.new() as to_asset: + to_asset.asset_name = "Asset 1" + to_asset.asset_profile_id = self.profile_id + to_asset.quantity = 1 + to_asset.price_unit = 500 + to_asset.operating_unit_id = self.b2c_OU + with t.to_asset_ids.new() as to_asset: + to_asset.asset_name = "Asset 2" + to_asset.asset_profile_id = self.profile_id + to_asset.quantity = 1 + to_asset.price_unit = 500 + transfer_wiz = t.save() + # Test expand asset lines from quantity line + self.assertEqual(len(transfer_wiz.to_asset_ids), 2) + self.assertEqual(transfer_wiz.operating_unit_id, self.asset1.operating_unit_id) + self.assertEqual(transfer_wiz.to_asset_ids[0].operating_unit_id, self.b2c_OU) + self.assertEqual( + transfer_wiz.to_asset_ids[1].operating_unit_id, + self.asset1.operating_unit_id, + ) + res = transfer_wiz.transfer() + transfer_move = self.env["account.move"].browse(res["domain"][0][2]) + assets = transfer_move.invoice_line_ids.mapped("asset_id") + self.assertEqual(transfer_move.operating_unit_id, self.asset1.operating_unit_id) + # 2 new assets created, and value equal to original assets + new_assets = assets.filtered(lambda l: l.state == "draft") + self.assertEqual(sum(new_assets.mapped("purchase_value")), 1000) + self.assertEqual(new_assets.operating_unit_id, self.asset1.operating_unit_id) diff --git a/account_asset_transfer_operating_unit/wizard/__init__.py b/account_asset_transfer_operating_unit/wizard/__init__.py new file mode 100644 index 0000000000..d3a388ee18 --- /dev/null +++ b/account_asset_transfer_operating_unit/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_asset_transfer diff --git a/account_asset_transfer_operating_unit/wizard/account_asset_transfer.py b/account_asset_transfer_operating_unit/wizard/account_asset_transfer.py new file mode 100644 index 0000000000..b8f1e98bfe --- /dev/null +++ b/account_asset_transfer_operating_unit/wizard/account_asset_transfer.py @@ -0,0 +1,57 @@ +# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountAssetTransfer(models.TransientModel): + _inherit = "account.asset.transfer" + + operating_unit_id = fields.Many2one( + comodel_name="operating.unit", + string="Operating Unit", + ) + + @api.model + def default_get(self, field_list): + res = super().default_get(field_list) + from_asset_ids = self.env.context.get("active_ids") + assets = self.env["account.asset"].browse(from_asset_ids) + # Prepare default values + operating_unit_id = assets.mapped("operating_unit_id") + res["operating_unit_id"] = ( + operating_unit_id.id if len(operating_unit_id) == 1 else False + ) + return res + + def _get_new_move_transfer(self): + move_values = super()._get_new_move_transfer() + move_values["operating_unit_id"] = self.operating_unit_id.id + return move_values + + def _get_move_line_from_asset(self, move_line): + move_lines = super()._get_move_line_from_asset(move_line) + move_lines["operating_unit_id"] = move_line.operating_unit_id.id + return move_lines + + def _get_move_line_to_asset(self, to_asset): + move_lines = super()._get_move_line_to_asset(to_asset) + move_lines["operating_unit_id"] = (to_asset.operating_unit_id.id,) + return move_lines + + +class AccountAssetTransferLine(models.TransientModel): + _inherit = "account.asset.transfer.line" + + operating_unit_id = fields.Many2one( + comodel_name="operating.unit", + compute="_compute_asset_transfer_operating_unit", + readonly=False, + store=True, + string="Operating Unit", + ) + + @api.depends("transfer_id.operating_unit_id") + def _compute_asset_transfer_operating_unit(self): + for rec in self: + rec.operating_unit_id = rec.transfer_id.operating_unit_id diff --git a/account_asset_transfer_operating_unit/wizard/account_asset_transfer.xml b/account_asset_transfer_operating_unit/wizard/account_asset_transfer.xml new file mode 100644 index 0000000000..f6c8fc292a --- /dev/null +++ b/account_asset_transfer_operating_unit/wizard/account_asset_transfer.xml @@ -0,0 +1,31 @@ + + + + account.asset.transfer.form + account.asset.transfer + + + + + + + + + + + ['|', ('operating_unit_ids', '=', operating_unit_id), + ('operating_unit_ids', '=', False)] + + + + + diff --git a/setup/account_asset_transfer_operating_unit/odoo/addons/account_asset_transfer_operating_unit b/setup/account_asset_transfer_operating_unit/odoo/addons/account_asset_transfer_operating_unit new file mode 120000 index 0000000000..e04386c23a --- /dev/null +++ b/setup/account_asset_transfer_operating_unit/odoo/addons/account_asset_transfer_operating_unit @@ -0,0 +1 @@ +../../../../account_asset_transfer_operating_unit \ No newline at end of file diff --git a/setup/account_asset_transfer_operating_unit/setup.py b/setup/account_asset_transfer_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_asset_transfer_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)