[ADD] account_asset_pms: Allow to set pms property in assets

This commit is contained in:
Omar (Comunitea)
2022-12-18 10:53:08 +01:00
committed by Darío Lodeiros
parent 2dcb707a7b
commit c786ba3b4e
18 changed files with 248 additions and 0 deletions

View File

View File

@@ -0,0 +1,2 @@
from . import models
from . import report

View File

@@ -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,
}

View File

@@ -0,0 +1,3 @@
from . import account_asset
from . import account_asset_line
from . import account_move

View File

@@ -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"]

View File

@@ -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()

View File

@@ -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

View File

@@ -0,0 +1 @@
* Omar Castiñeira <omar@comunitea.com>

View File

@@ -0,0 +1 @@
This module adds PMS property information to assets.

View File

@@ -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.

View File

@@ -0,0 +1 @@
from . import account_asset_report_xls

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1 @@
from . import test_account_asset_pms_property

View File

@@ -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)

View File

@@ -0,0 +1,31 @@
<odoo>
<record id="account_asset_view_form_add_pms_property" model="ir.ui.view">
<field name="name">account.asset.form.add_pms_property</field>
<field name="model">account.asset</field>
<field
name="inherit_id"
ref="account_asset_management.account_asset_view_form"
/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="pms_property_id" />
</field>
</field>
</record>
<record id="account_asset_view_tree_add_pms_property" model="ir.ui.view">
<field name="name">account.asset.tree.add_pms_property</field>
<field name="model">account.asset</field>
<field
name="inherit_id"
ref="account_asset_management.account_asset_view_tree"
/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="pms_property_id" optional="hide" />
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
../../../../account_asset_pms

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)