|
6 | 6 |
|
7 | 7 | from odoo import fields
|
8 | 8 | from odoo.exceptions import ValidationError
|
9 |
| -from odoo.fields import Command |
| 9 | +from odoo.fields import Command, first |
| 10 | +from odoo.tests import Form |
10 | 11 | from odoo.tools.date_utils import relativedelta
|
11 | 12 |
|
12 | 13 | from .common import Common
|
@@ -731,3 +732,64 @@ def test_same_asset_report_residual_partial_depreciation(self):
|
731 | 732 | self.assertEqual(
|
732 | 733 | asset_report_depreciation_line.amount_residual, expected_residual_amount
|
733 | 734 | )
|
| 735 | + |
| 736 | + def test_wizard_compute_depreciated_fund(self): |
| 737 | + """ |
| 738 | + When partially dismissing an asset, |
| 739 | + the fund amount in wizard is computed based on |
| 740 | + the purchased amount and civil depreciation amounts. |
| 741 | + """ |
| 742 | + # Arrange |
| 743 | + civil_depreciation_type = self.env.ref( |
| 744 | + "l10n_it_asset_management.ad_type_civilistico" |
| 745 | + ) |
| 746 | + purchase_date = date(2019, 1, 1) |
| 747 | + depreciation_date = date(2020, 1, 1) |
| 748 | + civil_depreciable_amount = 1000 |
| 749 | + civil_depreciated_amount = 250 |
| 750 | + purchase_amount = 300 |
| 751 | + |
| 752 | + asset = self._create_asset(purchase_date) |
| 753 | + civil_depreciation = first( |
| 754 | + asset.depreciation_ids.filtered( |
| 755 | + lambda d: d.type_id == civil_depreciation_type |
| 756 | + ) |
| 757 | + ) |
| 758 | + civil_depreciation.mode_id.line_ids.unlink() |
| 759 | + civil_depreciation.percentage = 25.0 |
| 760 | + self._depreciate_asset(asset, depreciation_date) |
| 761 | + |
| 762 | + invoice_form = Form( |
| 763 | + self.env["account.move"].with_context(default_move_type="out_invoice") |
| 764 | + ) |
| 765 | + invoice_form.partner_id = self.env.ref("base.partner_demo") |
| 766 | + with invoice_form.invoice_line_ids.new() as line: |
| 767 | + line.account_id = asset.category_id.asset_account_id |
| 768 | + line.price_unit = 100 |
| 769 | + invoice = invoice_form.save() |
| 770 | + invoice.action_post() |
| 771 | + |
| 772 | + self.assertEqual( |
| 773 | + civil_depreciation.amount_depreciable, civil_depreciable_amount |
| 774 | + ) |
| 775 | + self.assertEqual( |
| 776 | + civil_depreciation.amount_depreciated, civil_depreciated_amount |
| 777 | + ) |
| 778 | + |
| 779 | + # Act |
| 780 | + wizard_action = invoice.open_wizard_manage_asset() |
| 781 | + wizard_form = Form( |
| 782 | + self.env[wizard_action["res_model"]].with_context( |
| 783 | + **wizard_action["context"] |
| 784 | + ) |
| 785 | + ) |
| 786 | + wizard_form.management_type = "partial_dismiss" |
| 787 | + wizard_form.asset_id = asset |
| 788 | + wizard_form.asset_purchase_amount = purchase_amount |
| 789 | + wizard = wizard_form.save() |
| 790 | + |
| 791 | + # Assert |
| 792 | + self.assertEqual( |
| 793 | + wizard.depreciated_fund_amount, |
| 794 | + purchase_amount * civil_depreciated_amount / civil_depreciable_amount, |
| 795 | + ) |
0 commit comments