From c10bd10ad41b1097d2009bb8891b137be26be724 Mon Sep 17 00:00:00 2001 From: Aritz Olea Date: Tue, 9 Apr 2024 09:48:21 +0200 Subject: [PATCH] [IMP] account_asset_management: Keep line original price on expansion --- .../models/account_move.py | 23 +++++++++++-------- .../tests/test_account_asset_management.py | 5 ++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index d4eeeb666..1f54479a8 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -250,12 +250,17 @@ class AccountMoveLine(models.Model): def _expand_asset_line(self): self.ensure_one() - if self.asset_profile_id and self.quantity > 1.0: - profile = self.asset_profile_id - if profile.asset_product_item: - aml = self.with_context(check_move_validity=False) - qty = self.quantity - name = self.name - aml.write({"quantity": 1, "name": "{} {}".format(name, 1)}) - for i in range(1, int(qty)): - aml.copy({"name": "{} {}".format(name, i + 1)}) + if self.quantity > 1.0 and self.asset_profile_id.asset_product_item: + aml = self.with_context(check_move_validity=False) + qty = self.quantity + name = self.name + aml.write( + { + "quantity": 1, + "name": "{} {}".format(name, 1), + # Make sure the price is not changed, like with account_invoice_pricelist + "price_unit": self.price_unit, + } + ) + for i in range(1, int(qty)): + aml.copy({"name": "{} {}".format(name, i + 1)}) diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index 1ca5b761c..0ce665b94 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -599,8 +599,13 @@ class TestAssetManagement(AccountTestInvoicingCommon): line = invoice.invoice_line_ids[0] self.assertTrue(line.price_unit > 0.0) line.quantity = 2 + line_price = 670 + line.price_unit = line_price line.asset_profile_id = asset_profile self.assertEqual(len(invoice.invoice_line_ids), 2) + self.assertTrue( + all([line.price_unit == line_price for line in invoice.invoice_line_ids]) + ) invoice.action_post() # get all asset after invoice validation current_asset = self.env["account.asset"].search([])