Skip to content

Commit

Permalink
IMP l10n_it_asset_management: gestione Pro-rata Temporis con data di …
Browse files Browse the repository at this point in the history
…fine ammortamento
  • Loading branch information
eLBati committed Jun 27, 2024
1 parent 82c0f17 commit 2631262
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 27 deletions.
47 changes: 33 additions & 14 deletions l10n_it_asset_management/models/asset_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class AssetDepreciation(models.Model):
percentage = fields.Float(string="Depreciation (%)")

pro_rata_temporis = fields.Boolean(string="Pro-rata Temporis")
date_end = fields.Date()

requires_account_move = fields.Boolean(
readonly=True,
Expand Down Expand Up @@ -414,13 +415,6 @@ def get_depreciation_amount(self, dep_date):
def get_depreciation_amount_multiplier(self, dep_date):
self.ensure_one()

# Base multiplier
multiplier = self.percentage / 100

# Update multiplier from depreciation mode data
multiplier *= self.mode_id.get_depreciation_amount_multiplier()

# Update multiplier from pro-rata temporis
date_start = self.date_start
if dep_date < date_start:
dt_start_str = fields.Date.from_string(date_start).strftime("%d-%m-%Y")
Expand All @@ -430,15 +424,40 @@ def get_depreciation_amount_multiplier(self, dep_date):
start_date=dt_start_str,
)
)
fiscal_year_obj = self.env["account.fiscal.year"]
fy_start = fiscal_year_obj.get_fiscal_year_by_date(
date_start, company=self.company_id
)
fy_dep = fiscal_year_obj.get_fiscal_year_by_date(
dep_date, company=self.company_id
)

if self.pro_rata_temporis or self._context.get("force_prorata"):
fiscal_year_obj = self.env["account.fiscal.year"]
fy_start = fiscal_year_obj.get_fiscal_year_by_date(
date_start, company=self.company_id
)
fy_dep = fiscal_year_obj.get_fiscal_year_by_date(
dep_date, company=self.company_id
# Base multiplier
multiplier = self.percentage / 100

# Set multiplier from pro-rata temporis with date_end
if (
self.pro_rata_temporis or self._context.get("force_prorata")
) and self.date_end:
fy_end = fiscal_year_obj.get_fiscal_year_by_date(
self.date_end, company=self.company_id
)
total_days = (self.date_end - self.date_start).days + 1
dep_year_days = (fy_dep.date_to - fy_dep.date_from).days + 1

if fy_dep == fy_start:
dep_year_days = (fy_start.date_to - self.date_start).days + 1
elif fy_dep == fy_end:
dep_year_days = (self.date_end - fy_end.date_from).days + 1
multiplier = dep_year_days / total_days

# Update multiplier from depreciation mode data
multiplier *= self.mode_id.get_depreciation_amount_multiplier()

# Update multiplier from pro-rata temporis without date_end
if (
self.pro_rata_temporis or self._context.get("force_prorata")
) and not self.date_end:
if fy_dep == fy_start:
# If current depreciation lies within the same fiscal year in
# which the asset was registered, compute multiplier as a
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_asset_management/report/asset_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ class ReportDepreciation(models.TransientModel):
# Fields to be printed
dep_amount_depreciable = fields.Float()
dep_date_start = fields.Char()
dep_date_end = fields.Char()
dep_percentage = fields.Float()
dep_pro_rata_temporis = fields.Char()
mode_name = fields.Char()
Expand Down Expand Up @@ -630,6 +631,7 @@ def get_report_dep_data(self):
return {
"dep_amount_depreciable": dep.amount_depreciable,
"dep_date_start": format_date(dep, "date_start", "%d-%m-%Y"),
"dep_date_end": format_date(dep, "date_end", "%d-%m-%Y"),
"dep_percentage": dep.percentage,
"dep_pro_rata_temporis": dep_pro_rata_temporis,
"mode_name": dep.mode_id.name_get()[0][-1] if dep.mode_id else "",
Expand Down
41 changes: 30 additions & 11 deletions l10n_it_asset_management/report/templates/asset_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,16 @@
<div class="act_as_cell" style="width: 16.667%;" name="date_start">
<span>Starting From</span>
</div>
<div class="act_as_cell" style="width: 16.667%;" name="percentage">
<span>Dep. Percentage (%)</span>
</div>
<t t-if="dep_section.dep_date_end">
<div class="act_as_cell" style="width: 16.667%;" name="date_end">
<span>Ending On</span>
</div>
</t>
<t t-if="not dep_section.dep_date_end">
<div class="act_as_cell" style="width: 16.667%;" name="percentage">
<span>Dep. Percentage</span>
</div>
</t>
<div class="act_as_cell" style="width: 16.667%;" name="pro_rata_temporis">
<span>Pro Rata Temporis</span>
</div>
Expand Down Expand Up @@ -491,14 +498,26 @@
</div>
<div class="act_as_cell" style="width: 16.667%;" name="percentage">
<span>
<a
t-att-res-id="active_id"
view-type="form"
t-att-res-model="res_model"
class="o_account_financial_reports_web_action"
>
<t t-out="dep_section.dep_percentage" />
</a>
<t t-if="not dep_section.dep_date_end">
<a
t-att-res-id="active_id"
view-type="form"
t-att-res-model="res_model"
class="o_account_financial_reports_web_action"
>
<t t-out="dep_section.dep_percentage" />
</a>
</t>
<t t-if="dep_section.dep_date_end">
<a
t-att-res-id="active_id"
view-type="form"
t-att-res-model="res_model"
class="o_account_financial_reports_web_action"
>
<t t-out="dep_section.dep_date_end" />
</a>
</t>
</span>
</div>
<div class="act_as_cell" style="width: 16.667%;" name="pro_rata_temporis">
Expand Down
6 changes: 5 additions & 1 deletion l10n_it_asset_management/views/asset_depreciation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
name="pro_rata_temporis"
attrs="{'readonly': [('state', '!=', 'non_depreciated')]}"
/>
<field
name="date_end"
attrs="{'readonly': [('state', '!=', 'non_depreciated')], 'invisible': [('pro_rata_temporis', '=', False)]}"
/>
<field
name="percentage"
attrs="{'readonly': [('state', '!=', 'non_depreciated')]}"
attrs="{'readonly': [('state', '!=', 'non_depreciated')], 'invisible': [('date_end', '!=', False)]}"
/>
<field
name="base_coeff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_depreciations_domain(self):
domain = [
("amount_residual", ">", 0),
("date_start", "!=", False),
("date_start", "<", self.date_dep),
("date_start", "<=", self.date_dep),
("type_id", "in", self.type_ids.ids),
]
if self.asset_ids:
Expand Down

0 comments on commit 2631262

Please sign in to comment.