Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] New module account_asset_utilities
- Loading branch information
Showing
10 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
=========================== | ||
Assets Management Utilities | ||
=========================== | ||
|
||
This module extends the functionality of Assets Management. | ||
|
||
* When an asset is created from an invoice, that asset will be linked to its | ||
invoice line. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/avanzosc/odoo-addons/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es> | ||
|
||
Do not contact contributors directly about support or help with technical issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Assets Management Utilities", | ||
"version": "11.0.1.0.0", | ||
"category": "Accounting", | ||
"license": "AGPL-3", | ||
"author": "AvanzOSC", | ||
"website": "http://www.avanzosc.es", | ||
"depends": [ | ||
"account_asset", | ||
], | ||
"data": [ | ||
"views/account_asset_view.xml", | ||
"views/account_invoice_view.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import account_asset | ||
from . import account_invoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class AccountAssetAsset(models.Model): | ||
_inherit = 'account.asset.asset' | ||
|
||
invoice_line_id = fields.Many2one( | ||
comodel_name='account.invoice.line', string='Invoice line') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tools.safe_eval import safe_eval | ||
from odoo import api, fields, models | ||
from odoo.osv import expression | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
def _compute_assets_count(self): | ||
for invoice in self: | ||
cond = [('invoice_id', '=', invoice.id)] | ||
invoice.assets_count = ( | ||
self.env['account.asset.asset'].search_count(cond)) | ||
|
||
assets_count = fields.Integer( | ||
string='Assets', compute='_compute_assets_count') | ||
|
||
def show_assets_from_invoice(self): | ||
res = {} | ||
if self.assets_count: | ||
action = self.env.ref( | ||
'account_asset.action_account_asset_asset_form') | ||
action_dict = action.read()[0] if action else {} | ||
new_domain = [('invoice_id', '=', self.id)] | ||
action_dict['domain'] = expression.AND( | ||
[new_domain, safe_eval(action_dict.get('domain', '[]'))]) | ||
return action_dict | ||
return res | ||
|
||
|
||
class AccountInvoiceLine(models.Model): | ||
_inherit = 'account.invoice.line' | ||
|
||
account_asset_ids = fields.One2many( | ||
comodel_name='account.asset.asset', string='Assets', | ||
inverse_name='invoice_line_id') | ||
|
||
@api.one | ||
def asset_create(self): | ||
return super(AccountInvoiceLine, | ||
self.with_context( | ||
default_invoice_line_id=self.id)).asset_create() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_account_asset_utilities |
69 changes: 69 additions & 0 deletions
69
account_asset_utilities/tests/test_account_asset_utilities.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright 2017 Oihane Crucelaegui - AvanzOSC | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.account_asset.tests.test_account_asset import TestAccountAsset | ||
from odoo.osv import expression | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
|
||
class TestAccountAssetUtilities(TestAccountAsset): | ||
|
||
def setUp(self): | ||
super(TestAccountAssetUtilities, self).setUp() | ||
self._load('account', 'test', 'account_minimal_test.xml') | ||
self._load('account_asset', 'test', 'account_asset_demo_test.xml') | ||
asset_category = self.browse_ref( | ||
'account_asset.account_asset_category_fixedassets_test0') | ||
|
||
partner = self.env['res.partner'].create({ | ||
'name': 'Test Partner', | ||
}) | ||
product = self.env['product.product'].create({ | ||
'name': 'Test Product', | ||
}) | ||
|
||
# Should be changed by automatic on_change later | ||
invoice_account = self.env['account.account'].search( | ||
[('user_type_id', '=', | ||
self.env.ref('account.data_account_type_receivable').id)], | ||
limit=1).id | ||
invoice_line_account = self.env['account.account'].search( | ||
[('user_type_id', '=', | ||
self.env.ref('account.data_account_type_expenses').id)], | ||
limit=1).id | ||
|
||
self.invoice = self.env['account.invoice'].create({ | ||
'partner_id': partner.id, | ||
'account_id': invoice_account, | ||
'type': 'in_invoice', | ||
}) | ||
|
||
self.invoice_line = self.env['account.invoice.line'].create({ | ||
'product_id': product.id, | ||
'quantity': 1.0, | ||
'price_unit': 100.0, | ||
'invoice_id': self.invoice.id, | ||
'name': 'product that cost 100', | ||
'account_id': invoice_line_account, | ||
'asset_category_id': asset_category.id, | ||
}) | ||
|
||
def test_account_asset_utilities(self): | ||
self.assertFalse(self.invoice_line.account_asset_ids) | ||
result = self.invoice.show_assets_from_invoice() | ||
self.assertEquals(result, {}) | ||
self.invoice.action_move_create() | ||
self.invoice.invalidate_cache() | ||
self.assertTrue(self.invoice_line.account_asset_ids) | ||
self.assertEquals( | ||
self.invoice.assets_count, | ||
len(self.invoice.mapped('invoice_line_ids.account_asset_ids'))) | ||
result = self.invoice.show_assets_from_invoice() | ||
action = self.env.ref( | ||
'account_asset.action_account_asset_asset_form') | ||
action_dict = action.read()[0] if action else {} | ||
new_domain = [('invoice_id', '=', self.invoice.id)] | ||
action_domain = expression.AND( | ||
[new_domain, safe_eval(action_dict.get('domain') or '[]')]) | ||
domain = result.get('domain') | ||
self.assertEquals(action_domain, domain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="account_asset_asset_form_view" model="ir.ui.view"> | ||
<field name="name">account.asset.asset.form</field> | ||
<field name="model">account.asset.asset</field> | ||
<field name="inherit_id" | ||
ref="account_asset.view_account_asset_asset_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_id" position="after"> | ||
<field name="invoice_line_id" options="{'no_create': True}" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="account_invoice_supplier_assets_form_view" model="ir.ui.view"> | ||
<field name="name">account.invoice.supplier.assets.form</field> | ||
<field name="model">account.invoice</field> | ||
<field name="inherit_id" ref="account.invoice_supplier_form" /> | ||
<field name="arch" type="xml"> | ||
<h1 position="before"> | ||
<div class="oe_button_box" name="button_box"> | ||
<button name="show_assets_from_invoice" | ||
type="object" class="oe_stat_button oe_inline" icon="fa-pencil"> | ||
<field name="assets_count" widget="statinfo" string="Assets"/> | ||
</button> | ||
</div> | ||
</h1> | ||
</field> | ||
</record> | ||
</odoo> |