diff --git a/assets_management/__manifest__.py b/assets_management/__manifest__.py index c5092c224843..31b6f8d4a0d2 100644 --- a/assets_management/__manifest__.py +++ b/assets_management/__manifest__.py @@ -8,7 +8,7 @@ "category": "Localization/Italy", "summary": "Gestione Cespiti", "author": "Openforce, Odoo Community Association (OCA)", - "website": "https://github.com/OCA/l10n-italy" "/tree/12.0/assets_management", + "website": "https://github.com/OCA/l10n-italy", "license": "AGPL-3", "depends": [ "account", diff --git a/assets_management/models/asset_category.py b/assets_management/models/asset_category.py index a63996e28772..1b0ffa9aa94e 100644 --- a/assets_management/models/asset_category.py +++ b/assets_management/models/asset_category.py @@ -122,7 +122,7 @@ def copy(self, default=None): def unlink(self): if self.env["asset.asset"].sudo().search([("category_id", "in", self.ids)]): raise UserError( - _("Cannot delete categories while they're still linked" " to an asset.") + _("Cannot delete categories while they're still linked to an asset.") ) return super().unlink() diff --git a/assets_management/models/asset_depreciation.py b/assets_management/models/asset_depreciation.py index 5c3a2d2cc704..a67d8ca3610f 100644 --- a/assets_management/models/asset_depreciation.py +++ b/assets_management/models/asset_depreciation.py @@ -255,7 +255,7 @@ def check_before_generate_depreciation_lines(self, dep_date): # Check if self is a valid recordset if not self: raise ValidationError( - _("Cannot create any depreciation according to current" " settings.") + _("Cannot create any depreciation according to current settings.") ) lines = self.mapped("line_ids") @@ -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 @@ -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) diff --git a/assets_management/models/asset_depreciation_line.py b/assets_management/models/asset_depreciation_line.py index c8d8fb7c2ba5..c4c929971e06 100644 --- a/assets_management/models/asset_depreciation_line.py +++ b/assets_management/models/asset_depreciation_line.py @@ -446,13 +446,27 @@ def get_gain_account_move_line_vals(self): def get_historical_account_move_line_vals(self): raise NotImplementedError( - _("Cannot create account move lines for lines of type" " `Historical`") + _("Cannot create account move lines for lines of type `Historical`") ) def get_in_account_move_line_vals(self): - raise NotImplementedError( - _("Cannot create account move lines for lines of type `In`") - ) + self.ensure_one() + credit_line_vals = { + "account_id": self.asset_id.category_id.gain_account_id.id, + "credit": self.amount, + "debit": 0.0, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), + } + + debit_line_vals = { + "account_id": self.asset_id.category_id.asset_account_id.id, + "credit": 0.0, + "debit": self.amount, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), + } + return [credit_line_vals, debit_line_vals] def get_loss_account_move_line_vals(self): self.ensure_one() @@ -473,9 +487,22 @@ def get_loss_account_move_line_vals(self): return [credit_line_vals, debit_line_vals] def get_out_account_move_line_vals(self): - raise NotImplementedError( - _("Cannot create account move lines for lines of type `Out`") - ) + self.ensure_one() + credit_line_vals = { + "account_id": self.asset_id.category_id.asset_account_id.id, + "credit": self.amount, + "debit": 0.0, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), + } + debit_line_vals = { + "account_id": self.asset_id.category_id.loss_account_id.id, + "credit": 0.0, + "debit": self.amount, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), + } + return [credit_line_vals, debit_line_vals] def needs_account_move(self): self.ensure_one() diff --git a/assets_management/wizard/account_move_manage_asset.py b/assets_management/wizard/account_move_manage_asset.py index 8b194f1a8aa9..6ed02cb3050f 100644 --- a/assets_management/wizard/account_move_manage_asset.py +++ b/assets_management/wizard/account_move_manage_asset.py @@ -259,7 +259,7 @@ def check_pre_dismiss_asset(self): if not self.move_line_ids: raise ValidationError( - _("At least one move line is mandatory to dismiss" " an asset!") + _("At least one move line is mandatory to dismiss an asset!") ) if not len(self.move_line_ids.mapped("move_id")) == 1: @@ -303,7 +303,7 @@ def check_pre_update_asset(self): if not self.move_line_ids: raise ValidationError( - _("At least one move line is mandatory to update" " an asset!") + _("At least one move line is mandatory to update an asset!") ) if not all( diff --git a/assets_management/wizard/asset_generate_depreciation.py b/assets_management/wizard/asset_generate_depreciation.py index 38cefa414953..1d7b424d4e43 100644 --- a/assets_management/wizard/asset_generate_depreciation.py +++ b/assets_management/wizard/asset_generate_depreciation.py @@ -2,7 +2,8 @@ # Copyright 2019 Openforce Srls Unipersonale (www.openforce.it) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError class WizardAssetsGenerateDepreciations(models.TransientModel): @@ -65,7 +66,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"}