diff --git a/account_asset_management/__manifest__.py b/account_asset_management/__manifest__.py index 30b9c94a..42b9b641 100644 --- a/account_asset_management/__manifest__.py +++ b/account_asset_management/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Assets Management", - "version": "14.0.2.7.0", + "version": "15.0.1.0.0", "license": "AGPL-3", "depends": ["account", "report_xlsx_helper"], "excludes": ["account_asset"], diff --git a/account_asset_management/data/cron.xml b/account_asset_management/data/cron.xml index ba591ecf..580c07a4 100644 --- a/account_asset_management/data/cron.xml +++ b/account_asset_management/data/cron.xml @@ -1,17 +1,15 @@ - - - - Asset Management: Generate assets - - code - model.create({}).asset_compute() - - 1 - days - -1 - - - - + + + Asset Management: Generate assets + + code + model.create({}).asset_compute() + + 1 + days + -1 + + + diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index 683c9884..57826f37 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -59,7 +59,6 @@ class AccountAsset(models.Model): states=READONLY_STATES, ) purchase_value = fields.Float( - string="Purchase Value", required=True, states=READONLY_STATES, help="This amount represent the initial value of the asset." @@ -67,7 +66,6 @@ class AccountAsset(models.Model): "\nPurchase Value - Salvage Value.", ) salvage_value = fields.Float( - string="Salvage Value", digits="Account", states=READONLY_STATES, help="The estimated value that an asset will realize upon " @@ -77,7 +75,6 @@ class AccountAsset(models.Model): depreciation_base = fields.Float( compute="_compute_depreciation_base", digits="Account", - string="Depreciation Base", store=True, help="This amount represent the depreciation base " "of the asset (Purchase Value - Salvage Value).", @@ -94,7 +91,7 @@ class AccountAsset(models.Model): string="Depreciated Value", store=True, ) - note = fields.Text("Note") + note = fields.Text() profile_id = fields.Many2one( comodel_name="account.asset.profile", string="Asset Profile", @@ -227,7 +224,6 @@ class AccountAsset(models.Model): help="Use number of days to calculate depreciation amount", ) use_leap_years = fields.Boolean( - string="Use leap years", compute="_compute_use_leap_years", readonly=False, store=True, @@ -1241,13 +1237,11 @@ class AccountAsset(models.Model): asset_ref = depreciation.asset_id.name if depreciation.asset_id.code: asset_ref = "[{}] {}".format(depreciation.asset_id.code, asset_ref) - error_log += _("\nError while processing asset '%s': %s") % ( - asset_ref, - str(e), - ) - error_msg = _("Error while processing asset '%s': \n\n%s") % ( - asset_ref, - tb, + error_log += _( + "\nError while processing asset '{ref}': {exception}" + ).format(ref=asset_ref, exception=str(e)) + error_msg = _("Error while processing asset '{ref}': \n\n{tb}").format( + ref=asset_ref, tb=tb ) _logger.error("%s, %s", self._name, error_msg) diff --git a/account_asset_management/models/account_asset_group.py b/account_asset_management/models/account_asset_group.py index 56b96e37..10ec693c 100644 --- a/account_asset_management/models/account_asset_group.py +++ b/account_asset_management/models/account_asset_group.py @@ -14,7 +14,7 @@ class AccountAssetGroup(models.Model): _parent_store = True _check_company_auto = True - name = fields.Char(string="Name", size=64, required=True, index=True) + name = fields.Char(size=64, required=True, index=True) code = fields.Char(index=True) parent_path = fields.Char(index=True) company_id = fields.Many2one( diff --git a/account_asset_management/models/account_asset_line.py b/account_asset_management/models/account_asset_line.py index e51e6a35..80dba746 100644 --- a/account_asset_management/models/account_asset_line.py +++ b/account_asset_management/models/account_asset_line.py @@ -31,7 +31,7 @@ class AccountAssetLine(models.Model): depreciation_base = fields.Float( related="asset_id.depreciation_base", string="Depreciation Base", readonly=True ) - amount = fields.Float(string="Amount", digits="Account", required=True) + amount = fields.Float(digits="Account", required=True) remaining_value = fields.Float( compute="_compute_values", digits="Account", @@ -263,17 +263,17 @@ class AccountAssetLine(models.Model): asset = line.asset_id depreciation_date = line.line_date am_vals = line._setup_move_data(depreciation_date) - move = self.env["account.move"].with_context(ctx).create(am_vals) + move = self.env["account.move"].with_context(**ctx).create(am_vals) depr_acc = asset.profile_id.account_depreciation_id exp_acc = asset.profile_id.account_expense_depreciation_id aml_d_vals = line._setup_move_line_data( depreciation_date, depr_acc, "depreciation", move ) - self.env["account.move.line"].with_context(ctx).create(aml_d_vals) + self.env["account.move.line"].with_context(**ctx).create(aml_d_vals) aml_e_vals = line._setup_move_line_data( depreciation_date, exp_acc, "expense", move ) - self.env["account.move.line"].with_context(ctx).create(aml_e_vals) + self.env["account.move.line"].with_context(**ctx).create(aml_e_vals) move.action_post() line.with_context(allow_asset_line_update=True).write({"move_id": move.id}) created_move_ids.append(move.id) diff --git a/account_asset_management/models/account_asset_profile.py b/account_asset_management/models/account_asset_profile.py index c132ea07..1c9a0036 100644 --- a/account_asset_management/models/account_asset_profile.py +++ b/account_asset_management/models/account_asset_profile.py @@ -11,7 +11,7 @@ class AccountAssetProfile(models.Model): _description = "Asset profile" _order = "name" - name = fields.Char(string="Name", size=64, required=True, index=True) + name = fields.Char(size=64, required=True, index=True) note = fields.Text() account_analytic_id = fields.Many2one( comodel_name="account.analytic.account", string="Analytic account" @@ -129,7 +129,6 @@ class AccountAssetProfile(models.Model): help="Use number of days to calculate depreciation amount", ) use_leap_years = fields.Boolean( - string="Use leap years", default=False, help="If not set, the system will distribute evenly the amount to " "amortize across the years, based on the number of years. " diff --git a/account_asset_management/models/account_asset_recompute_trigger.py b/account_asset_management/models/account_asset_recompute_trigger.py index 4d7c7789..3ff9dc2b 100644 --- a/account_asset_management/models/account_asset_recompute_trigger.py +++ b/account_asset_management/models/account_asset_recompute_trigger.py @@ -8,7 +8,7 @@ class AccountAssetRecomputeTrigger(models.Model): _name = "account.asset.recompute.trigger" _description = "Asset table recompute triggers" - reason = fields.Char(string="Reason", required=True) + reason = fields.Char(required=True) company_id = fields.Many2one("res.company", string="Company", required=True) date_trigger = fields.Datetime( "Trigger Date", @@ -18,7 +18,6 @@ class AccountAssetRecomputeTrigger(models.Model): date_completed = fields.Datetime("Completion Date", readonly=True) state = fields.Selection( selection=[("open", "Open"), ("done", "Done")], - string="State", default="open", readonly=True, ) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index 932dda7b..9ad4b4c5 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -85,7 +85,7 @@ class AccountMove(models.Model): } def action_post(self): - super().action_post() + ret_val = super().action_post() for move in self: for aml in move.line_ids.filtered( lambda line: line.asset_profile_id and not line.tax_line_id @@ -119,12 +119,13 @@ class AccountMove(models.Model): if refs: message = _("This invoice created the asset(s): %s") % ", ".join(refs) move.message_post(body=message) + return ret_val def button_draft(self): invoices = self.filtered(lambda r: r.is_purchase_document()) if invoices: invoices.line_ids.asset_id.unlink() - super().button_draft() + return super().button_draft() def _reverse_move_vals(self, default_values, cancel=True): move_vals = super()._reverse_move_vals(default_values, cancel) diff --git a/account_asset_management/readme/CONTRIBUTORS.rst b/account_asset_management/readme/CONTRIBUTORS.rst index 99153bcc..5f2ab013 100644 --- a/account_asset_management/readme/CONTRIBUTORS.rst +++ b/account_asset_management/readme/CONTRIBUTORS.rst @@ -20,3 +20,7 @@ * Jordi Ballester * Miquel Raïch + +* `Sygel `_: + + * Manuel Regidor diff --git a/account_asset_management/report/account_asset_report_xls.py b/account_asset_management/report/account_asset_report_xls.py index d4af7da2..063e491d 100644 --- a/account_asset_management/report/account_asset_report_xls.py +++ b/account_asset_management/report/account_asset_report_xls.py @@ -308,8 +308,8 @@ class AssetReportXlsx(models.AbstractModel): self.env["account.asset"]._xls_acquisition_template() ) wl_acq = self.env["account.asset"]._xls_acquisition_fields() - title = self._get_title(wiz, "acquisition", format="normal") - title_short = self._get_title(wiz, "acquisition", format="short") + title = self._get_title(wiz, "acquisition", frmt="normal") + title_short = self._get_title(wiz, "acquisition", frmt="short") sheet_name = title_short[:31].replace("/", "-") return { @@ -326,8 +326,8 @@ class AssetReportXlsx(models.AbstractModel): active_template = self._get_asset_template() active_template.update(self.env["account.asset"]._xls_active_template()) wl_act = self.env["account.asset"]._xls_active_fields() - title = self._get_title(wiz, "active", format="normal") - title_short = self._get_title(wiz, "active", format="short") + title = self._get_title(wiz, "active", frmt="normal") + title_short = self._get_title(wiz, "active", frmt="short") sheet_name = title_short[:31].replace("/", "-") return { @@ -344,8 +344,8 @@ class AssetReportXlsx(models.AbstractModel): removal_template = self._get_asset_template() removal_template.update(self.env["account.asset"]._xls_removal_template()) wl_dsp = self.env["account.asset"]._xls_removal_fields() - title = self._get_title(wiz, "removal", format="normal") - title_short = self._get_title(wiz, "removal", format="short") + title = self._get_title(wiz, "removal", frmt="normal") + title_short = self._get_title(wiz, "removal", frmt="short") sheet_name = title_short[:31].replace("/", "-") return { @@ -357,21 +357,21 @@ class AssetReportXlsx(models.AbstractModel): "report_type": "removal", } - def _get_title(self, wiz, report, format="normal"): + def _get_title(self, wiz, report, frmt="normal"): prefix = "{} - {}".format(wiz.date_from, wiz.date_to) if report == "acquisition": - if format == "normal": + if frmt == "normal": title = prefix + " : " + _("New Acquisitions") else: title = "ACQ" elif report == "active": - if format == "normal": + if frmt == "normal": title = prefix + " : " + _("Active Assets") else: title = "ACT" else: - if format == "normal": + if frmt == "normal": title = prefix + " : " + _("Removed Assets") else: title = "DSP" @@ -412,9 +412,8 @@ class AssetReportXlsx(models.AbstractModel): raise UserError( _( "Inconsistent reporting structure." - "\nPlease correct Asset Group '%s' (id %s)" - ) - % (child.name, child.id) + "\nPlease correct Asset Group '{group}' (id {id})" + ).format(group=child.name, id=child.id) ) groups.extend(_child_get(child)) return groups @@ -468,8 +467,8 @@ class AssetReportXlsx(models.AbstractModel): report = ws_params["report_type"] def asset_filter(asset): - filter = getattr(self, "{}_filter".format(report)) - return filter(wiz, asset) + filt = getattr(self, "{}_filter".format(report)) + return filt(wiz, asset) def _has_assets(group, group_val): assets = group_val.get("assets") @@ -567,8 +566,8 @@ class AssetReportXlsx(models.AbstractModel): row_pos = self._report_title(ws, row_pos, ws_params, data, wiz) def asset_filter(asset): - filter = getattr(self, "{}_filter".format(report)) - return filter(wiz, asset) + filt = getattr(self, "{}_filter".format(report)) + return filt(wiz, asset) assets = data["assets"].filtered(asset_filter) diff --git a/account_asset_management/security/account_asset_security.xml b/account_asset_management/security/account_asset_security.xml index 33b2f92c..00201502 100644 --- a/account_asset_management/security/account_asset_security.xml +++ b/account_asset_management/security/account_asset_security.xml @@ -1,29 +1,27 @@ - - - - Account Asset Profile multi-company - - - ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] - - - Account Asset multi-company - - - ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] - - - Account Asset Group multi-company - - - ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] - - + + + Account Asset Profile multi-company + + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + Account Asset multi-company + + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + Account Asset Group multi-company + + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index e4ec031b..a21bf14d 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -7,7 +7,7 @@ import calendar import time from datetime import date, datetime -from odoo import fields +from odoo import Command, fields from odoo.tests.common import Form from odoo.addons.account.tests.common import AccountTestInvoicingCommon @@ -27,37 +27,58 @@ class TestAssetManagement(AccountTestInvoicingCommon): cls.product = cls.env["product.product"].create( {"name": "Test", "standard_price": 500.0} ) - move_form = Form( - cls.env["account.move"].with_context( - default_move_type="in_invoice", check_move_validity=False + + cls.invoice = ( + cls.env["account.move"] + .with_context(check_move_validity=False) + .create( + { + "move_type": "in_invoice", + "invoice_date": fields.Date.context_today(cls.env.user), + "partner_id": cls.partner.id, + "invoice_line_ids": [ + Command.create( + { + "name": "test", + "product_id": cls.product.id, + "price_unit": 2000.00, + "quantity": 1, + } + ), + ], + } ) ) - move_form.invoice_date = fields.Date.context_today(cls.env.user) - move_form.partner_id = cls.partner - with move_form.invoice_line_ids.new() as line_form: - line_form.name = "test" - line_form.product_id = cls.product - line_form.price_unit = 2000.00 - line_form.quantity = 1 - cls.invoice = move_form.save() - move_form = Form( - cls.env["account.move"].with_context( - default_move_type="in_invoice", check_move_validity=False + + cls.invoice_2 = ( + cls.env["account.move"] + .with_context(check_move_validity=False) + .create( + { + "move_type": "in_invoice", + "invoice_date": fields.Date.context_today(cls.env.user), + "partner_id": cls.partner.id, + "invoice_line_ids": [ + Command.create( + { + "name": "test 2", + "product_id": cls.product.id, + "price_unit": 10000.00, + "quantity": 1, + } + ), + Command.create( + { + "name": "test 3", + "product_id": cls.product.id, + "price_unit": 20000.00, + "quantity": 1, + } + ), + ], + } ) ) - move_form.invoice_date = fields.Date.context_today(cls.env.user) - move_form.partner_id = cls.partner - with move_form.invoice_line_ids.new() as line_form: - line_form.name = "test 2" - line_form.product_id = cls.product - line_form.price_unit = 10000.00 - line_form.quantity = 1 - with move_form.invoice_line_ids.new() as line_form: - line_form.name = "test 3" - line_form.product_id = cls.product - line_form.price_unit = 20000.00 - line_form.quantity = 1 - cls.invoice_2 = move_form.save() # analytic configuration cls.env.user.write( @@ -121,20 +142,28 @@ class TestAssetManagement(AccountTestInvoicingCommon): "amount": 15.0, } ) - move_form = Form( - self.env["account.move"].with_context( - default_move_type="in_invoice", check_move_validity=False + + invoice = ( + self.env["account.move"] + .with_context(check_move_validity=False) + .create( + { + "move_type": "in_invoice", + "invoice_date": fields.Date.context_today(self.env.user), + "partner_id": self.partner.id, + "invoice_line_ids": [ + Command.create( + { + "name": "Line 1", + "price_unit": 200.0, + "quantity": 1, + "tax_ids": [tax.id], + } + ), + ], + } ) ) - move_form.invoice_date = fields.Date.context_today(self.env.user) - move_form.partner_id = self.partner - with move_form.invoice_line_ids.new() as line_form: - line_form.name = "Line 1" - line_form.price_unit = 200.0 - line_form.quantity = 1 - line_form.tax_ids.clear() - line_form.tax_ids.add(tax) - invoice = move_form.save() self.assertEqual(invoice.partner_id, self.partner) def test_00_fiscalyear_lock_date_month(self): @@ -510,7 +539,7 @@ class TestAssetManagement(AccountTestInvoicingCommon): asset.compute_depreciation_board() asset.validate() wiz_ctx = {"active_id": asset.id, "early_removal": True} - wiz = self.remove_model.with_context(wiz_ctx).create( + wiz = self.remove_model.with_context(**wiz_ctx).create( { "date_remove": "2019-01-31", "sale_value": 0.0, @@ -535,11 +564,10 @@ class TestAssetManagement(AccountTestInvoicingCommon): self.assertTrue(len(invoice.invoice_line_ids) > 0) line = invoice.invoice_line_ids[0] self.assertTrue(line.price_unit > 0.0) - move_form = Form(invoice) - with move_form.invoice_line_ids.edit(0) as line_form: - line_form.quantity = 2 - line_form.asset_profile_id = asset_profile - invoice = move_form.save() + invoice.invoice_line_ids[0].write( + {"quantity": 2, "asset_profile_id": asset_profile.id} + ) + invoice._onchange_invoice_line_ids() invoice.action_post() # get all asset after invoice validation current_asset = self.env["account.asset"].search([]) @@ -577,8 +605,7 @@ class TestAssetManagement(AccountTestInvoicingCommon): def test_11_assets_from_invoice(self): all_assets = self.env["account.asset"].search([]) ctx = dict(self.invoice_2._context) - del ctx["default_move_type"] - invoice = self.invoice_2.with_context(ctx) + invoice = self.invoice_2.with_context(**ctx) asset_profile = self.car5y asset_profile.asset_product_item = True # Compute depreciation lines on invoice validation @@ -837,7 +864,7 @@ class TestAssetManagement(AccountTestInvoicingCommon): ) wiz = Form( self.env["wiz.asset.move.reverse"].with_context( - { + **{ "active_model": depreciation_line._name, "active_id": depreciation_line.id, "active_ids": [depreciation_line.id], @@ -845,6 +872,7 @@ class TestAssetManagement(AccountTestInvoicingCommon): ) ) reverse_wizard = wiz.save() + reverse_wizard.write({"journal_id": depreciation_line.move_id.journal_id.id}) reverse_wizard.reverse_move() ict0.refresh() self.assertEqual(ict0.value_depreciated, 0) diff --git a/account_asset_management/views/account_asset.xml b/account_asset_management/views/account_asset.xml index 99f6e26c..377bce25 100644 --- a/account_asset_management/views/account_asset.xml +++ b/account_asset_management/views/account_asset.xml @@ -174,7 +174,6 @@ options="{'reload_on_button': true}" > @@ -252,7 +251,7 @@ - + @@ -290,7 +289,7 @@ account.asset.tree account.asset - + diff --git a/account_asset_management/views/account_asset_group.xml b/account_asset_management/views/account_asset_group.xml index f557df8e..2f08be64 100644 --- a/account_asset_management/views/account_asset_group.xml +++ b/account_asset_management/views/account_asset_group.xml @@ -1,53 +1,51 @@ - - - account.asset.group.form - account.asset.group - -
+ + account.asset.group.form + account.asset.group + + + - - - - - - + + + + - - -
- - account.asset.group.tree - account.asset.group - - - - - - - - - - - account.asset.group.search - account.asset.group - - - - - - - - - - Asset Groups - account.asset.group - tree,form - -
+ + +
+ + + account.asset.group.tree + account.asset.group + + + + + + + + + + + account.asset.group.search + account.asset.group + + + + + + + + + + Asset Groups + account.asset.group + tree,form +
diff --git a/account_asset_management/views/account_asset_profile.xml b/account_asset_management/views/account_asset_profile.xml index 1abcca13..0268f534 100644 --- a/account_asset_management/views/account_asset_profile.xml +++ b/account_asset_management/views/account_asset_profile.xml @@ -1,145 +1,143 @@ - - - account.asset.profile.form - account.asset.profile - -
- - -
-
+ + account.asset.profile.form + account.asset.profile + + + + +
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - -
- -
-
- - account.asset.profile.tree - account.asset.profile - - - - - - - - - - - - - - - - - - - - account.asset.profile.search - account.asset.profile - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + account.asset.profile.tree + account.asset.profile + + + + + + + + + + + + + + + + + + + + account.asset.profile.search + account.asset.profile + + + + + + + - - - - - - - - - Asset Profiles - account.asset.profile - tree,form - -
+ + + + + + + Asset Profiles + account.asset.profile + tree,form +
diff --git a/account_asset_management/wizard/account_asset_remove.py b/account_asset_management/wizard/account_asset_remove.py index 60a91de9..3dad7bec 100644 --- a/account_asset_management/wizard/account_asset_remove.py +++ b/account_asset_management/wizard/account_asset_remove.py @@ -32,9 +32,7 @@ class AccountAssetRemove(models.TransientModel): "in case of early removal", ) force_date = fields.Date(string="Force accounting date") - sale_value = fields.Float( - string="Sale Value", default=lambda self: self._default_sale_value() - ) + sale_value = fields.Float(default=lambda self: self._default_sale_value()) account_sale_id = fields.Many2one( comodel_name="account.account", string="Asset Sale Account", diff --git a/account_asset_management/wizard/wiz_asset_move_reverse.py b/account_asset_management/wizard/wiz_asset_move_reverse.py index 8f3d4eb3..7fd420b1 100644 --- a/account_asset_management/wizard/wiz_asset_move_reverse.py +++ b/account_asset_management/wizard/wiz_asset_move_reverse.py @@ -18,7 +18,7 @@ class WizAssetMoveReverse(models.TransientModel): required=True, default=fields.Date.context_today, ) - reason = fields.Char(string="Reason") + reason = fields.Char() journal_id = fields.Many2one( "account.journal", string="Use Specific Journal",