[ENH] account_asset_transfer: allow transfer asset without moves

This commit is contained in:
ps-tubtim
2022-06-06 13:41:23 +07:00
committed by Saran440
parent c29e35cf3e
commit 264349eda3
8 changed files with 82 additions and 35 deletions

View File

@@ -31,6 +31,10 @@ AUC is Asset under construction where some assets are in construction phase and
cost needs to be captured for the time being. Once asset is fully completed then cost needs to be captured for the time being. Once asset is fully completed then
cost would be transferred to final asset cost would be transferred to final asset
**Note:**
* If the asset don't have journal entries, asset transfer will use account settings from the asset/asset profile instead.
**Table of contents** **Table of contents**
.. contents:: .. contents::
@@ -77,6 +81,7 @@ Contributors
* `Ecosoft <http://ecosoft.co.th>`__: * `Ecosoft <http://ecosoft.co.th>`__:
* Kitti U. <kittiu@ecosoft.co.th> * Kitti U. <kittiu@ecosoft.co.th>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@@ -20,7 +20,6 @@ class AccountAsset(models.Model):
not asset.method_number not asset.method_number
and asset.value_residual and asset.value_residual
and asset.state == "open" and asset.state == "open"
and asset.account_move_line_ids
) )
def _search_can_transfer(self, operator, value): def _search_can_transfer(self, operator, value):
@@ -29,7 +28,6 @@ class AccountAsset(models.Model):
("method_number", "=", 0), ("method_number", "=", 0),
("value_residual", ">", 0), ("value_residual", ">", 0),
("state", "=", "open"), ("state", "=", "open"),
("account_move_line_ids", "!=", False),
] ]
if operator == "!=": if operator == "!=":
return [ return [
@@ -39,7 +37,6 @@ class AccountAsset(models.Model):
("method_number", ">", 0), ("method_number", ">", 0),
("value_residual", "=", 0), ("value_residual", "=", 0),
("state", "!=", "open"), ("state", "!=", "open"),
("account_move_line_ids", "=", False),
] ]
def _check_can_transfer(self): def _check_can_transfer(self):

View File

@@ -1,3 +1,4 @@
* `Ecosoft <http://ecosoft.co.th>`__: * `Ecosoft <http://ecosoft.co.th>`__:
* Kitti U. <kittiu@ecosoft.co.th> * Kitti U. <kittiu@ecosoft.co.th>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>

View File

@@ -3,3 +3,7 @@ This module allow transferring assets under construction (AUC) to normal assets.
AUC is Asset under construction where some assets are in construction phase and AUC is Asset under construction where some assets are in construction phase and
cost needs to be captured for the time being. Once asset is fully completed then cost needs to be captured for the time being. Once asset is fully completed then
cost would be transferred to final asset cost would be transferred to final asset
**Note:**
* If the asset don't have journal entries, asset transfer will use account settings from the asset/asset profile instead.

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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> <title>Asset Transfer from AUC to Asset</title>
<style type="text/css"> <style type="text/css">
@@ -372,6 +372,10 @@ ul.auto-toc {
<p>AUC is Asset under construction where some assets are in construction phase and <p>AUC is Asset under construction where some assets are in construction phase and
cost needs to be captured for the time being. Once asset is fully completed then cost needs to be captured for the time being. Once asset is fully completed then
cost would be transferred to final asset</p> cost would be transferred to final asset</p>
<p><strong>Note:</strong></p>
<ul class="simple">
<li>If the asset dont have journal entries, asset transfer will use account settings from the asset/asset profile instead.</li>
</ul>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
@@ -423,6 +427,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple"> <ul class="simple">
<li><a class="reference external" href="http://ecosoft.co.th">Ecosoft</a>:<ul> <li><a class="reference external" href="http://ecosoft.co.th">Ecosoft</a>:<ul>
<li>Kitti U. &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li> <li>Kitti U. &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@@ -18,7 +18,7 @@ class TestAccountAssetTransfer(TestAssetManagement):
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
# Profile Under Construction # Profile Under Construction
cls.profile_uac = cls.asset_profile_model.create( cls.profile_auc = cls.asset_profile_model.create(
{ {
"account_expense_depreciation_id": cls.company_data[ "account_expense_depreciation_id": cls.company_data[
"default_account_expense" "default_account_expense"
@@ -54,10 +54,10 @@ class TestAccountAssetTransfer(TestAssetManagement):
} }
) )
def test_01_asset_transfer_uac_to_asset(self): def test_01_asset_transfer_auc_to_asset(self):
"""Create UAC and then transfer to normal asset class, """Create AUC and then transfer to normal asset class,
I expect a new journal entry will be created""" I expect a new journal entry will be created"""
# Create 3 UAC assets from an invoice # Create 3 AUC assets from an invoice
move_form = Form( move_form = Form(
self.env["account.move"].with_context( self.env["account.move"].with_context(
default_move_type="in_invoice", check_move_validity=False default_move_type="in_invoice", check_move_validity=False
@@ -68,22 +68,32 @@ class TestAccountAssetTransfer(TestAssetManagement):
with move_form.invoice_line_ids.new() as line_form: with move_form.invoice_line_ids.new() as line_form:
line_form.name = "Wall" line_form.name = "Wall"
line_form.price_unit = 2000.00 line_form.price_unit = 2000.00
line_form.asset_profile_id = self.profile_uac line_form.asset_profile_id = self.profile_auc
with move_form.invoice_line_ids.new() as line_form: with move_form.invoice_line_ids.new() as line_form:
line_form.name = "Roof" line_form.name = "Roof"
line_form.price_unit = 10000.00 line_form.price_unit = 10000.00
line_form.asset_profile_id = self.profile_uac line_form.asset_profile_id = self.profile_auc
with move_form.invoice_line_ids.new() as line_form: with move_form.invoice_line_ids.new() as line_form:
line_form.name = "Floor" line_form.name = "Floor"
line_form.price_unit = 10000.00 line_form.price_unit = 10000.00
line_form.asset_profile_id = self.profile_uac line_form.asset_profile_id = self.profile_auc
self.invoice_uac = move_form.save() self.invoice_auc = move_form.save()
self.invoice_uac.invoice_line_ids.write( self.invoice_auc.invoice_line_ids.write(
{"asset_profile_id": self.profile_uac.id} {"asset_profile_id": self.profile_auc.id}
) )
self.invoice_uac.action_post() self.invoice_auc.action_post()
# Test can can_review status # Create AUC asset without move
assets = self.invoice_uac.invoice_line_ids.mapped("asset_id") asset_auc = self.env["account.asset"].create(
{
"name": "Door",
"profile_id": self.profile_auc.id,
"purchase_value": 1000,
"date_start": fields.Date.context_today(self.env.user),
}
)
# Test can_transfer status
assets = self.invoice_auc.invoice_line_ids.mapped("asset_id")
assets += asset_auc
self.assertFalse(list(set(assets.mapped("can_transfer")))[0]) self.assertFalse(list(set(assets.mapped("can_transfer")))[0])
assets.validate() assets.validate()
assets.invalidate_cache() assets.invalidate_cache()
@@ -100,7 +110,7 @@ class TestAccountAssetTransfer(TestAssetManagement):
with transfer_form.to_asset_ids.new() as to_asset: with transfer_form.to_asset_ids.new() as to_asset:
to_asset.asset_name = "Asset 1" to_asset.asset_name = "Asset 1"
to_asset.asset_profile_id = self.profile_asset to_asset.asset_profile_id = self.profile_asset
to_asset.asset_value = 2000 to_asset.asset_value = 3000
with transfer_form.to_asset_ids.new() as to_asset: with transfer_form.to_asset_ids.new() as to_asset:
to_asset.asset_name = "Asset 2" to_asset.asset_name = "Asset 2"
to_asset.asset_profile_id = self.profile_asset to_asset.asset_profile_id = self.profile_asset
@@ -111,4 +121,4 @@ class TestAccountAssetTransfer(TestAssetManagement):
assets = transfer_move.invoice_line_ids.mapped("asset_id") assets = transfer_move.invoice_line_ids.mapped("asset_id")
# 2 new assets created, and value equal to original assets # 2 new assets created, and value equal to original assets
new_assets = assets.filtered(lambda l: l.state == "draft") new_assets = assets.filtered(lambda l: l.state == "draft")
self.assertEqual(sum(new_assets.mapped("purchase_value")), 22000) self.assertEqual(sum(new_assets.mapped("purchase_value")), 23000)

View File

@@ -19,6 +19,16 @@
help="Transfer asset from AUC to Asset" help="Transfer asset from AUC to Asset"
/> />
</button> </button>
<xpath expr="//header[last()]" position="after">
<div
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
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>
</field> </field>
</record> </record>

View File

@@ -142,17 +142,33 @@ class AccountAssetTransfer(models.TransientModel):
"domain": [("id", "=", move.id)], "domain": [("id", "=", move.id)],
} }
def _get_move_line_from_asset(self, move_line): def _get_move_line_from_asset(self, asset):
# Case asset created with account move
if asset.account_move_line_ids:
asset.account_move_line_ids.ensure_one()
move_line = asset.account_move_line_ids[0]
return { return {
"name": move_line.name, "name": move_line.name,
"account_id": move_line.account_id.id, "account_id": move_line.account_id.id,
"analytic_account_id": move_line.analytic_account_id.id, "analytic_account_id": move_line.analytic_account_id.id or False,
"analytic_tag_ids": [(4, tag.id) for tag in move_line.analytic_tag_ids], "analytic_tag_ids": [(4, tag.id) for tag in move_line.analytic_tag_ids],
"debit": move_line.credit, "debit": move_line.credit,
"credit": move_line.debit, "credit": move_line.debit,
"partner_id": move_line.partner_id.id, "partner_id": move_line.partner_id.id,
"asset_id": move_line.asset_id.id, # Link to existing asset "asset_id": move_line.asset_id.id, # Link to existing asset
} }
# Case asset created without account moves
else:
return {
"name": asset.name,
"account_id": asset.profile_id.account_asset_id.id,
"analytic_account_id": asset.account_analytic_id.id,
"analytic_tag_ids": [(4, tag.id) for tag in asset.analytic_tag_ids],
"debit": 0.0,
"credit": asset.purchase_value or 0.0,
"partner_id": asset.partner_id.id,
"asset_id": asset.id, # Link to existing asset
}
def _get_move_line_to_asset(self, to_asset): def _get_move_line_to_asset(self, to_asset):
return { return {
@@ -170,11 +186,10 @@ class AccountAssetTransfer(models.TransientModel):
def _get_transfer_data(self): def _get_transfer_data(self):
move_lines = [] move_lines = []
# Create lines from assets # Create lines from assets
for asset in self.from_asset_ids: move_lines += [
asset.account_move_line_ids.ensure_one() (0, 0, self._get_move_line_from_asset(from_asset))
move_line = asset.account_move_line_ids[0] for from_asset in self.from_asset_ids
move_line_vals = self._get_move_line_from_asset(move_line) ]
move_lines.append((0, 0, move_line_vals))
# Create lines for new assets # Create lines for new assets
move_lines += [ move_lines += [
(0, 0, self._get_move_line_to_asset(to_asset)) (0, 0, self._get_move_line_to_asset(to_asset))