diff --git a/account_asset_transfer/README.rst b/account_asset_transfer/README.rst index 658e39e99b3..dd17f8ab7ce 100644 --- a/account_asset_transfer/README.rst +++ b/account_asset_transfer/README.rst @@ -60,6 +60,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 =========== diff --git a/account_asset_transfer/readme/USAGE.rst b/account_asset_transfer/readme/USAGE.rst index 3954a025a17..a28c5fe3b24 100644 --- a/account_asset_transfer/readme/USAGE.rst +++ b/account_asset_transfer/readme/USAGE.rst @@ -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" diff --git a/account_asset_transfer/static/description/index.html b/account_asset_transfer/static/description/index.html index e02e5e3c2f5..68db9344aa2 100644 --- a/account_asset_transfer/static/description/index.html +++ b/account_asset_transfer/static/description/index.html @@ -407,6 +407,7 @@

Usage

  • 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

    diff --git a/account_asset_transfer/tests/test_account_asset_transfer.py b/account_asset_transfer/tests/test_account_asset_transfer.py index d310cbb92eb..c7ad7d2d818 100644 --- a/account_asset_transfer/tests/test_account_asset_transfer.py +++ b/account_asset_transfer/tests/test_account_asset_transfer.py @@ -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, @@ -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, @@ -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") diff --git a/account_asset_transfer/wizard/account_asset_transfer.py b/account_asset_transfer/wizard/account_asset_transfer.py index 72a34dcca6b..09382a741fe 100644 --- a/account_asset_transfer/wizard/account_asset_transfer.py +++ b/account_asset_transfer/wizard/account_asset_transfer.py @@ -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" @@ -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", @@ -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)}) diff --git a/account_asset_transfer/wizard/account_asset_transfer.xml b/account_asset_transfer/wizard/account_asset_transfer.xml index c402e59d763..87a7403ab29 100644 --- a/account_asset_transfer/wizard/account_asset_transfer.xml +++ b/account_asset_transfer/wizard/account_asset_transfer.xml @@ -23,6 +23,14 @@ +
    +
    + + + + Transfer Asset + account.asset.transfer + form + new + + Transfer Asset