Skip to content

Commit

Permalink
Merge PR #4071 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by eLBati
  • Loading branch information
OCA-git-bot committed Oct 4, 2024
2 parents 1d50a33 + fb81f29 commit 9bdee7c
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 65 deletions.
3 changes: 1 addition & 2 deletions l10n_it_asset_management/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ Contributors
- Nextev Srl <odoo@nextev.it>

Base icon made by `surang <https://www.flaticon.com/authors/surang>`__
from
[`www.flaticon.com](https://www.flaticon.com/) <http://www.flaticon.com](https://www.flaticon.com/)>`__.
from `www.flaticon.com <http://www.flaticon.com>`__.

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_asset_management/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "ITA - Gestione Cespiti",
"version": "16.0.1.0.1",
"version": "16.0.1.1.0",
"category": "Localization/Italy",
"summary": "Gestione Cespiti",
"author": "Openforce, Odoo Community Association (OCA)",
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_asset_management/data/asset_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
</record>
<record id="ad_mode_materiale_line" model="asset.depreciation.mode.line">
<field name="mode_id" ref="ad_mode_materiale" />
<field name="from_nr">1</field>
<field name="to_nr">1</field>
<field name="from_year_nr">1</field>
<field name="to_year_nr">1</field>
<field name="coefficient">0.5</field>
</record>

Expand Down
32 changes: 32 additions & 0 deletions l10n_it_asset_management/migrations/16.0.1.1.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

MODEL_TO_RENAMED_FIELDS = {
"asset.depreciation.mode.line": [
("from_nr", "from_year_nr"),
("to_nr", "to_year_nr"),
]
}


def _rename_fields(env):
openupgrade.rename_fields(
env,
[
(
model_name,
model_name.replace(".", "_"),
field_spec[0],
field_spec[1],
)
for model_name, field_specs in MODEL_TO_RENAMED_FIELDS.items()
for field_spec in field_specs
],
)


@openupgrade.migrate()
def migrate(env, version):
_rename_fields(env)
22 changes: 22 additions & 0 deletions l10n_it_asset_management/models/account_fiscal_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,25 @@ def get_fiscal_year_by_date_domain(self, date, company=None):
if company:
domain.append(("company_id", "in", company.ids))
return domain

@api.model
def _get_passed_years(self, start_date, end_date):
"""Find all fiscal years between `start_date` and `end_date`."""
if start_date and end_date:
overlapping_fiscal_year_domain = self.new(
{
"date_from": start_date,
"date_to": end_date,
}
)._get_overlapping_domain()
# Exclude current record's NewId
# because it is not supported in domains
overlapping_fiscal_year_domain = [
term if term[0] != "id" else ("id", "!=", 0)
for term in overlapping_fiscal_year_domain
]
overlapping_fiscal_years = self.search(overlapping_fiscal_year_domain)
passed_years = len(overlapping_fiscal_years)
else:
passed_years = None
return passed_years
46 changes: 29 additions & 17 deletions l10n_it_asset_management/models/asset_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,36 @@ def check_before_generate_depreciation_lines(self, dep_date):
)
)

def generate_depreciation_lines(self, dep_date):
def generate_depreciation_lines(self, dep_date, period=None, period_count=None):
# Set new date within context if necessary
self.check_before_generate_depreciation_lines(dep_date)

new_lines = self.env["asset.depreciation.line"]
for dep in self:
new_line = dep.generate_depreciation_lines_single(dep_date)
new_line = dep.generate_depreciation_lines_single(
dep_date, period=period, period_count=period_count
)
if new_line:
new_lines |= new_line

return new_lines

def generate_depreciation_lines_single(self, dep_date):
def generate_depreciation_lines_single(
self, dep_date, period=None, period_count=None
):
self.ensure_one()
res = self.env["asset.depreciation.line"]
if self.last_depreciation_date and self.last_depreciation_date > dep_date:
return res
dep_nr = self.get_max_depreciation_nr() + 1
dep = self.with_context(dep_nr=dep_nr, used_asset=self.asset_id.used)
dep_amount = dep.get_depreciation_amount(dep_date)
passed_fiscal_years = self.env["account.fiscal.year"]._get_passed_years(
self.asset_id.purchase_date, dep_date
)
dep = self.with_context(
passed_fiscal_years=passed_fiscal_years, used_asset=self.asset_id.used
)
dep_amount = dep.get_depreciation_amount(
dep_date, period=period, period_count=period_count
)
if not dep_amount:
return res
dep = dep.with_context(dep_amount=dep_amount)
Expand Down Expand Up @@ -393,15 +403,17 @@ def get_depreciable_amount(self, dep_date=None):
depreciable_amount = 0
return depreciable_amount

def get_depreciation_amount(self, dep_date):
def get_depreciation_amount(self, dep_date, period=None, period_count=None):
self.ensure_one()
zero_dep_date = self.zero_depreciation_until
if zero_dep_date and dep_date <= zero_dep_date:
return 0

# Get depreciable amount, multiplier and digits
amount = self.get_depreciable_amount(dep_date)
multiplier = self.get_depreciation_amount_multiplier(dep_date)
multiplier = self.get_depreciation_amount_multiplier(
dep_date, period=period, period_count=period_count
)
digits = self.env["decimal.precision"].precision_get("Account")
dep_amount = round(amount * multiplier, digits)

Expand All @@ -411,12 +423,20 @@ def get_depreciation_amount(self, dep_date):

return dep_amount

def get_depreciation_amount_multiplier(self, dep_date):
def get_depreciation_amount_multiplier(
self, dep_date, period=None, period_count=None
):
self.ensure_one()

# Base multiplier
multiplier = self.percentage / 100

if period == "month":
multiplier /= 12

if period_count:
multiplier *= period_count

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

Expand Down Expand Up @@ -503,14 +523,6 @@ def get_dismiss_account_move_vals(self):
"move_type": "entry",
}

def get_max_depreciation_nr(self):
self.ensure_one()
num_lines = self.line_ids.filtered("requires_depreciation_nr")
nums = num_lines.mapped("depreciation_nr")
if not nums:
nums = [0]
return max(nums)

def get_pro_rata_temporis_dates(self, date):
"""
Gets useful dates for pro rata temporis computations, according to
Expand Down
6 changes: 5 additions & 1 deletion l10n_it_asset_management/models/asset_depreciation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,14 @@ def generate_account_move_single(self):

def get_account_move_vals(self):
self.ensure_one()
journal = self.env.context.get(
"l10n_it_asset_override_journal",
self.asset_id.category_id.journal_id,
)
return {
"company_id": self.company_id.id,
"date": self.date,
"journal_id": self.asset_id.category_id.journal_id.id,
"journal_id": journal.id,
"line_ids": [],
"ref": _("Asset: ") + self.asset_id.make_name(),
"move_type": "entry",
Expand Down
22 changes: 16 additions & 6 deletions l10n_it_asset_management/models/asset_depreciation_mode_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class AssetDepreciationModeLine(models.Model):
_name = "asset.depreciation.mode.line"
_description = "Asset Depreciation Mode Line"
_order = "from_nr asc, to_nr asc"
_order = "from_year_nr asc, to_year_nr asc"

application = fields.Selection(
[("coefficient", "Coefficient"), ("percentage", "Percentage")],
Expand All @@ -24,8 +24,12 @@ class AssetDepreciationModeLine(models.Model):
"res.company", readonly=True, related="mode_id.company_id", string="Company"
)

from_nr = fields.Integer(
from_year_nr = fields.Integer(
required=True,
string="From Year",
help="Minimum number of fiscal years passed "
"from asset purchase date "
"to apply this line.",
)

mode_id = fields.Many2one(
Expand All @@ -38,7 +42,12 @@ class AssetDepreciationModeLine(models.Model):

percentage = fields.Float()

to_nr = fields.Integer()
to_year_nr = fields.Integer(
string="To Year",
help="Maximum number of fiscal years passed "
"from asset purchase date "
"to apply this line.",
)

@api.onchange("application")
def onchange_application(self):
Expand All @@ -53,13 +62,14 @@ def onchange_application(self):

def get_depreciation_amount_multiplier(self):
multiplier = 1
nr = self._context.get("dep_nr")
if nr is None:
passed_fiscal_years = self._context.get("passed_fiscal_years")
if passed_fiscal_years is None:
# Cannot compare to any line
return multiplier

lines = self.filtered(
lambda line: line.from_nr <= nr and (not line.to_nr or line.to_nr >= nr)
lambda line: line.from_year_nr <= passed_fiscal_years
and (not line.to_year_nr or line.to_year_nr >= passed_fiscal_years)
)
if not lines:
return multiplier
Expand Down
14 changes: 5 additions & 9 deletions l10n_it_asset_management/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -438,15 +437,12 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Nextev Srl &lt;<a class="reference external" href="mailto:odoo&#64;nextev.it">odoo&#64;nextev.it</a>&gt;</li>
</ul>
<p>Base icon made by <a class="reference external" href="https://www.flaticon.com/authors/surang">surang</a>
from
[<a class="reference external" href="http://www.flaticon.com](https://www.flaticon.com/)">www.flaticon.com](https://www.flaticon.com/)</a>.</p>
from <a class="reference external" href="http://www.flaticon.com">www.flaticon.com</a>.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Loading

0 comments on commit 9bdee7c

Please sign in to comment.