Skip to content

Commit 1471376

Browse files
committed
Merge PR #4766 into 14.0
Signed-off-by francesco-ooops
2 parents 0dfcf65 + b58040c commit 1471376

File tree

12 files changed

+674
-68
lines changed

12 files changed

+674
-68
lines changed

assets_management/README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Contributors
8888

8989
* Simone Rubino <simone.rubino@aion-tech.it>
9090

91-
Base icon made by `surang <https://www.flaticon.com/authors/surang>`_ from `www.flaticon.com <https://www.flaticon.com/>`_.
91+
Base icon made by `surang <https://www.flaticon.com/authors/surang>`__
92+
from `www.flaticon.com <http://www.flaticon.com>`__.
9293

9394
Maintainers
9495
~~~~~~~~~~~

assets_management/data/asset_data.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
</record>
3838
<record id="ad_mode_materiale_line" model="asset.depreciation.mode.line">
3939
<field name="mode_id" ref="ad_mode_materiale" />
40-
<field name="from_nr">1</field>
41-
<field name="to_nr">1</field>
40+
<field name="from_year_nr">1</field>
41+
<field name="to_year_nr">1</field>
4242
<field name="coefficient">0.5</field>
4343
</record>
4444

assets_management/models/account_fiscal_year.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ def get_fiscal_year_by_date_domain(self, date, company=None):
3535
if company:
3636
domain.append(("company_id", "in", company.ids))
3737
return domain
38+
39+
@api.model
40+
def _get_passed_years(self, start_date, end_date):
41+
"""Find all fiscal years between `start_date` and `end_date`."""
42+
if start_date and end_date:
43+
overlapping_fiscal_year_domain = self.new(
44+
{
45+
"date_from": start_date,
46+
"date_to": end_date,
47+
}
48+
)._get_overlapping_domain()
49+
# Exclude current record's NewId
50+
# because it is not supported in domains
51+
overlapping_fiscal_year_domain = [
52+
term if term[0] != "id" else ("id", "!=", 0)
53+
for term in overlapping_fiscal_year_domain
54+
]
55+
overlapping_fiscal_years = self.search(overlapping_fiscal_year_domain)
56+
passed_years = len(overlapping_fiscal_years)
57+
else:
58+
passed_years = None
59+
return passed_years

assets_management/models/asset_depreciation.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -293,26 +293,36 @@ def check_before_generate_depreciation_lines(self, dep_date):
293293
).format(draft_names)
294294
)
295295

296-
def generate_depreciation_lines(self, dep_date):
296+
def generate_depreciation_lines(self, dep_date, period=None, period_count=None):
297297
# Set new date within context if necessary
298298
self.check_before_generate_depreciation_lines(dep_date)
299299

300300
new_lines = self.env["asset.depreciation.line"]
301301
for dep in self:
302-
new_line = dep.generate_depreciation_lines_single(dep_date)
302+
new_line = dep.generate_depreciation_lines_single(
303+
dep_date, period=period, period_count=period_count
304+
)
303305
if new_line:
304306
new_lines |= new_line
305307

306308
return new_lines
307309

308-
def generate_depreciation_lines_single(self, dep_date):
310+
def generate_depreciation_lines_single(
311+
self, dep_date, period=None, period_count=None
312+
):
309313
self.ensure_one()
310314
res = self.env["asset.depreciation.line"]
311315
if self.last_depreciation_date and self.last_depreciation_date > dep_date:
312316
return res
313-
dep_nr = self.get_max_depreciation_nr() + 1
314-
dep = self.with_context(dep_nr=dep_nr, used_asset=self.asset_id.used)
315-
dep_amount = dep.get_depreciation_amount(dep_date)
317+
passed_fiscal_years = self.env["account.fiscal.year"]._get_passed_years(
318+
self.asset_id.purchase_date, dep_date
319+
)
320+
dep = self.with_context(
321+
passed_fiscal_years=passed_fiscal_years, used_asset=self.asset_id.used
322+
)
323+
dep_amount = dep.get_depreciation_amount(
324+
dep_date, period=period, period_count=period_count
325+
)
316326
if not dep_amount:
317327
return res
318328
dep = dep.with_context(dep_amount=dep_amount)
@@ -397,15 +407,17 @@ def get_depreciable_amount(self, dep_date=None):
397407
depreciable_amount = 0
398408
return depreciable_amount
399409

400-
def get_depreciation_amount(self, dep_date):
410+
def get_depreciation_amount(self, dep_date, period=None, period_count=None):
401411
self.ensure_one()
402412
zero_dep_date = self.zero_depreciation_until
403413
if zero_dep_date and dep_date <= zero_dep_date:
404414
return 0
405415

406416
# Get depreciable amount, multiplier and digits
407417
amount = self.get_depreciable_amount(dep_date)
408-
multiplier = self.get_depreciation_amount_multiplier(dep_date)
418+
multiplier = self.get_depreciation_amount_multiplier(
419+
dep_date, period=period, period_count=period_count
420+
)
409421
digits = self.env["decimal.precision"].precision_get("Account")
410422
dep_amount = round(amount * multiplier, digits)
411423

@@ -415,12 +427,20 @@ def get_depreciation_amount(self, dep_date):
415427

416428
return dep_amount
417429

418-
def get_depreciation_amount_multiplier(self, dep_date):
430+
def get_depreciation_amount_multiplier(
431+
self, dep_date, period=None, period_count=None
432+
):
419433
self.ensure_one()
420434

421435
# Base multiplier
422436
multiplier = self.percentage / 100
423437

438+
if period == "month":
439+
multiplier /= 12
440+
441+
if period_count:
442+
multiplier *= period_count
443+
424444
# Update multiplier from depreciation mode data
425445
multiplier *= self.mode_id.get_depreciation_amount_multiplier()
426446

@@ -504,14 +524,6 @@ def get_dismiss_account_move_vals(self):
504524
"move_type": "entry",
505525
}
506526

507-
def get_max_depreciation_nr(self):
508-
self.ensure_one()
509-
num_lines = self.line_ids.filtered("requires_depreciation_nr")
510-
nums = num_lines.mapped("depreciation_nr")
511-
if not nums:
512-
nums = [0]
513-
return max(nums)
514-
515527
def get_pro_rata_temporis_dates(self, date):
516528
"""
517529
Gets useful dates for pro rata temporis computations, according to

assets_management/models/asset_depreciation_line.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,14 @@ def generate_account_move_single(self):
369369

370370
def get_account_move_vals(self):
371371
self.ensure_one()
372+
journal = self.env.context.get(
373+
"l10n_it_asset_override_journal",
374+
self.asset_id.category_id.journal_id,
375+
)
372376
return {
373377
"company_id": self.company_id.id,
374378
"date": self.date,
375-
"journal_id": self.asset_id.category_id.journal_id.id,
379+
"journal_id": journal.id,
376380
"line_ids": [],
377381
"ref": _("Asset: ") + self.asset_id.make_name(),
378382
"move_type": "entry",

assets_management/models/asset_depreciation_mode_line.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class AssetDepreciationModeLine(models.Model):
99
_name = "asset.depreciation.mode.line"
1010
_description = "Asset Depreciation Mode Line"
11-
_order = "from_nr asc, to_nr asc"
11+
_order = "from_year_nr asc, to_year_nr asc"
1212

1313
application = fields.Selection(
1414
[("coefficient", "Coefficient"), ("percentage", "Percentage")],
@@ -25,9 +25,12 @@ class AssetDepreciationModeLine(models.Model):
2525
"res.company", readonly=True, related="mode_id.company_id", string="Company"
2626
)
2727

28-
from_nr = fields.Integer(
28+
from_year_nr = fields.Integer(
2929
required=True,
30-
string="From Nr",
30+
string="From Year",
31+
help="Minimum number of fiscal years passed "
32+
"from asset purchase date "
33+
"to apply this line.",
3134
)
3235

3336
mode_id = fields.Many2one(
@@ -40,8 +43,11 @@ class AssetDepreciationModeLine(models.Model):
4043

4144
percentage = fields.Float(string="Percentage")
4245

43-
to_nr = fields.Integer(
44-
string="To Nr",
46+
to_year_nr = fields.Integer(
47+
string="To Year",
48+
help="Maximum number of fiscal years passed "
49+
"from asset purchase date "
50+
"to apply this line.",
4551
)
4652

4753
@api.onchange("application")
@@ -57,13 +63,14 @@ def onchange_application(self):
5763

5864
def get_depreciation_amount_multiplier(self):
5965
multiplier = 1
60-
nr = self._context.get("dep_nr")
61-
if nr is None:
66+
passed_fiscal_years = self._context.get("passed_fiscal_years")
67+
if passed_fiscal_years is None:
6268
# Cannot compare to any line
6369
return multiplier
6470

6571
lines = self.filtered(
66-
lambda l: l.from_nr <= nr and (not l.to_nr or l.to_nr >= nr)
72+
lambda line: line.from_year_nr <= passed_fiscal_years
73+
and (not line.to_year_nr or line.to_year_nr >= passed_fiscal_years)
6774
)
6875
if not lines:
6976
return multiplier

assets_management/static/description/index.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -428,14 +427,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
428427
</ul>
429428
</li>
430429
</ul>
431-
<p>Base icon made by <a class="reference external" href="https://www.flaticon.com/authors/surang">surang</a> from <a class="reference external" href="https://www.flaticon.com/">www.flaticon.com</a>.</p>
430+
<p>Base icon made by <a class="reference external" href="https://www.flaticon.com/authors/surang">surang</a>
431+
from <a class="reference external" href="http://www.flaticon.com">www.flaticon.com</a>.</p>
432432
</div>
433433
<div class="section" id="maintainers">
434434
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
435435
<p>This module is maintained by the OCA.</p>
436-
<a class="reference external image-reference" href="https://odoo-community.org">
437-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
438-
</a>
436+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
439437
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
440438
mission is to support the collaborative development of Odoo features and
441439
promote its widespread use.</p>

0 commit comments

Comments
 (0)