mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] account_asset_pms: Allow to set pms property in assets
This commit is contained in:
committed by
Darío Lodeiros
parent
2dcb707a7b
commit
c786ba3b4e
0
account_asset_pms/README.rst
Normal file
0
account_asset_pms/README.rst
Normal file
2
account_asset_pms/__init__.py
Normal file
2
account_asset_pms/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import models
|
||||||
|
from . import report
|
||||||
19
account_asset_pms/__manifest__.py
Normal file
19
account_asset_pms/__manifest__.py
Normal 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,
|
||||||
|
}
|
||||||
3
account_asset_pms/models/__init__.py
Normal file
3
account_asset_pms/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from . import account_asset
|
||||||
|
from . import account_asset_line
|
||||||
|
from . import account_move
|
||||||
30
account_asset_pms/models/account_asset.py
Normal file
30
account_asset_pms/models/account_asset.py
Normal 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"]
|
||||||
14
account_asset_pms/models/account_asset_line.py
Normal file
14
account_asset_pms/models/account_asset_line.py
Normal 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()
|
||||||
13
account_asset_pms/models/account_move.py
Normal file
13
account_asset_pms/models/account_move.py
Normal 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
|
||||||
1
account_asset_pms/readme/CONTRIBUTORS.rst
Normal file
1
account_asset_pms/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Omar Castiñeira <omar@comunitea.com>
|
||||||
1
account_asset_pms/readme/DESCRIPTION.rst
Normal file
1
account_asset_pms/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This module adds PMS property information to assets.
|
||||||
3
account_asset_pms/readme/USAGE.rst
Normal file
3
account_asset_pms/readme/USAGE.rst
Normal 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.
|
||||||
1
account_asset_pms/report/__init__.py
Normal file
1
account_asset_pms/report/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import account_asset_report_xls
|
||||||
26
account_asset_pms/report/account_asset_report_xls.py
Normal file
26
account_asset_pms/report/account_asset_report_xls.py
Normal 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
|
||||||
BIN
account_asset_pms/static/description/icon.png
Normal file
BIN
account_asset_pms/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
1
account_asset_pms/tests/__init__.py
Normal file
1
account_asset_pms/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_account_asset_pms_property
|
||||||
96
account_asset_pms/tests/test_account_asset_pms_property.py
Normal file
96
account_asset_pms/tests/test_account_asset_pms_property.py
Normal 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)
|
||||||
31
account_asset_pms/views/account_asset_view.xml
Normal file
31
account_asset_pms/views/account_asset_view.xml
Normal 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>
|
||||||
1
setup/account_asset_pms/odoo/addons/account_asset_pms
Symbolic link
1
setup/account_asset_pms/odoo/addons/account_asset_pms
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../../account_asset_pms
|
||||||
6
setup/account_asset_pms/setup.py
Normal file
6
setup/account_asset_pms/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user