Skip to content

Commit

Permalink
[ENH] account_asset_transfer: add feature expand asset line
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-tubtim authored and Saran440 committed Oct 18, 2022
1 parent b4ba942 commit 5830d24
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
2 changes: 2 additions & 0 deletions account_asset_transfer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Given asset under construction has been created, i.e., by vendor bill.
- Click "Transfer" button
- Odoo will create journal entry as well as new asset(s)

**Note:** You can click "Expand Asset" button for expand asset line that selects the asset profile set to be "Create an asset by product item"

Bug Tracker
===========

Expand Down
2 changes: 2 additions & 0 deletions account_asset_transfer/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Given asset under construction has been created, i.e., by vendor bill.
- On asset transfer wizard, on the "To New Asset" tab, choose new profile(s)
- Click "Transfer" button
- Odoo will create journal entry as well as new asset(s)

**Note:** You can click "Expand Asset" button for expand asset line that selects the asset profile set to be "Create an asset by product item"
3 changes: 2 additions & 1 deletion account_asset_transfer/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Asset Transfer from AUC to Asset</title>
<style type="text/css">

Expand Down Expand Up @@ -405,6 +405,7 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
<li>Click “Transfer” button</li>
<li>Odoo will create journal entry as well as new asset(s)</li>
</ul>
<p><strong>Note:</strong> You can click “Expand Asset” button for expand asset line that selects the asset profile set to be “Create an asset by product item”</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
Expand Down
12 changes: 10 additions & 2 deletions account_asset_transfer/tests/test_account_asset_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUpClass(cls):
].id,
"journal_id": cls.company_data["default_journal_purchase"].id,
"transfer_journal_id": cls.company_data["default_journal_misc"].id,
"asset_product_item": True,
"name": "Asset Under Construction",
"method_time": "year",
"method_number": 0,
Expand All @@ -47,6 +48,7 @@ def setUpClass(cls):
"default_account_assets"
].id,
"journal_id": cls.company_data["default_journal_purchase"].id,
"asset_product_item": True,
"name": "Room - 5 Years",
"method_time": "year",
"method_number": 5,
Expand Down Expand Up @@ -110,12 +112,18 @@ def test_01_asset_transfer_auc_to_asset(self):
with transfer_form.to_asset_ids.new() as to_asset:
to_asset.asset_name = "Asset 1"
to_asset.asset_profile_id = self.profile_asset
to_asset.asset_value = 3000
to_asset.quantity = 6
to_asset.price_unit = 500
with transfer_form.to_asset_ids.new() as to_asset:
to_asset.asset_name = "Asset 2"
to_asset.asset_profile_id = self.profile_asset
to_asset.asset_value = 20000
to_asset.quantity = 1
to_asset.price_unit = 20000
transfer_form.save()
# Test expand asset lines from quantity line
self.assertEqual(len(transfer_wiz.to_asset_ids), 2)
transfer_wiz.expand_to_asset_ids()
self.assertEqual(len(transfer_wiz.to_asset_ids), 7)
res = transfer_wiz.transfer()
transfer_move = self.env["account.move"].browse(res["domain"][0][2])
assets = transfer_move.invoice_line_ids.mapped("asset_id")
Expand Down
40 changes: 39 additions & 1 deletion account_asset_transfer/wizard/account_asset_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ def _get_transfer_data(self):
]
return move_lines

def expand_to_asset_ids(self):
self.ensure_one()
lines = self.to_asset_ids.filtered(lambda l: l.asset_profile_id and l.quantity)
for line in lines:
line._expand_asset_line()
action = self.env.ref("account_asset_transfer.action_account_asset_transfer")
result = action.sudo().read()[0]
result.update({"res_id": self.id})
return result


class AccountAssetTransferLine(models.TransientModel):
_name = "account.asset.transfer.line"
Expand All @@ -212,10 +222,22 @@ class AccountAssetTransferLine(models.TransientModel):
required=True,
)
asset_name = fields.Char(required=True)
quantity = fields.Float(
string="Quantity",
required=True,
default=0.0,
)
price_unit = fields.Float(
string="Unit Price",
required=True,
default=0.0,
)
asset_value = fields.Float(
string="Asset Value",
required=True,
compute="_compute_asset_value",
default=0.0,
store=True,
required=True,
)
partner_id = fields.Many2one(
comodel_name="res.partner",
Expand All @@ -229,3 +251,19 @@ class AccountAssetTransferLine(models.TransientModel):
comodel_name="account.analytic.tag",
string="Analytic tags",
)

@api.depends("quantity", "price_unit")
def _compute_asset_value(self):
for rec in self:
rec.asset_value = rec.quantity * rec.price_unit

def _expand_asset_line(self):
self.ensure_one()
profile = self.asset_profile_id
if profile and self.quantity > 1.0 and profile.asset_product_item:
line = self
qty = self.quantity
name = self.asset_name
self.update({"quantity": 1, "asset_name": "{} {}".format(name, 1)})
for i in range(1, int(qty)):
line.copy({"asset_name": "{} {}".format(name, i + 1)})
17 changes: 17 additions & 0 deletions account_asset_transfer/wizard/account_asset_transfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
</group>
<notebook>
<page name="to_asset" string="To New Asset">
<div class="oe_right" name="buttons">
<button
name="expand_to_asset_ids"
type="object"
string="Expand Asset"
icon="fa-bars"
/>
</div>
<field
name="to_asset_ids"
context="{
Expand All @@ -35,6 +43,8 @@
<tree editable="bottom">
<field name="asset_profile_id" />
<field name="asset_name" />
<field name="price_unit" />
<field name="quantity" />
<field name="asset_value" />
<field name="partner_id" />
<field
Expand Down Expand Up @@ -69,6 +79,13 @@
</field>
</record>

<record id="action_account_asset_transfer" model="ir.actions.act_window">
<field name="name">Transfer Asset</field>
<field name="res_model">account.asset.transfer</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<record id="action_asset_transfer_from_list" model="ir.actions.server">
<field name="name">Transfer Asset</field>
<field name="groups_id" eval="[(4, ref('account.group_account_manager'))]" />
Expand Down

0 comments on commit 5830d24

Please sign in to comment.