Skip to content

Commit

Permalink
[14.0][FIX] do not create depreciation lines with zero amount
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Mar 27, 2023
1 parent 937d3bb commit 25e49f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion assets_management/models/asset_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ def generate_depreciation_lines(self, dep_date):

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

return new_lines

Expand All @@ -320,6 +322,8 @@ def generate_depreciation_lines_single(self, dep_date):
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)
if not dep_amount:
return False
dep = dep.with_context(dep_amount=dep_amount)

vals = dep.prepare_depreciation_line_vals(dep_date)
Expand Down
3 changes: 2 additions & 1 deletion assets_management/wizard/asset_generate_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def do_generate(self):
# Add depreciation date in context just in case
deps = self.get_depreciations().with_context(dep_date=self.date_dep)
dep_lines = deps.generate_depreciation_lines(self.date_dep)
deps.post_generate_depreciation_lines(dep_lines)
if dep_lines:
deps.post_generate_depreciation_lines(dep_lines)
if self._context.get("reload_window"):
return {"type": "ir.actions.client", "tag": "reload"}

Expand Down

0 comments on commit 25e49f9

Please sign in to comment.