[ENH] account_asset_transfer: add feature expand asset line

This commit is contained in:
ps-tubtim
2022-10-05 17:47:11 +07:00
committed by Saran440
parent e7d2e57a60
commit 8c5195d13e
6 changed files with 73 additions and 5 deletions

View File

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

View File

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

View File

@@ -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">
@@ -405,6 +405,7 @@ cost would be transferred to final asset</p>
<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>

View File

@@ -29,6 +29,7 @@ class TestAccountAssetTransfer(TestAssetManagement):
].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,
@@ -47,6 +48,7 @@ class TestAccountAssetTransfer(TestAssetManagement):
"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,
@@ -110,12 +112,18 @@ class TestAccountAssetTransfer(TestAssetManagement):
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")

View File

@@ -197,6 +197,16 @@ class AccountAssetTransfer(models.TransientModel):
]
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"
@@ -212,11 +222,23 @@ class AccountAssetTransferLine(models.TransientModel):
required=True,
)
asset_name = fields.Char(required=True)
asset_value = fields.Float(
string="Asset Value",
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",
compute="_compute_asset_value",
default=0.0,
store=True,
required=True,
)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Partner",
@@ -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)})

View File

@@ -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="{
@@ -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
@@ -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'))]" />