mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] account_asset_management: Keep line original price on expansion
This commit is contained in:
@@ -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)})
|
||||
|
||||
@@ -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([])
|
||||
|
||||
Reference in New Issue
Block a user