diff --git a/account_asset_pms/README.rst b/account_asset_pms/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/account_asset_pms/__init__.py b/account_asset_pms/__init__.py new file mode 100644 index 000000000..bf588bc8b --- /dev/null +++ b/account_asset_pms/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import report diff --git a/account_asset_pms/__manifest__.py b/account_asset_pms/__manifest__.py new file mode 100644 index 000000000..45dc7278a --- /dev/null +++ b/account_asset_pms/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Assets Management PMS", + "summary": "Add property in assets configuration", + "version": "14.0.1.0.0", + "development_status": "Beta", + "category": "Accounting & Finance", + "website": "https://github.com/OCA/pms", + "author": "Comunitea, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["account_asset_management", "pms"], + "data": [ + "views/account_asset_view.xml", + ], + "auto_install": True, +} diff --git a/account_asset_pms/models/__init__.py b/account_asset_pms/models/__init__.py new file mode 100644 index 000000000..a087b4f62 --- /dev/null +++ b/account_asset_pms/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_asset +from . import account_asset_line +from . import account_move diff --git a/account_asset_pms/models/account_asset.py b/account_asset_pms/models/account_asset.py new file mode 100644 index 000000000..90ee118d1 --- /dev/null +++ b/account_asset_pms/models/account_asset.py @@ -0,0 +1,30 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountAsset(models.Model): + _inherit = "account.asset" + _check_pms_properties_auto = True + + pms_property_id = fields.Many2one( + name="Property", + comodel_name="pms.property", + check_pms_properties=True, + ) + + @api.model + def _xls_acquisition_fields(self): + res = super()._xls_acquisition_fields() + return res + ["pms_property_id"] + + @api.model + def _xls_active_fields(self): + res = super()._xls_active_fields() + return res + ["pms_property_id"] + + @api.model + def _xls_removal_fields(self): + res = super()._xls_removal_fields() + return res + ["pms_property_id"] diff --git a/account_asset_pms/models/account_asset_line.py b/account_asset_pms/models/account_asset_line.py new file mode 100644 index 000000000..c1f8b2b91 --- /dev/null +++ b/account_asset_pms/models/account_asset_line.py @@ -0,0 +1,14 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountAssetLine(models.Model): + _inherit = "account.asset.line" + + def create_move(self): + return super( + AccountAssetLine, + self.with_context(force_pms_property=self.asset_id.pms_property_id.id), + ).create_move() diff --git a/account_asset_pms/models/account_move.py b/account_asset_pms/models/account_move.py new file mode 100644 index 000000000..734eeddd4 --- /dev/null +++ b/account_asset_pms/models/account_move.py @@ -0,0 +1,13 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _prepare_asset_vals(self, aml): + res = super()._prepare_asset_vals(aml) + res.update({"pms_property_id": aml.pms_property_id or self.pms_property_id}) + return res diff --git a/account_asset_pms/readme/CONTRIBUTORS.rst b/account_asset_pms/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..35552577f --- /dev/null +++ b/account_asset_pms/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Omar Castiñeira diff --git a/account_asset_pms/readme/DESCRIPTION.rst b/account_asset_pms/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c83788919 --- /dev/null +++ b/account_asset_pms/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds PMS property information to assets. diff --git a/account_asset_pms/readme/USAGE.rst b/account_asset_pms/readme/USAGE.rst new file mode 100644 index 000000000..21edfc94f --- /dev/null +++ b/account_asset_pms/readme/USAGE.rst @@ -0,0 +1,3 @@ +* Go to Invoicing > Assets > Assets +* Assets can be realated to pms property that will be passed to depreciations moves. +* If asset is created from invoice, PMS property of invoice will be passed to. diff --git a/account_asset_pms/report/__init__.py b/account_asset_pms/report/__init__.py new file mode 100644 index 000000000..2a46ed581 --- /dev/null +++ b/account_asset_pms/report/__init__.py @@ -0,0 +1 @@ +from . import account_asset_report_xls diff --git a/account_asset_pms/report/account_asset_report_xls.py b/account_asset_pms/report/account_asset_report_xls.py new file mode 100644 index 000000000..1e8ec1e5e --- /dev/null +++ b/account_asset_pms/report/account_asset_report_xls.py @@ -0,0 +1,26 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AssetReportXlsx(models.AbstractModel): + _inherit = "report.account_asset_management.asset_report_xls" + + def _get_asset_template(self): + asset_template = super()._get_asset_template() + asset_template.update( + { + "pms_property": { + "header": {"type": "string", "value": self._("PMS Property")}, + "asset": { + "type": "string", + "value": self._render( + "asset.pms_property_id.display_name or ''" + ), + }, + "width": 20, + } + } + ) + return asset_template diff --git a/account_asset_pms/static/description/icon.png b/account_asset_pms/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_asset_pms/static/description/icon.png differ diff --git a/account_asset_pms/tests/__init__.py b/account_asset_pms/tests/__init__.py new file mode 100644 index 000000000..e36864580 --- /dev/null +++ b/account_asset_pms/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_asset_pms_property diff --git a/account_asset_pms/tests/test_account_asset_pms_property.py b/account_asset_pms/tests/test_account_asset_pms_property.py new file mode 100644 index 000000000..dfa359685 --- /dev/null +++ b/account_asset_pms/tests/test_account_asset_pms_property.py @@ -0,0 +1,96 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import time + +from odoo.tests import common + + +class TestAccountAssetPmsProperty(common.TransactionCase): + def setUp(self): + super(TestAccountAssetPmsProperty, self).setUp() + self.AccountAccount = self.env["account.account"] + self.AccountAsset = self.env["account.asset"] + self.ResUsers = self.env["res.users"] + self.product_id = self.env["product.template"].search( + [("type", "=", "service")], limit=1 + ) + # Groups + self.grp_account_manager = self.env.ref("account.group_account_manager") + self.group_user = self.env.ref("base.group_user") + # Company + self.company = self.env.ref("base.main_company") + # Pricelist + self.pricelist = self.env["product.pricelist"].create( + { + "name": "Pricelist", + } + ) + # Property + self.pms_property = self.env["pms.property"].create( + { + "name": "Pms_property_test", + "company_id": self.company.id, + "default_pricelist_id": self.pricelist.id, + } + ) + # Accounts + self.account_expense = self.AccountAccount.search( + [ + ("company_id", "=", self.company.id), + ( + "user_type_id", + "=", + self.env.ref("account.data_account_type_expenses").id, + ), + ], + limit=1, + ) + self.account_asset = self.env["account.account"].search( + [ + ("company_id", "=", self.company.id), + ( + "user_type_id", + "=", + self.env.ref("account.data_account_type_current_assets").id, + ), + ], + limit=1, + ) + # Journal + self.journal_purchase = self.env["account.journal"].search( + [("company_id", "=", self.company.id), ("type", "=", "purchase")], limit=1 + ) + # Asset Profile + self.profile_id = self.env["account.asset.profile"].create( + { + "account_expense_depreciation_id": self.account_expense.id, + "account_asset_id": self.account_asset.id, + "account_depreciation_id": self.account_asset.id, + "journal_id": self.journal_purchase.id, + "name": "Hardware - 3 Years", + "method_time": "year", + "method_number": 3, + "method_period": "year", + } + ) + self.asset1 = self._create_asset(self.pms_property) + + def _create_asset(self, pms_property): + asset = self.AccountAsset.create( + { + "name": "Test Asset", + "profile_id": self.profile_id.id, + "purchase_value": 1000, + "salvage_value": 0, + "date_start": time.strftime("%Y-01-01"), + "method_time": "year", + "method_number": 3, + "method_period": "month", + "pms_property_id": pms_property.id, + } + ) + return asset + + def test_asset(self): + self.assertEqual(self.asset1.pms_property_id.id, self.pms_property.id) diff --git a/account_asset_pms/views/account_asset_view.xml b/account_asset_pms/views/account_asset_view.xml new file mode 100644 index 000000000..78d9ae5b5 --- /dev/null +++ b/account_asset_pms/views/account_asset_view.xml @@ -0,0 +1,31 @@ + + + + account.asset.form.add_pms_property + account.asset + + + + + + + + + + account.asset.tree.add_pms_property + account.asset + + + + + + + + + diff --git a/setup/account_asset_pms/odoo/addons/account_asset_pms b/setup/account_asset_pms/odoo/addons/account_asset_pms new file mode 120000 index 000000000..69f0f3515 --- /dev/null +++ b/setup/account_asset_pms/odoo/addons/account_asset_pms @@ -0,0 +1 @@ +../../../../account_asset_pms \ No newline at end of file diff --git a/setup/account_asset_pms/setup.py b/setup/account_asset_pms/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_asset_pms/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)