[FIX] account_asset_management: Fix onchange account_id and asset_profile_id to prevent account_id is empty in some use cases
This commit is contained in:
parent
1620d3a4d8
commit
4e31113bbe
@ -1,5 +1,6 @@
|
|||||||
# Copyright 2009-2018 Noviat
|
# Copyright 2009-2018 Noviat
|
||||||
# Copyright 2021 Tecnativa - João Marques
|
# Copyright 2021 Tecnativa - João Marques
|
||||||
|
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -121,9 +122,15 @@ class AccountMoveLine(models.Model):
|
|||||||
|
|
||||||
@api.onchange("account_id")
|
@api.onchange("account_id")
|
||||||
def _onchange_account_id(self):
|
def _onchange_account_id(self):
|
||||||
|
if self.account_id.asset_profile_id:
|
||||||
self.asset_profile_id = self.account_id.asset_profile_id
|
self.asset_profile_id = self.account_id.asset_profile_id
|
||||||
super()._onchange_account_id()
|
super()._onchange_account_id()
|
||||||
|
|
||||||
|
@api.onchange("asset_profile_id")
|
||||||
|
def _onchange_asset_profile_id(self):
|
||||||
|
if self.asset_profile_id.account_asset_id:
|
||||||
|
self.account_id = self.asset_profile_id.account_asset_id
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
for vals in vals_list:
|
for vals in vals_list:
|
||||||
|
@ -14,3 +14,4 @@
|
|||||||
* Ernesto Tejeda
|
* Ernesto Tejeda
|
||||||
* Pedro M. Baeza
|
* Pedro M. Baeza
|
||||||
* João Marques
|
* João Marques
|
||||||
|
* Víctor Martínez
|
||||||
|
@ -90,6 +90,30 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_invoice_line_without_product(self):
|
||||||
|
tax = self.env["account.tax"].create(
|
||||||
|
{
|
||||||
|
"name": "TAX 15%",
|
||||||
|
"amount_type": "percent",
|
||||||
|
"type_tax_use": "purchase",
|
||||||
|
"amount": 15.0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
move_form = Form(
|
||||||
|
self.env["account.move"].with_context(
|
||||||
|
default_move_type="in_invoice", check_move_validity=False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
move_form.partner_id = self.partner
|
||||||
|
with move_form.invoice_line_ids.new() as line_form:
|
||||||
|
line_form.name = "Line 1"
|
||||||
|
line_form.price_unit = 200.0
|
||||||
|
line_form.quantity = 1
|
||||||
|
line_form.tax_ids.clear()
|
||||||
|
line_form.tax_ids.add(tax)
|
||||||
|
invoice = move_form.save()
|
||||||
|
self.assertEqual(invoice.partner_id, self.partner)
|
||||||
|
|
||||||
def test_01_nonprorata_basic(self):
|
def test_01_nonprorata_basic(self):
|
||||||
"""Basic tests of depreciation board computations and postings."""
|
"""Basic tests of depreciation board computations and postings."""
|
||||||
# First create demo assets and do some sanity checks
|
# First create demo assets and do some sanity checks
|
||||||
|
Loading…
Reference in New Issue
Block a user