mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[ENH] add source/dest asset when transfer asset
This commit is contained in:
@@ -13,6 +13,9 @@ class AccountAsset(models.Model):
|
||||
search="_search_can_transfer",
|
||||
help="Allow transfer AUC (running) to Asset",
|
||||
)
|
||||
is_transfer = fields.Boolean(
|
||||
help="flag indicating if the asset has been transferred from/to another asset."
|
||||
)
|
||||
|
||||
def _compute_can_transfer(self):
|
||||
for asset in self:
|
||||
@@ -56,3 +59,36 @@ class AccountAsset(models.Model):
|
||||
"type": "ir.actions.act_window",
|
||||
"context": ctx,
|
||||
}
|
||||
|
||||
def open_assets(self):
|
||||
self.ensure_one()
|
||||
moves = self.account_move_line_ids.mapped("move_id")
|
||||
assets = self.env["account.asset"]
|
||||
asset_from = self._context.get("asset_from")
|
||||
asset_to = self._context.get("asset_to")
|
||||
for move in moves:
|
||||
# Source Assets, we check from move that create this asset
|
||||
if (
|
||||
asset_from
|
||||
and self.id
|
||||
not in move.line_ids.filtered(lambda l: l.credit).mapped("asset_id").ids
|
||||
):
|
||||
assets = move.line_ids.filtered(lambda l: l.credit).mapped("asset_id")
|
||||
break
|
||||
# Destination Assets, we check from move that create destination asset
|
||||
elif (
|
||||
asset_to
|
||||
and self.id
|
||||
in move.line_ids.filtered(lambda l: l.credit).mapped("asset_id").ids
|
||||
):
|
||||
assets = move.line_ids.filtered(lambda l: l.debit).mapped("asset_id")
|
||||
break
|
||||
return {
|
||||
"name": _("Assets"),
|
||||
"view_mode": "tree,form",
|
||||
"res_model": "account.asset",
|
||||
"view_id": False,
|
||||
"type": "ir.actions.act_window",
|
||||
"context": self._context,
|
||||
"domain": [("id", "in", assets.ids)],
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
|
||||
* Kitti U. <kittiu@ecosoft.co.th>
|
||||
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
|
||||
* Saran Lim. <saranl@ecosoft.co.th>
|
||||
|
||||
@@ -2,7 +2,7 @@ Given asset under construction has been created, i.e., by vendor bill.
|
||||
|
||||
- Go to asset menu
|
||||
- Filter "Transferrable" assets and look for desired assets to transfer
|
||||
- Select assets to transfer, and click actoin "Transfer Asset"
|
||||
- Select assets to transfer, and click action "Transfer Asset"
|
||||
- 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)
|
||||
|
||||
@@ -101,7 +101,9 @@ class TestAccountAssetTransfer(TestAssetManagement):
|
||||
assets.invalidate_cache()
|
||||
# can_transfer = True after validate
|
||||
self.assertTrue(list(set(assets.mapped("can_transfer")))[0])
|
||||
|
||||
self.assertEqual(list(set(assets.mapped("is_transfer"))), [False])
|
||||
# Keep source asset
|
||||
source_assets = assets
|
||||
# Create Asset Transfer
|
||||
transfer_form = Form(
|
||||
self.env["account.asset.transfer"].with_context(active_ids=assets.ids)
|
||||
@@ -130,3 +132,11 @@ class TestAccountAssetTransfer(TestAssetManagement):
|
||||
# 2 new assets created, and value equal to original assets
|
||||
new_assets = assets.filtered(lambda l: l.state == "draft")
|
||||
self.assertEqual(sum(new_assets.mapped("purchase_value")), 23000)
|
||||
# All asset transfer will change to is_transfer
|
||||
self.assertEqual(list(set(assets.mapped("is_transfer"))), [True])
|
||||
# Check source asset from new asset
|
||||
result = new_assets[0].with_context(asset_from=1).open_assets()
|
||||
self.assertEqual(sorted(result["domain"][0][2]), source_assets.ids)
|
||||
# Check dest asset from source asset
|
||||
result = source_assets[0].with_context(asset_to=1).open_assets()
|
||||
self.assertEqual(result["domain"][0][2], new_assets.ids)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="account_asset_view_form">
|
||||
<record id="account_asset_view_form" model="ir.ui.view">
|
||||
<field name="name">account.asset.form</field>
|
||||
<field name="model">account.asset</field>
|
||||
<field
|
||||
@@ -10,6 +10,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<button name="remove" position="after">
|
||||
<field name="can_transfer" invisible="1" />
|
||||
<field name="is_transfer" invisible="1" />
|
||||
<button
|
||||
name="transfer"
|
||||
string="Transfer"
|
||||
@@ -24,11 +25,34 @@
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
style="margin-bottom:0px;"
|
||||
attrs="{'invisible': ['|', ('can_transfer', '=', 'False'), ('account_move_line_ids', '!=', [])]}"
|
||||
attrs="{'invisible': ['|', ('can_transfer', '=', False), ('account_move_line_ids', '!=', [])]}"
|
||||
>
|
||||
There are no journal entries on current asset(s), asset transfer will use account settings from the asset/asset profile instead.
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="//div[@name='button_box']/button[@name='open_entries']"
|
||||
position="before"
|
||||
>
|
||||
<button
|
||||
name="open_assets"
|
||||
string="Asset From"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
context="{'asset_from': 1}"
|
||||
attrs="{'invisible': [('is_transfer', '=', False)]}"
|
||||
icon="fa-bars"
|
||||
/>
|
||||
<button
|
||||
name="open_assets"
|
||||
string="Asset To"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
context="{'asset_to': 1}"
|
||||
attrs="{'invisible': [('is_transfer', '=', False)]}"
|
||||
icon="fa-bars"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class AccountAssetTransfer(models.TransientModel):
|
||||
balance = rec.from_asset_value - rec.to_asset_value
|
||||
rec.balance = balance if balance > 0 else 0
|
||||
|
||||
def _check_amount_trasnfer(self):
|
||||
def _check_amount_transfer(self):
|
||||
self.ensure_one()
|
||||
if float_compare(self.from_asset_value, self.to_asset_value, 2) != 0:
|
||||
raise UserError(_("Total values of new assets must equal to source assets"))
|
||||
@@ -120,7 +120,7 @@ class AccountAssetTransfer(models.TransientModel):
|
||||
def transfer(self):
|
||||
self.ensure_one()
|
||||
self.from_asset_ids._check_can_transfer()
|
||||
self._check_amount_trasnfer()
|
||||
self._check_amount_transfer()
|
||||
# Create transfer journal entry
|
||||
move_vals = self._get_new_move_transfer()
|
||||
move = self.env["account.move"].create(move_vals)
|
||||
@@ -132,6 +132,8 @@ class AccountAssetTransfer(models.TransientModel):
|
||||
self.from_asset_ids.write(
|
||||
{"state": "removed", "date_remove": self.date_transfer}
|
||||
)
|
||||
# Set all assets is transfer document
|
||||
move.line_ids.mapped("asset_id").write({"is_transfer": True})
|
||||
return {
|
||||
"name": _("Asset Transfer Journal Entry"),
|
||||
"view_mode": "tree,form",
|
||||
|
||||
Reference in New Issue
Block a user