From cac7b29afe3a32bc9217dbd5e8a45b9f290d8181 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Fri, 2 Dec 2022 10:13:15 +0100 Subject: [PATCH] [IMP] assets_management: black, isort, prettier --- assets_management/__manifest__.py | 89 +-- assets_management/data/asset_data.xml | 4 +- assets_management/data/ir_cron.xml | 10 +- assets_management/models/account_account.py | 36 +- .../models/account_fiscal_year.py | 10 +- assets_management/models/account_invoice.py | 110 +-- .../models/account_invoice_line.py | 73 +- assets_management/models/account_journal.py | 20 +- assets_management/models/account_move.py | 117 +-- assets_management/models/account_move_line.py | 50 +- assets_management/models/asset.py | 188 ++--- .../models/asset_accounting_info.py | 151 ++-- assets_management/models/asset_category.py | 82 +- .../asset_category_depreciation_type.py | 36 +- .../models/asset_depreciation.py | 370 ++++----- .../models/asset_depreciation_line.py | 287 ++++--- .../models/asset_depreciation_line_type.py | 36 +- .../models/asset_depreciation_mode.py | 72 +- .../models/asset_depreciation_mode_line.py | 34 +- .../models/asset_depreciation_type.py | 35 +- assets_management/models/asset_tag.py | 11 +- assets_management/report/asset_journal.py | 739 ++++++++--------- .../report/asset_journal_xlsx.py | 712 ++++++++++------- assets_management/report/asset_previsional.py | 734 ++++++++--------- .../report/asset_previsional_xlsx.py | 651 ++++++++------- assets_management/report/layout.xml | 44 +- assets_management/report/paperformat.xml | 4 +- assets_management/report/reports.xml | 94 ++- .../report/templates/asset_journal.xml | 756 +++++++++++------- .../report/templates/asset_previsional.xml | 662 +++++++++------ assets_management/security/res_groups.xml | 6 +- assets_management/security/rules.xml | 44 +- assets_management/static/src/css/report.css | 74 +- .../tests/test_assets_management.py | 161 ++-- assets_management/views/account_invoice.xml | 174 ++-- assets_management/views/account_move.xml | 118 +-- assets_management/views/action_client.xml | 8 +- assets_management/views/asset.xml | 243 +++--- .../views/asset_accounting_info.xml | 143 ++-- assets_management/views/asset_category.xml | 65 +- .../views/asset_depreciation.xml | 224 +++--- .../views/asset_depreciation_line.xml | 210 ++--- .../views/asset_depreciation_line_type.xml | 30 +- .../views/asset_depreciation_mode.xml | 54 +- .../views/asset_depreciation_type.xml | 30 +- assets_management/views/asset_menuitems.xml | 60 +- assets_management/views/asset_tag.xml | 22 +- .../wizard/account_invoice_manage_asset.py | 536 +++++++------ .../account_invoice_manage_asset_view.xml | 437 +++++----- .../wizard/account_move_manage_asset.py | 576 ++++++------- .../wizard/account_move_manage_asset_view.xml | 376 +++++---- .../wizard/asset_generate_depreciation.py | 43 +- .../asset_generate_depreciation_view.xml | 88 +- .../wizard/asset_journal_report.py | 102 +-- .../wizard/asset_journal_report_view.xml | 87 +- .../wizard/asset_previsional_report.py | 102 +-- .../wizard/asset_previsional_report_view.xml | 87 +- 57 files changed, 5627 insertions(+), 4690 deletions(-) diff --git a/assets_management/__manifest__.py b/assets_management/__manifest__.py index c98ce0b52af0..53acd7fc5651 100644 --- a/assets_management/__manifest__.py +++ b/assets_management/__manifest__.py @@ -3,51 +3,50 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - 'name': 'ITA - Gestione Cespiti', - 'version': '12.0.1.0.0', - 'category': 'Localization/Italy', - 'summary': "Gestione Cespiti", - 'author': 'Openforce, Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/l10n-italy' - '/tree/12.0/assets_management', - 'license': 'AGPL-3', - 'depends': [ - 'account', - 'account_cancel', - 'account_financial_report', - 'account_fiscal_year', - 'mail', + "name": "ITA - Gestione Cespiti", + "version": "12.0.1.0.0", + "category": "Localization/Italy", + "summary": "Gestione Cespiti", + "author": "Openforce, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/l10n-italy" "/tree/12.0/assets_management", + "license": "AGPL-3", + "depends": [ + "account", + "account_cancel", + "account_financial_report", + "account_fiscal_year", + "mail", ], - 'data': [ - 'security/ir.model.access.csv', - 'security/res_groups.xml', - 'security/rules.xml', - 'data/ir_cron.xml', - 'data/asset_data.xml', - 'report/layout.xml', - 'report/paperformat.xml', - 'report/templates/asset_journal.xml', - 'report/templates/asset_previsional.xml', - 'report/reports.xml', - 'views/action_client.xml', - 'views/asset_menuitems.xml', - 'views/account_invoice.xml', - 'views/account_move.xml', - 'views/asset.xml', - 'views/asset_accounting_info.xml', - 'views/asset_category.xml', - 'views/asset_depreciation.xml', - 'views/asset_depreciation_line.xml', - 'views/asset_depreciation_line_type.xml', - 'views/asset_depreciation_mode.xml', - 'views/asset_depreciation_type.xml', - 'views/asset_tag.xml', - 'wizard/account_invoice_manage_asset_view.xml', - 'wizard/account_move_manage_asset_view.xml', - 'wizard/asset_generate_depreciation_view.xml', - 'wizard/asset_journal_report_view.xml', - 'wizard/asset_previsional_report_view.xml', + "data": [ + "security/ir.model.access.csv", + "security/res_groups.xml", + "security/rules.xml", + "data/ir_cron.xml", + "data/asset_data.xml", + "report/layout.xml", + "report/paperformat.xml", + "report/templates/asset_journal.xml", + "report/templates/asset_previsional.xml", + "report/reports.xml", + "views/action_client.xml", + "views/asset_menuitems.xml", + "views/account_invoice.xml", + "views/account_move.xml", + "views/asset.xml", + "views/asset_accounting_info.xml", + "views/asset_category.xml", + "views/asset_depreciation.xml", + "views/asset_depreciation_line.xml", + "views/asset_depreciation_line_type.xml", + "views/asset_depreciation_mode.xml", + "views/asset_depreciation_type.xml", + "views/asset_tag.xml", + "wizard/account_invoice_manage_asset_view.xml", + "wizard/account_move_manage_asset_view.xml", + "wizard/asset_generate_depreciation_view.xml", + "wizard/asset_journal_report_view.xml", + "wizard/asset_previsional_report_view.xml", ], - 'development_status': 'Beta', - 'installable': True, + "development_status": "Beta", + "installable": True, } diff --git a/assets_management/data/asset_data.xml b/assets_management/data/asset_data.xml index dec82812daf7..97c5236dbea6 100644 --- a/assets_management/data/asset_data.xml +++ b/assets_management/data/asset_data.xml @@ -1,4 +1,4 @@ - + @@ -36,7 +36,7 @@ 1 - + 1 1 0.5 diff --git a/assets_management/data/ir_cron.xml b/assets_management/data/ir_cron.xml index b4f3434c46da..c16b18077771 100644 --- a/assets_management/data/ir_cron.xml +++ b/assets_management/data/ir_cron.xml @@ -1,15 +1,15 @@ - + Vacuum Empty Asset Accounting Info - - + + 5 minutes -1 - - + + code model.cron_vacuum_table() diff --git a/assets_management/models/account_account.py b/assets_management/models/account_account.py index 9461fe000250..a48d2f3183d1 100644 --- a/assets_management/models/account_account.py +++ b/assets_management/models/account_account.py @@ -7,23 +7,31 @@ class AccountAccount(models.Model): - _inherit = 'account.account' + _inherit = "account.account" @api.multi def unlink(self): - if self.env['asset.category'].sudo().search([ - '|', - '|', - '|', - '|', - ('asset_account_id', 'in', self.ids), - ('depreciation_account_id', 'in', self.ids), - ('fund_account_id', 'in', self.ids), - ('gain_account_id', 'in', self.ids), - ('loss_account_id', 'in', self.ids), - ]): + if ( + self.env["asset.category"] + .sudo() + .search( + [ + "|", + "|", + "|", + "|", + ("asset_account_id", "in", self.ids), + ("depreciation_account_id", "in", self.ids), + ("fund_account_id", "in", self.ids), + ("gain_account_id", "in", self.ids), + ("loss_account_id", "in", self.ids), + ] + ) + ): raise UserError( - _("Cannot delete accounts while they're still used" - " by asset categories.") + _( + "Cannot delete accounts while they're still used" + " by asset categories." + ) ) return super().unlink() diff --git a/assets_management/models/account_fiscal_year.py b/assets_management/models/account_fiscal_year.py index 1aa24a3484c1..64d697d50dce 100644 --- a/assets_management/models/account_fiscal_year.py +++ b/assets_management/models/account_fiscal_year.py @@ -7,12 +7,10 @@ class AccountFiscalYear(models.Model): - _inherit = 'account.fiscal.year' + _inherit = "account.fiscal.year" @api.model - def get_fiscal_year_by_date( - self, date, limit=1, company=None, miss_raise=True - ): + def get_fiscal_year_by_date(self, date, limit=1, company=None, miss_raise=True): """ Retrieves fiscal year by given ``date`` (a datetime.date object). @@ -33,7 +31,7 @@ def get_fiscal_year_by_date_domain(self, date, company=None): """ Prepares a search() domain to retrieve fiscal years by given ``date``. """ - domain = [('date_from', '<=', date), ('date_to', '>=', date)] + domain = [("date_from", "<=", date), ("date_to", ">=", date)] if company: - domain.append(('company_id', 'in', company.ids)) + domain.append(("company_id", "in", company.ids)) return domain diff --git a/assets_management/models/account_invoice.py b/assets_management/models/account_invoice.py index 859b5761e7db..4962c163d702 100644 --- a/assets_management/models/account_invoice.py +++ b/assets_management/models/account_invoice.py @@ -7,43 +7,39 @@ class AccountInvoice(models.Model): - _inherit = 'account.invoice' + _inherit = "account.invoice" asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'invoice_id', - string="Assets Accounting Info" + "asset.accounting.info", "invoice_id", string="Assets Accounting Info" ) asset_ids = fields.Many2many( - 'asset.asset', - compute='_compute_asset_data', - store=True, - string="Assets" + "asset.asset", compute="_compute_asset_data", store=True, string="Assets" ) dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - compute='_compute_asset_data', + "asset.depreciation.line", + compute="_compute_asset_data", store=True, - string="Depreciation Lines" + string="Depreciation Lines", ) hide_link_asset_button = fields.Boolean( - compute='_compute_hide_link_asset_button', + compute="_compute_hide_link_asset_button", default=True, string="Hide Asset Button", ) - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for inv in self: - comp = inv.get_linked_aa_info_records().mapped('company_id') + comp = inv.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != inv.company_id): raise ValidationError( - _("`{}`: cannot change invoice's company once it's already" - " related to an asset.") - .format(inv.name_get()[0][-1]) + _( + "`{}`: cannot change invoice's company once it's already" + " related to an asset." + ).format(inv.name_get()[0][-1]) ) @api.multi @@ -53,43 +49,45 @@ def action_invoice_cancel(self): # Remove every a.a.info related to current invoices, and delete # related depreciation lines aa_infos = self.mapped(lambda i: i.get_linked_aa_info_records()) - dep_lines = aa_infos.mapped('dep_line_id') + dep_lines = aa_infos.mapped("dep_line_id") aa_infos.unlink() # Filtering needed: cannot delete dep lines with a.a.info - dep_lines.filtered( - lambda l: not l.asset_accounting_info_ids - ).unlink() + dep_lines.filtered(lambda l: not l.asset_accounting_info_ids).unlink() return res @api.multi @api.depends( - 'asset_accounting_info_ids', - 'asset_accounting_info_ids.asset_id', - 'asset_accounting_info_ids.dep_line_id', + "asset_accounting_info_ids", + "asset_accounting_info_ids.asset_id", + "asset_accounting_info_ids.dep_line_id", ) def _compute_asset_data(self): for inv in self: aa_info = inv.get_linked_aa_info_records() - assets = aa_info.mapped('asset_id') - dep_lines = aa_info.mapped('dep_line_id') + assets = aa_info.mapped("asset_id") + dep_lines = aa_info.mapped("dep_line_id") if dep_lines: - assets += dep_lines.mapped('asset_id') - inv.update({ - 'asset_ids': [(6, 0, assets.ids)], - 'dep_line_ids': [(6, 0, dep_lines.ids)] - }) + assets += dep_lines.mapped("asset_id") + inv.update( + { + "asset_ids": [(6, 0, assets.ids)], + "dep_line_ids": [(6, 0, dep_lines.ids)], + } + ) @api.multi def _compute_hide_link_asset_button(self): valid_account_ids = self.get_valid_accounts() if not valid_account_ids: - self.update({'hide_link_asset_button': True}) + self.update({"hide_link_asset_button": True}) else: for inv in self: - inv.hide_link_asset_button = not any([ - l.account_id.id in valid_account_ids.ids - for l in inv.invoice_line_ids - ]) or inv.state in ('draft', 'cancel') + inv.hide_link_asset_button = not any( + [ + l.account_id.id in valid_account_ids.ids + for l in inv.invoice_line_ids + ] + ) or inv.state in ("draft", "cancel") @api.multi def open_wizard_manage_asset(self): @@ -98,31 +96,33 @@ def open_wizard_manage_asset(self): lambda l: not l.asset_accounting_info_ids ) if not lines: - raise ValidationError( - _("Every line is already linked to an asset.") - ) + raise ValidationError(_("Every line is already linked to an asset.")) - xmlid = 'assets_management.action_wizard_invoice_manage_asset' + xmlid = "assets_management.action_wizard_invoice_manage_asset" act = self.env.ref(xmlid).read()[0] ctx = dict(self._context) - ctx.update({ - 'default_company_id': self.company_id.id, - 'default_dismiss_date': self.date_invoice or self.date_due, - 'default_invoice_ids': [(6, 0, self.ids)], - 'default_invoice_line_ids': [(6, 0, lines.ids)], - 'default_purchase_date': self.date_invoice or self.date_due, - 'invoice_ids': self.ids, - }) - act.update({'context': ctx}) + ctx.update( + { + "default_company_id": self.company_id.id, + "default_dismiss_date": self.date_invoice or self.date_due, + "default_invoice_ids": [(6, 0, self.ids)], + "default_invoice_line_ids": [(6, 0, lines.ids)], + "default_purchase_date": self.date_invoice or self.date_due, + "invoice_ids": self.ids, + } + ) + act.update({"context": ctx}) return act def get_linked_aa_info_records(self): self.ensure_one() - return self.env['asset.accounting.info'].search([ - '|', - ('invoice_id', '=', self.id), - ('invoice_line_id.invoice_id', '=', self.id), - ]) + return self.env["asset.accounting.info"].search( + [ + "|", + ("invoice_id", "=", self.id), + ("invoice_line_id.invoice_id", "=", self.id), + ] + ) def get_valid_accounts(self): - return self.env['asset.category'].search([]).mapped('asset_account_id') + return self.env["asset.category"].search([]).mapped("asset_account_id") diff --git a/assets_management/models/account_invoice_line.py b/assets_management/models/account_invoice_line.py index 9789781dfda2..ad454ba9c1c9 100644 --- a/assets_management/models/account_invoice_line.py +++ b/assets_management/models/account_invoice_line.py @@ -7,63 +7,61 @@ class AccountInvoiceLine(models.Model): - _inherit = 'account.invoice.line' + _inherit = "account.invoice.line" asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'invoice_line_id', - string="Assets Accounting Info" + "asset.accounting.info", "invoice_line_id", string="Assets Accounting Info" ) asset_ids = fields.Many2many( - 'asset.asset', - compute='_compute_asset_data', - store=True, - string="Assets" + "asset.asset", compute="_compute_asset_data", store=True, string="Assets" ) dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - compute='_compute_asset_data', + "asset.depreciation.line", + compute="_compute_asset_data", store=True, - string="Depreciation Lines" + string="Depreciation Lines", ) - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for inv_line in self: - comp = inv_line.get_linked_aa_info_records().mapped('company_id') + comp = inv_line.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != inv_line.company_id): raise ValidationError( - _("`{}`: cannot change invoice line's company once it's" - " already related to an asset.") - .format(inv_line.name_get()[0][-1]) + _( + "`{}`: cannot change invoice line's company once it's" + " already related to an asset." + ).format(inv_line.name_get()[0][-1]) ) @api.multi - @api.depends('asset_accounting_info_ids', - 'asset_accounting_info_ids.asset_id', - 'asset_accounting_info_ids.dep_line_id') + @api.depends( + "asset_accounting_info_ids", + "asset_accounting_info_ids.asset_id", + "asset_accounting_info_ids.dep_line_id", + ) def _compute_asset_data(self): for line in self: aa_info = line.get_linked_aa_info_records() - assets = aa_info.mapped('asset_id') - dep_lines = aa_info.mapped('dep_line_id') + assets = aa_info.mapped("asset_id") + dep_lines = aa_info.mapped("dep_line_id") if dep_lines: - assets += dep_lines.mapped('asset_id') - line.update({ - 'asset_ids': [(6, 0, assets.ids)], - 'dep_line_ids': [(6, 0, dep_lines.ids)], - }) + assets += dep_lines.mapped("asset_id") + line.update( + { + "asset_ids": [(6, 0, assets.ids)], + "dep_line_ids": [(6, 0, dep_lines.ids)], + } + ) def get_asset_purchase_amount(self, currency=None): purchase_amount = 0 for line in self: # Standard line amount - purchase_amount += line.currency_id.compute( - line.price_subtotal, currency - ) + purchase_amount += line.currency_id.compute(line.price_subtotal, currency) if line.invoice_line_tax_ids: # Get taxes discount = line.price_unit * (line.discount or 0.0) / 100 @@ -72,16 +70,19 @@ def get_asset_purchase_amount(self, currency=None): qty = line.quantity product = line.product_id partner = line.invoice_id.partner_id - taxes = line.invoice_line_tax_ids.compute_all( - price_unit, line_currency, qty, product, partner - ).get('taxes') or [] + taxes = ( + line.invoice_line_tax_ids.compute_all( + price_unit, line_currency, qty, product, partner + ).get("taxes") + or [] + ) # Add non-deductible taxes for tax_dict in taxes: - if not (tax_dict.get('account_id') - or tax_dict.get('refund_account_id')) \ - and tax_dict.get('amount'): + if not ( + tax_dict.get("account_id") or tax_dict.get("refund_account_id") + ) and tax_dict.get("amount"): purchase_amount += line.currency_id.compute( - tax_dict.get('amount'), currency + tax_dict.get("amount"), currency ) return purchase_amount diff --git a/assets_management/models/account_journal.py b/assets_management/models/account_journal.py index c831dc1b89e9..a6668629bc33 100644 --- a/assets_management/models/account_journal.py +++ b/assets_management/models/account_journal.py @@ -7,15 +7,23 @@ class AccountJournal(models.Model): - _inherit = 'account.journal' + _inherit = "account.journal" @api.multi def unlink(self): - if self.env['asset.category'].sudo().search([ - ('journal_id', 'in', self.ids), - ]): + if ( + self.env["asset.category"] + .sudo() + .search( + [ + ("journal_id", "in", self.ids), + ] + ) + ): raise UserError( - _("Cannot delete journals while they're still used" - " by asset categories.") + _( + "Cannot delete journals while they're still used" + " by asset categories." + ) ) return super().unlink() diff --git a/assets_management/models/account_move.py b/assets_management/models/account_move.py index cb80fa0654a6..175951cc24d5 100644 --- a/assets_management/models/account_move.py +++ b/assets_management/models/account_move.py @@ -7,43 +7,39 @@ class AccountMove(models.Model): - _inherit = 'account.move' + _inherit = "account.move" asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'move_id', - string="Assets Accounting Info" + "asset.accounting.info", "move_id", string="Assets Accounting Info" ) asset_ids = fields.Many2many( - 'asset.asset', - compute='_compute_asset_data', - store=True, - string="Assets" + "asset.asset", compute="_compute_asset_data", store=True, string="Assets" ) dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - compute='_compute_asset_data', + "asset.depreciation.line", + compute="_compute_asset_data", store=True, - string="Depreciation Lines" + string="Depreciation Lines", ) hide_link_asset_button = fields.Boolean( - compute='_compute_hide_link_asset_button', + compute="_compute_hide_link_asset_button", default=True, string="Hide Asset Button", ) - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for move in self: - comp = move.get_linked_aa_info_records().mapped('company_id') + comp = move.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != move.company_id): raise ValidationError( - _("`{}`: cannot change move's company once it's already" - " related to an asset.") - .format(move.name_get()[0][-1]) + _( + "`{}`: cannot change move's company once it's already" + " related to an asset." + ).format(move.name_get()[0][-1]) ) @api.multi @@ -53,76 +49,81 @@ def button_cancel(self): # Remove every a.a.info related to current moves, and delete # related depreciation lines aa_infos = self.mapped(lambda m: m.get_linked_aa_info_records()) - dep_lines = aa_infos.mapped('dep_line_id') + dep_lines = aa_infos.mapped("dep_line_id") aa_infos.unlink() # Filtering needed: cannot delete dep lines with a.a.info - dep_lines.filtered( - lambda l: not l.asset_accounting_info_ids - ).unlink() + dep_lines.filtered(lambda l: not l.asset_accounting_info_ids).unlink() return res @api.multi @api.depends( - 'asset_accounting_info_ids', - 'asset_accounting_info_ids.asset_id', - 'asset_accounting_info_ids.dep_line_id', + "asset_accounting_info_ids", + "asset_accounting_info_ids.asset_id", + "asset_accounting_info_ids.dep_line_id", ) def _compute_asset_data(self): for move in self: aa_info = move.get_linked_aa_info_records() - assets = aa_info.mapped('asset_id') - dep_lines = aa_info.mapped('dep_line_id') + assets = aa_info.mapped("asset_id") + dep_lines = aa_info.mapped("dep_line_id") if dep_lines: - assets += dep_lines.mapped('asset_id') - move.update({ - 'asset_ids': [(6, 0, assets.ids)], - 'dep_line_ids': [(6, 0, dep_lines.ids)] - }) + assets += dep_lines.mapped("asset_id") + move.update( + { + "asset_ids": [(6, 0, assets.ids)], + "dep_line_ids": [(6, 0, dep_lines.ids)], + } + ) @api.multi def _compute_hide_link_asset_button(self): valid_account_ids = self.get_valid_accounts() if not valid_account_ids: - self.update({'hide_link_asset_button': True}) + self.update({"hide_link_asset_button": True}) else: for move in self: - move.hide_link_asset_button = not any([ - l.account_id.id in valid_account_ids.ids - for l in move.line_ids - ]) or move.state != 'posted' + move.hide_link_asset_button = ( + not any( + [ + l.account_id.id in valid_account_ids.ids + for l in move.line_ids + ] + ) + or move.state != "posted" + ) @api.multi def open_wizard_manage_asset(self): self.ensure_one() - lines = self.line_ids.filtered( - lambda l: not l.asset_accounting_info_ids - ) + lines = self.line_ids.filtered(lambda l: not l.asset_accounting_info_ids) if not lines: - raise ValidationError( - _("Every line is already linked to an asset.") - ) + raise ValidationError(_("Every line is already linked to an asset.")) - xmlid = 'assets_management.action_wizard_account_move_manage_asset' + xmlid = "assets_management.action_wizard_account_move_manage_asset" act = self.env.ref(xmlid).read()[0] ctx = dict(self._context) - ctx.update({ - 'default_company_id': self.company_id.id, - 'default_dismiss_date': self.date or fields.Date.today(), - 'default_move_ids': [(6, 0, self.ids)], - 'default_move_line_ids': [(6, 0, lines.ids)], - 'default_purchase_date': self.date or fields.Date.today(), - 'move_ids': self.ids, - }) - act.update({'context': ctx}) + ctx.update( + { + "default_company_id": self.company_id.id, + "default_dismiss_date": self.date or fields.Date.today(), + "default_move_ids": [(6, 0, self.ids)], + "default_move_line_ids": [(6, 0, lines.ids)], + "default_purchase_date": self.date or fields.Date.today(), + "move_ids": self.ids, + } + ) + act.update({"context": ctx}) return act def get_linked_aa_info_records(self): self.ensure_one() - return self.env['asset.accounting.info'].search([ - '|', - ('move_id', '=', self.id), - ('move_line_id.move_id', '=', self.id), - ]) + return self.env["asset.accounting.info"].search( + [ + "|", + ("move_id", "=", self.id), + ("move_line_id.move_id", "=", self.id), + ] + ) def get_valid_accounts(self): - return self.env['asset.category'].search([]).mapped('asset_account_id') + return self.env["asset.category"].search([]).mapped("asset_account_id") diff --git a/assets_management/models/account_move_line.py b/assets_management/models/account_move_line.py index 3be8346c9c65..5f0bfdf113ce 100644 --- a/assets_management/models/account_move_line.py +++ b/assets_management/models/account_move_line.py @@ -7,56 +7,54 @@ class AccountMoveLine(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move.line" asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'move_line_id', - string="Assets Accounting Info" + "asset.accounting.info", "move_line_id", string="Assets Accounting Info" ) asset_ids = fields.Many2many( - 'asset.asset', - compute='_compute_asset_data', - store=True, - string="Assets" + "asset.asset", compute="_compute_asset_data", store=True, string="Assets" ) dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - compute='_compute_asset_data', + "asset.depreciation.line", + compute="_compute_asset_data", store=True, - string="Depreciation Lines" + string="Depreciation Lines", ) - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for move_line in self: - comp = move_line.get_linked_aa_info_records().mapped('company_id') + comp = move_line.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != move_line.company_id): raise ValidationError( - _("`{}`: cannot change move line's company once it's" - " already related to an asset.") - .format(move_line.name_get()[0][-1]) + _( + "`{}`: cannot change move line's company once it's" + " already related to an asset." + ).format(move_line.name_get()[0][-1]) ) @api.multi @api.depends( - 'asset_accounting_info_ids', - 'asset_accounting_info_ids.asset_id', - 'asset_accounting_info_ids.dep_line_id', + "asset_accounting_info_ids", + "asset_accounting_info_ids.asset_id", + "asset_accounting_info_ids.dep_line_id", ) def _compute_asset_data(self): for line in self: aa_info = line.get_linked_aa_info_records() - assets = aa_info.mapped('asset_id') - dep_lines = aa_info.mapped('dep_line_id') + assets = aa_info.mapped("asset_id") + dep_lines = aa_info.mapped("dep_line_id") if dep_lines: - assets += dep_lines.mapped('asset_id') - line.update({ - 'asset_ids': [(6, 0, assets.ids)], - 'dep_line_ids': [(6, 0, dep_lines.ids)], - }) + assets += dep_lines.mapped("asset_id") + line.update( + { + "asset_ids": [(6, 0, assets.ids)], + "dep_line_ids": [(6, 0, dep_lines.ids)], + } + ) def get_asset_purchase_amount(self, currency=None): purchase_amount = 0 diff --git a/assets_management/models/asset.py b/assets_management/models/asset.py index 7c9ebd3c7b60..6f0140a414fe 100644 --- a/assets_management/models/asset.py +++ b/assets_management/models/asset.py @@ -7,23 +7,21 @@ class Asset(models.Model): - _name = 'asset.asset' + _name = "asset.asset" _description = "Assets" - _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] - _order = 'purchase_date desc, name asc' + _inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"] + _order = "purchase_date desc, name asc" @api.model def get_default_company_id(self): return self.env.user.company_id asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'asset_id', - string="Accounting Info" + "asset.accounting.info", "asset_id", string="Accounting Info" ) category_id = fields.Many2one( - 'asset.category', + "asset.category", required=True, string="Category", ) @@ -34,97 +32,75 @@ def get_default_company_id(self): ) company_id = fields.Many2one( - 'res.company', + "res.company", default=get_default_company_id, required=True, string="Company", - track_visibility='onchange', + track_visibility="onchange", ) currency_id = fields.Many2one( - 'res.currency', + "res.currency", required=True, string="Currency", ) - customer_id = fields.Many2one( - 'res.partner', - string="Customer" - ) + customer_id = fields.Many2one("res.partner", string="Customer") depreciation_ids = fields.One2many( - 'asset.depreciation', - 'asset_id', + "asset.depreciation", + "asset_id", string="Depreciations", ) name = fields.Char( required=True, string="Name", - track_visibility='onchange', + track_visibility="onchange", ) purchase_amount = fields.Monetary( string="Purchase Value", - track_visibility='onchange', + track_visibility="onchange", ) purchase_date = fields.Date( default=fields.Date.today(), string="Purchase Date", - track_visibility='onchange', + track_visibility="onchange", ) - purchase_invoice_id = fields.Many2one( - 'account.invoice', - string="Purchase Invoice" - ) + purchase_invoice_id = fields.Many2one("account.invoice", string="Purchase Invoice") - purchase_move_id = fields.Many2one( - 'account.move', - string="Purchase Move" - ) + purchase_move_id = fields.Many2one("account.move", string="Purchase Move") sale_amount = fields.Monetary( string="Sale Value", ) - sale_date = fields.Date( - string="Sale Date" - ) + sale_date = fields.Date(string="Sale Date") - sale_invoice_id = fields.Many2one( - 'account.invoice', - string="Sale Invoice" - ) + sale_invoice_id = fields.Many2one("account.invoice", string="Sale Invoice") - sale_move_id = fields.Many2one( - 'account.move', - string="Sale Move" - ) + sale_move_id = fields.Many2one("account.move", string="Sale Move") - sold = fields.Boolean( - string="Sold" - ) + sold = fields.Boolean(string="Sold") state = fields.Selection( - [('non_depreciated', "Non Depreciated"), - ('partially_depreciated', "Partially Depreciated"), - ('totally_depreciated', "Depreciated")], - compute='_compute_state', - default='non_depreciated', + [ + ("non_depreciated", "Non Depreciated"), + ("partially_depreciated", "Partially Depreciated"), + ("totally_depreciated", "Depreciated"), + ], + compute="_compute_state", + default="non_depreciated", store=True, - string="State" + string="State", ) - supplier_id = fields.Many2one( - 'res.partner', - string="Supplier" - ) + supplier_id = fields.Many2one("res.partner", string="Supplier") - supplier_ref = fields.Char( - string="Supplier Ref." - ) + supplier_ref = fields.Char(string="Supplier Ref.") used = fields.Boolean( string="Used", @@ -134,10 +110,10 @@ def get_default_company_id(self): def create(self, vals): # Add depreciation if it's missing while category is set create_deps_from_categ = False - if vals.get('category_id') and not vals.get('depreciation_ids'): + if vals.get("category_id") and not vals.get("depreciation_ids"): create_deps_from_categ = True - if vals.get('code'): - vals['code'] = ' '.join(vals.get('code').split()) + if vals.get("code"): + vals["code"] = " ".join(vals.get("code").split()) asset = super().create(vals) if create_deps_from_categ: asset.onchange_category_id() @@ -145,52 +121,58 @@ def create(self, vals): @api.multi def write(self, vals): - if vals.get('code'): - vals['code'] = ' '.join(vals.get('code').split()) + if vals.get("code"): + vals["code"] = " ".join(vals.get("code").split()) return super().write(vals) @api.multi def unlink(self): - if self.mapped('asset_accounting_info_ids'): - assets = self.filtered('asset_accounting_info_ids') + if self.mapped("asset_accounting_info_ids"): + assets = self.filtered("asset_accounting_info_ids") name_list = "\n".join([a[-1] for a in assets.name_get()]) raise ValidationError( - _("The assets you are trying to delete are currently linked" - " to accounting info. Please remove them if necessary" - " before removing these assets:\n") + name_list + _( + "The assets you are trying to delete are currently linked" + " to accounting info. Please remove them if necessary" + " before removing these assets:\n" + ) + + name_list ) - self.mapped('depreciation_ids').unlink() + self.mapped("depreciation_ids").unlink() return super().unlink() @api.multi def name_get(self): return [(asset.id, asset.make_name()) for asset in self] - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for asset in self: - comp = asset.get_linked_aa_info_records().mapped('company_id') + comp = asset.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != asset.company_id): raise ValidationError( - _("`{}`: cannot change asset's company once it's already" - " related to accounting info.") - .format(asset.make_name()) + _( + "`{}`: cannot change asset's company once it's already" + " related to accounting info." + ).format(asset.make_name()) ) @api.multi - @api.depends('depreciation_ids', 'depreciation_ids.state') + @api.depends("depreciation_ids", "depreciation_ids.state") def _compute_state(self): for asset in self: asset.state = asset.get_asset_state() - @api.onchange('category_id') + @api.onchange("category_id") def onchange_category_id(self): # Do not allow category changes if any depreciation line is already # linked to an account move - if any(self.depreciation_ids.mapped('line_ids.move_id')): + if any(self.depreciation_ids.mapped("line_ids.move_id")): raise ValidationError( - _("Cannot change category for an asset that's already been" - " depreciated.") + _( + "Cannot change category for an asset that's already been" + " depreciated." + ) ) if self.category_id: @@ -204,18 +186,18 @@ def onchange_category_id(self): self.onchange_purchase_amount() self.onchange_purchase_date() - @api.onchange('company_id') + @api.onchange("company_id") def onchange_company_currency(self): if self.company_id: self.currency_id = self.company_id.currency_id - @api.onchange('purchase_amount') + @api.onchange("purchase_amount") def onchange_purchase_amount(self): if self.purchase_amount: for dep in self.depreciation_ids: dep.amount_depreciable = self.purchase_amount * dep.base_coeff - if self.depreciation_ids.mapped('line_ids').filtered( - lambda l: l.move_type == 'depreciated' + if self.depreciation_ids.mapped("line_ids").filtered( + lambda l: l.move_type == "depreciated" ): title = _("Warning!") msg = _( @@ -224,9 +206,9 @@ def onchange_purchase_amount(self): " upon depreciation lines, which will have to be updated" " manually." ) - return {'warning': {'title': title, 'message': msg}} + return {"warning": {"title": title, "message": msg}} - @api.onchange('purchase_date') + @api.onchange("purchase_date") def onchange_purchase_date(self): if self.purchase_date: for dep in self.depreciation_ids: @@ -235,42 +217,46 @@ def onchange_purchase_date(self): @api.multi def launch_wizard_generate_depreciations(self): self.ensure_one() - xmlid = 'assets_management.action_wizard_asset_generate_depreciation' + xmlid = "assets_management.action_wizard_asset_generate_depreciation" [act] = self.env.ref(xmlid).read() ctx = dict(self._context) - ctx.update({ - 'default_asset_ids': [(6, 0, self.ids)], - 'default_category_ids': [(6, 0, self.category_id.ids)], - 'default_company_id': self.company_id.id, - 'default_date': fields.Date.today(), - 'default_type_ids': [ - (6, 0, self.depreciation_ids.mapped('type_id').ids) - ], - }) - act['context'] = ctx + ctx.update( + { + "default_asset_ids": [(6, 0, self.ids)], + "default_category_ids": [(6, 0, self.category_id.ids)], + "default_company_id": self.company_id.id, + "default_date": fields.Date.today(), + "default_type_ids": [ + (6, 0, self.depreciation_ids.mapped("type_id").ids) + ], + } + ) + act["context"] = ctx return act def get_asset_state(self): self.ensure_one() if not self.depreciation_ids: - return 'non_depreciated' + return "non_depreciated" - states = tuple(set(self.depreciation_ids.mapped('state'))) + states = tuple(set(self.depreciation_ids.mapped("state"))) if not states: - return 'non_depreciated' + return "non_depreciated" elif len(states) == 1: return states[0] else: - return 'partially_depreciated' + return "partially_depreciated" def get_linked_aa_info_records(self): self.ensure_one() - return self.env['asset.accounting.info'].search([ - '|', - ('asset_id', '=', self.id), - ('dep_line_id.asset_id', '=', self.id), - ]) + return self.env["asset.accounting.info"].search( + [ + "|", + ("asset_id", "=", self.id), + ("dep_line_id.asset_id", "=", self.id), + ] + ) def make_name(self): self.ensure_one() diff --git a/assets_management/models/asset_accounting_info.py b/assets_management/models/asset_accounting_info.py index 5fc088510029..de1f8744c05b 100644 --- a/assets_management/models/asset_accounting_info.py +++ b/assets_management/models/asset_accounting_info.py @@ -25,59 +25,45 @@ class AssetAccountingInfo(models.Model): ``vals`` dictionary. """ - _name = 'asset.accounting.info' + _name = "asset.accounting.info" _description = "Asset Accounting Relations" - _table = 'asset_accounting_info' + _table = "asset_accounting_info" - asset_id = fields.Many2one( - 'asset.asset', - ondelete='set null', - string="Asset" - ) + asset_id = fields.Many2one("asset.asset", ondelete="set null", string="Asset") company_id = fields.Many2one( - 'res.company', + "res.company", readonly=True, string="Company", ) dep_line_id = fields.Many2one( - 'asset.depreciation.line', - ondelete='set null', - string="Depreciation Line" + "asset.depreciation.line", ondelete="set null", string="Depreciation Line" ) invoice_id = fields.Many2one( - 'account.invoice', - ondelete='set null', - string="Invoice" + "account.invoice", ondelete="set null", string="Invoice" ) invoice_line_id = fields.Many2one( - 'account.invoice.line', - ondelete='set null', - string="Invoice Line" + "account.invoice.line", ondelete="set null", string="Invoice Line" ) - move_id = fields.Many2one( - 'account.move', - ondelete='set null', - string="Move" - ) + move_id = fields.Many2one("account.move", ondelete="set null", string="Move") move_line_id = fields.Many2one( - 'account.move.line', - ondelete='set null', - string="Move Line" + "account.move.line", ondelete="set null", string="Move Line" ) relation_type = fields.Selection( - [('create', "Asset Creation"), - ('update', "Asset Update"), - ('partial_dismiss', "Asset Partial Dismissal"), - ('dismiss', "Asset Dismissal")], + [ + ("create", "Asset Creation"), + ("update", "Asset Update"), + ("partial_dismiss", "Asset Partial Dismissal"), + ("dismiss", "Asset Dismissal"), + ], required=True, - string="Relation Type" + string="Relation Type", ) @api.model @@ -92,9 +78,9 @@ def write(self, vals): # ``load=''`` avoids returning tuple ``(rec.id, rec.name)`` for M2o # fields and simply returns ``rec.id`` - old_info_vals = {d['id']: d for d in self.read(fnames, load='')} + old_info_vals = {d["id"]: d for d in self.read(fnames, load="")} res = super().write(vals) - new_info_vals = {d['id']: d for d in self.read(fnames, load='')} + new_info_vals = {d["id"]: d for d in self.read(fnames, load="")} # old/new_info_vals dicts both have the same keys to_check_ids = [] @@ -116,21 +102,24 @@ def name_get(self): @api.model def cron_vacuum_table(self): - """ A cron that deletes obsolete records """ + """A cron that deletes obsolete records""" aa_info = self.get_records_to_delete_by_cron() aa_info.unlink() @api.model def get_main_fields(self): return [ - 'asset_id', 'dep_line_id', - 'invoice_id', 'invoice_line_id', - 'move_id', 'move_line_id' + "asset_id", + "dep_line_id", + "invoice_id", + "invoice_line_id", + "move_id", + "move_line_id", ] @api.multi def button_unlink(self): - """ Button action: deletes a.a.info """ + """Button action: deletes a.a.info""" self.unlink() def check_and_normalize(self): @@ -139,45 +128,46 @@ def check_and_normalize(self): info.normalize_info() def check_coherence(self): - """ Checks info coherence """ + """Checks info coherence""" self.check_company_coherence() self.check_data_coherence() def check_company_coherence(self): - """ Checks companies """ + """Checks companies""" self.ensure_one() companies = self.get_all_companies() if len(companies) > 1: - raise ValidationError( - _("Incoherent company data.") - ) + raise ValidationError(_("Incoherent company data.")) def check_data_coherence(self): self.ensure_one() # If dep_line_id and asset_id are set, check whether the depreciation # line belongs to the given asset - if self.asset_id and self.dep_line_id \ - and self.asset_id != self.dep_line_id.depreciation_id.asset_id: - raise ValidationError( - _("Incoherent asset data.") - ) + if ( + self.asset_id + and self.dep_line_id + and self.asset_id != self.dep_line_id.depreciation_id.asset_id + ): + raise ValidationError(_("Incoherent asset data.")) # If invoice_line_id and invoice_id are set, check whether the invoice # line belongs to the given invoice - if self.invoice_id and self.invoice_line_id \ - and self.invoice_id != self.invoice_line_id.invoice_id: - raise ValidationError( - _("Incoherent invoice data.") - ) + if ( + self.invoice_id + and self.invoice_line_id + and self.invoice_id != self.invoice_line_id.invoice_id + ): + raise ValidationError(_("Incoherent invoice data.")) # If move_line_id and move_id are set, check whether the move line # belongs to the given move - if self.move_id and self.move_line_id \ - and self.move_id != self.move_line_id.move_id: - raise ValidationError( - _("Incoherent move data.") - ) + if ( + self.move_id + and self.move_line_id + and self.move_id != self.move_line_id.move_id + ): + raise ValidationError(_("Incoherent move data.")) def get_all_companies(self): company_ids = [] @@ -190,7 +180,7 @@ def get_all_companies(self): if rec and rec.company_id.id not in company_ids: company_ids.append(rec.company_id.id) - return self.env['res.company'].browse(company_ids) + return self.env["res.company"].browse(company_ids) def get_normalized_info_vals(self): self.ensure_one() @@ -198,22 +188,22 @@ def get_normalized_info_vals(self): # Set asset as dep line's asset if dep line is set if not self.asset_id and self.dep_line_id: - vals['asset_id'] = self.dep_line_id.asset_id.id + vals["asset_id"] = self.dep_line_id.asset_id.id # Set invoice_id as invoice line's invoice if invoice line is set if not self.invoice_id and self.invoice_line_id: - vals['invoice_id'] = self.invoice_line_id.invoice_id.id + vals["invoice_id"] = self.invoice_line_id.invoice_id.id # Set move_id as move line's move if move line is set if not self.move_id and self.move_line_id: - vals['move_id'] = self.move_line_id.move_id.id + vals["move_id"] = self.move_line_id.move_id.id # Set company companies = self.get_all_companies() if len(companies) == 1: - vals['company_id'] = companies.id + vals["company_id"] = companies.id else: - vals['company_id'] = False + vals["company_id"] = False return vals @@ -224,19 +214,21 @@ def get_records_to_delete_by_cron(self): OR (no invoice AND no invoice line AND no move AND no move line) """ - return self.search([ - '|', - '&', - ('asset_id', '=', False), - ('dep_line_id', '=', False), - '&', - '&', - '&', - ('invoice_id', '=', False), - ('invoice_line_id', '=', False), - ('move_id', '=', False), - ('move_line_id', '=', False), - ]) + return self.search( + [ + "|", + "&", + ("asset_id", "=", False), + ("dep_line_id", "=", False), + "&", + "&", + "&", + ("invoice_id", "=", False), + ("invoice_line_id", "=", False), + ("move_id", "=", False), + ("move_line_id", "=", False), + ] + ) def make_name(self): self.ensure_one() @@ -244,14 +236,15 @@ def make_name(self): name = self.asset_id.make_name() else: name = _("Unknown Asset") - relation_name = dict(self._fields['relation_type'].selection) \ - .get(self.relation_type) + relation_name = dict(self._fields["relation_type"].selection).get( + self.relation_type + ) if relation_name: name += " - " + relation_name return name.strip() def normalize_info(self): - """ Normalize asset accounting info if needed """ + """Normalize asset accounting info if needed""" self.ensure_one() vals = self.get_normalized_info_vals() if vals: diff --git a/assets_management/models/asset_category.py b/assets_management/models/asset_category.py index 0377bb5a8079..caef16bfe5d6 100644 --- a/assets_management/models/asset_category.py +++ b/assets_management/models/asset_category.py @@ -7,9 +7,9 @@ class AssetCategory(models.Model): - _name = 'asset.category' + _name = "asset.category" _description = "Asset Category" - _order = 'name' + _order = "name" @api.model def get_default_company_id(self): @@ -17,33 +17,33 @@ def get_default_company_id(self): @api.model def get_default_type_ids(self): - mode_obj = self.env['asset.depreciation.mode'] - dom = [('company_id', '=', self.get_default_company_id().id)] - mode = mode_obj.search(dom + [('default', '=', True)], limit=1) + mode_obj = self.env["asset.depreciation.mode"] + dom = [("company_id", "=", self.get_default_company_id().id)] + mode = mode_obj.search(dom + [("default", "=", True)], limit=1) # Field ``mode_id`` is required for asset.category.depreciation.type; # if no default mode is found, retry by getting the first one found. if not mode: mode = mode_obj.search(dom, limit=1) - types = self.env['asset.depreciation.type'].search(dom) + types = self.env["asset.depreciation.type"].search(dom) # Raise error if configuration has not been completed. if not (mode and types): raise UserError( - _("Before creating new categories, please complete the" - " assets' configuration for both depreciation types" - " and modes.") + _( + "Before creating new categories, please complete the" + " assets' configuration for both depreciation types" + " and modes." + ) ) return [ - (0, 0, {'base_coeff': 1, - 'depreciation_type_id': t.id, - 'mode_id': mode.id}) + (0, 0, {"base_coeff": 1, "depreciation_type_id": t.id, "mode_id": mode.id}) for t in types ] asset_account_id = fields.Many2one( - 'account.account', + "account.account", required=True, string="Asset Account", ) @@ -53,37 +53,31 @@ def get_default_type_ids(self): ) company_id = fields.Many2one( - 'res.company', - default=get_default_company_id, - string="Company" + "res.company", default=get_default_company_id, string="Company" ) depreciation_account_id = fields.Many2one( - 'account.account', + "account.account", required=True, string="Depreciation Account", ) fund_account_id = fields.Many2one( - 'account.account', + "account.account", required=True, string="Fund Account", ) gain_account_id = fields.Many2one( - 'account.account', + "account.account", required=True, string="Capital Gain Account", ) - journal_id = fields.Many2one( - 'account.journal', - required=True, - string="Journal" - ) + journal_id = fields.Many2one("account.journal", required=True, string="Journal") loss_account_id = fields.Many2one( - 'account.account', + "account.account", required=True, string="Capital Loss Account", ) @@ -96,18 +90,18 @@ def get_default_type_ids(self): print_by_default = fields.Boolean( default=True, help="Defines whether a category should be added by default when" - " printing assets' reports.", - string="Print By Default" + " printing assets' reports.", + string="Print By Default", ) tag_ids = fields.Many2many( - 'asset.tag', + "asset.tag", string="Tag", ) type_ids = fields.One2many( - 'asset.category.depreciation.type', - 'category_id', + "asset.category.depreciation.type", + "category_id", default=get_default_type_ids, string="Depreciation Types", ) @@ -115,28 +109,24 @@ def get_default_type_ids(self): @api.multi def copy(self, default=None): default = dict(default or []) - default.update({ - 'tag_ids': [(6, 0, self.tag_ids.ids)], - 'type_ids': [ - (0, 0, t.copy_data({'category_id': False})[0]) - for t in self.type_ids - ] - }) + default.update( + { + "tag_ids": [(6, 0, self.tag_ids.ids)], + "type_ids": [ + (0, 0, t.copy_data({"category_id": False})[0]) + for t in self.type_ids + ], + } + ) return super().copy(default) @api.multi def unlink(self): - if self.env['asset.asset'].sudo().search([ - ('category_id', 'in', self.ids) - ]): + 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() def get_depreciation_vals(self, amount_depreciable=0): - return [ - t.get_depreciation_vals(amount_depreciable) - for t in self.type_ids - ] + return [t.get_depreciation_vals(amount_depreciable) for t in self.type_ids] diff --git a/assets_management/models/asset_category_depreciation_type.py b/assets_management/models/asset_category_depreciation_type.py index a95bbe69dc58..0b81fa7b8061 100644 --- a/assets_management/models/asset_category_depreciation_type.py +++ b/assets_management/models/asset_category_depreciation_type.py @@ -6,7 +6,7 @@ class AssetCategoryDepreciationType(models.Model): - _name = 'asset.category.depreciation.type' + _name = "asset.category.depreciation.type" _description = "Asset Category - Depreciation Type" base_coeff = fields.Float( @@ -16,46 +16,40 @@ class AssetCategoryDepreciationType(models.Model): ) category_id = fields.Many2one( - 'asset.category', - ondelete='cascade', + "asset.category", + ondelete="cascade", readonly=True, required=True, - string="Category" + string="Category", ) company_id = fields.Many2one( - 'res.company', - readonly=True, - related='category_id.company_id', - string="Company" + "res.company", readonly=True, related="category_id.company_id", string="Company" ) depreciation_type_id = fields.Many2one( - 'asset.depreciation.type', + "asset.depreciation.type", required=True, string="Type", ) mode_id = fields.Many2one( - 'asset.depreciation.mode', + "asset.depreciation.mode", required=True, string="Dep Mode", ) - percentage = fields.Float( - string="Depreciation %") + percentage = fields.Float(string="Depreciation %") - pro_rata_temporis = fields.Boolean( - string="Pro-rata Temporis" - ) + pro_rata_temporis = fields.Boolean(string="Pro-rata Temporis") def get_depreciation_vals(self, amount_depreciable=0): self.ensure_one() return { - 'amount_depreciable': amount_depreciable * self.base_coeff, - 'base_coeff': self.base_coeff, - 'mode_id': self.mode_id.id, - 'percentage': self.percentage, - 'pro_rata_temporis': self.pro_rata_temporis, - 'type_id': self.depreciation_type_id.id + "amount_depreciable": amount_depreciable * self.base_coeff, + "base_coeff": self.base_coeff, + "mode_id": self.mode_id.id, + "percentage": self.percentage, + "pro_rata_temporis": self.pro_rata_temporis, + "type_id": self.depreciation_type_id.id, } diff --git a/assets_management/models/asset_depreciation.py b/assets_management/models/asset_depreciation.py index 0493edc5f85d..cd612793f40c 100644 --- a/assets_management/models/asset_depreciation.py +++ b/assets_management/models/asset_depreciation.py @@ -8,64 +8,62 @@ class AssetDepreciation(models.Model): - _name = 'asset.depreciation' + _name = "asset.depreciation" _description = "Assets Depreciations" - amount_depreciable = fields.Monetary( - string="Depreciable Amount" - ) + amount_depreciable = fields.Monetary(string="Depreciable Amount") amount_depreciable_updated = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Updated Amount", ) amount_depreciated = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Depreciated Amount", ) amount_gain = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", string="Capital Gain", store=True, ) amount_historical = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Historical Amount", ) amount_in = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="In Amount", ) amount_loss = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Capital Loss", ) amount_out = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Out Amount", ) amount_residual = fields.Monetary( - compute='_compute_amounts', + compute="_compute_amounts", store=True, string="Residual Amount", ) asset_id = fields.Many2one( - 'asset.asset', - ondelete='cascade', + "asset.asset", + ondelete="cascade", readonly=True, required=True, string="Asset", @@ -78,98 +76,74 @@ class AssetDepreciation(models.Model): ) company_id = fields.Many2one( - 'res.company', - readonly=True, - related='asset_id.company_id', - string="Company" + "res.company", readonly=True, related="asset_id.company_id", string="Company" ) currency_id = fields.Many2one( - 'res.currency', - readonly=True, - related='asset_id.currency_id', - string="Currency" + "res.currency", readonly=True, related="asset_id.currency_id", string="Currency" ) - date_start = fields.Date( - string="Date Start" - ) + date_start = fields.Date(string="Date Start") - dismiss_move_id = fields.Many2one( - 'account.move', - string="Dismiss Move" - ) + dismiss_move_id = fields.Many2one("account.move", string="Dismiss Move") first_dep_nr = fields.Integer( default=1, string="First Dep. Num", ) - force_all_dep_nr = fields.Boolean( - string="Force All Dep. Num" - ) + force_all_dep_nr = fields.Boolean(string="Force All Dep. Num") - force_first_dep_nr = fields.Boolean( - string="Force First Dep. Num" - ) + force_first_dep_nr = fields.Boolean(string="Force First Dep. Num") last_depreciation_date = fields.Date( - compute='_compute_last_depreciation_date', + compute="_compute_last_depreciation_date", store=True, string="Last Dep.", ) line_ids = fields.One2many( - 'asset.depreciation.line', - 'depreciation_id', - string="Lines" + "asset.depreciation.line", "depreciation_id", string="Lines" ) mode_id = fields.Many2one( - 'asset.depreciation.mode', + "asset.depreciation.mode", required=True, string="Mode", ) - percentage = fields.Float( - string="Depreciation (%)" - ) + percentage = fields.Float(string="Depreciation (%)") - pro_rata_temporis = fields.Boolean( - string="Pro-rata Temporis" - ) + pro_rata_temporis = fields.Boolean(string="Pro-rata Temporis") requires_account_move = fields.Boolean( readonly=True, - related='type_id.requires_account_move', + related="type_id.requires_account_move", string="Requires Account Move", ) state = fields.Selection( - [('non_depreciated', "Non Depreciated"), - ('partially_depreciated', "Partially Depreciated"), - ('totally_depreciated', "Depreciated")], - compute='_compute_state', - default='non_depreciated', + [ + ("non_depreciated", "Non Depreciated"), + ("partially_depreciated", "Partially Depreciated"), + ("totally_depreciated", "Depreciated"), + ], + compute="_compute_state", + default="non_depreciated", store=True, - string="State" + string="State", ) - type_id = fields.Many2one( - 'asset.depreciation.type', - string="Depreciation Type" - ) + type_id = fields.Many2one("asset.depreciation.type", string="Depreciation Type") - zero_depreciation_until = fields.Date( - string="Zero Depreciation Up To" - ) + zero_depreciation_until = fields.Date(string="Zero Depreciation Up To") @api.model def create(self, vals): dep = super().create(vals) dep.normalize_first_dep_nr() if dep.line_ids: - num_lines = dep.line_ids.filtered('requires_depreciation_nr') + num_lines = dep.line_ids.filtered("requires_depreciation_nr") if num_lines: num_lines.normalize_depreciation_nr() return dep @@ -181,27 +155,30 @@ def write(self, vals): if need_norm: need_norm.normalize_first_dep_nr(force=True) for dep in self: - num_lines = dep.line_ids.filtered('requires_depreciation_nr') + num_lines = dep.line_ids.filtered("requires_depreciation_nr") if num_lines and num_lines.need_normalize_depreciation_nr(): num_lines.normalize_depreciation_nr(force=True) return res @api.multi def unlink(self): - if self.mapped('line_ids'): + if self.mapped("line_ids"): raise ValidationError( - _("Cannot delete depreciations if there is any depreciation" - " line linked to it.") + _( + "Cannot delete depreciations if there is any depreciation" + " line linked to it." + ) ) - if any([m.state != 'draft' for m in self.mapped('dismiss_move_id')]): + if any([m.state != "draft" for m in self.mapped("dismiss_move_id")]): deps = self.filtered( - lambda l: l.dismiss_move_id - and l.dismiss_move_id.state != 'draft' + lambda l: l.dismiss_move_id and l.dismiss_move_id.state != "draft" ) name_list = "\n".join([l[-1] for l in deps.name_get()]) raise ValidationError( - _("Following lines are linked to posted account moves, and" - " cannot be deleted:\n{}").format(name_list) + _( + "Following lines are linked to posted account moves, and" + " cannot be deleted:\n{}" + ).format(name_list) ) return super().unlink() @@ -210,34 +187,32 @@ def name_get(self): return [(dep.id, dep.make_name()) for dep in self] @api.multi - @api.depends( - 'amount_depreciable', 'amount_depreciable_updated', 'amount_residual' - ) + @api.depends("amount_depreciable", "amount_depreciable_updated", "amount_residual") def _compute_state(self): for dep in self: dep.state = dep.get_depreciation_state() - @api.onchange('asset_id', 'base_coeff') + @api.onchange("asset_id", "base_coeff") def onchange_base_coeff(self): purchase_amount = self.asset_id.purchase_amount self.amount_depreciable = self.base_coeff * purchase_amount - @api.onchange('first_dep_nr') + @api.onchange("first_dep_nr") def onchange_normalize_first_dep_nr(self): if self.first_dep_nr <= 0: self.first_dep_nr = 1 - @api.onchange('force_all_dep_nr') + @api.onchange("force_all_dep_nr") def onchange_force_all_dep_nr(self): if self.force_all_dep_nr: self.first_dep_nr = 1 - @api.onchange('force_first_dep_nr') + @api.onchange("force_first_dep_nr") def onchange_force_first_dep_nr(self): if self.force_first_dep_nr and self.first_dep_nr <= 0: self.first_dep_nr = 1 - @api.onchange('force_all_dep_nr', 'force_first_dep_nr') + @api.onchange("force_all_dep_nr", "force_first_dep_nr") def onchange_force_dep_nrs(self): if self.force_all_dep_nr and self.force_first_dep_nr: self.force_all_dep_nr = False @@ -247,23 +222,25 @@ def onchange_force_dep_nrs(self): "Fields `Force All Dep. Num` and `Force First Dep. Num`" " cannot be both active." ) - return {'warning': {'title': title, 'message': msg}} + return {"warning": {"title": title, "message": msg}} if not self.force_all_dep_nr and self.force_first_dep_nr: self.first_dep_nr = 1 @api.multi - @api.depends('amount_depreciable', - 'line_ids.amount', - 'line_ids.balance', - 'line_ids.move_type', - 'asset_id.sold') + @api.depends( + "amount_depreciable", + "line_ids.amount", + "line_ids.balance", + "line_ids.move_type", + "asset_id.sold", + ) def _compute_amounts(self): for dep in self: vals = dep.get_computed_amounts() dep.update(vals) @api.multi - @api.depends('line_ids', 'line_ids.date', 'line_ids.move_type') + @api.depends("line_ids", "line_ids.date", "line_ids.move_type") def _compute_last_depreciation_date(self): """ Update date upon deps with at least one depreciation line (excluding @@ -271,11 +248,10 @@ def _compute_last_depreciation_date(self): """ for dep in self: dep_lines = dep.line_ids.filtered( - lambda l: l.move_type == 'depreciated' - and not l.partial_dismissal + lambda l: l.move_type == "depreciated" and not l.partial_dismissal ) if dep_lines: - dep.last_depreciation_date = max(dep_lines.mapped('date')) + dep.last_depreciation_date = max(dep_lines.mapped("date")) else: dep.last_depreciation_date = False @@ -283,51 +259,58 @@ 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') + lines = self.mapped("line_ids") # Check if any depreciation already has newer depreciation lines # than the given date newer_lines = lines.filtered( - lambda l: l.move_type == 'depreciated' + lambda l: l.move_type == "depreciated" and not l.partial_dismissal and l.date > dep_date ) if newer_lines: - asset_names = ', '.join([ - asset_name for asset_id, asset_name in - newer_lines.mapped('depreciation_id.asset_id').name_get() - ]) + asset_names = ", ".join( + [ + asset_name + for asset_id, asset_name in newer_lines.mapped( + "depreciation_id.asset_id" + ).name_get() + ] + ) raise ValidationError( - _("Cannot update the following assets which contain" - " newer depreciations for the chosen types:\n{}") - .format(asset_names) + _( + "Cannot update the following assets which contain" + " newer depreciations for the chosen types:\n{}" + ).format(asset_names) ) posted_lines = lines.filtered( - lambda l: l.date == dep_date - and l.move_id - and l.move_id.state != 'draft' + lambda l: l.date == dep_date and l.move_id and l.move_id.state != "draft" ) if posted_lines: - posted_names = ', '.join([ - asset_name for asset_id, asset_name in - posted_lines.mapped('depreciation_id.asset_id').name_get() - ]) + posted_names = ", ".join( + [ + asset_name + for asset_id, asset_name in posted_lines.mapped( + "depreciation_id.asset_id" + ).name_get() + ] + ) raise ValidationError( - _("Cannot update the following assets which contain" - " posted depreciation for the chosen date and types:\n{}") - .format(posted_names) + _( + "Cannot update the following assets which contain" + " posted depreciation for the chosen date and types:\n{}" + ).format(posted_names) ) def generate_depreciation_lines(self, dep_date): # Set new date within context if necessary self.check_before_generate_depreciation_lines(dep_date) - new_lines = self.env['asset.depreciation.line'] + new_lines = self.env["asset.depreciation.line"] for dep in self: new_lines |= dep.generate_depreciation_lines_single(dep_date) @@ -342,58 +325,68 @@ def generate_depreciation_lines_single(self, dep_date): dep = dep.with_context(dep_amount=dep_amount) vals = dep.prepare_depreciation_line_vals(dep_date) - return self.env['asset.depreciation.line'].create(vals) + return self.env["asset.depreciation.line"].create(vals) def generate_dismiss_account_move(self): self.ensure_one() - am_obj = self.env['account.move'] + am_obj = self.env["account.move"] vals = self.get_dismiss_account_move_vals() - if 'line_ids' not in vals: - vals['line_ids'] = [] + if "line_ids" not in vals: + vals["line_ids"] = [] line_vals = self.get_dismiss_account_move_line_vals() for v in line_vals: - vals['line_ids'].append((0, 0, v)) + vals["line_ids"].append((0, 0, v)) self.dismiss_move_id = am_obj.create(vals) def get_computed_amounts(self): self.ensure_one() vals = { - 'amount_{}'.format(k): abs(v) + "amount_{}".format(k): abs(v) for k, v in self.line_ids.get_balances_grouped().items() - if 'amount_{}'.format(k) in self._fields + if "amount_{}".format(k) in self._fields } if self.asset_id.sold: - vals.update({ - 'amount_depreciable_updated': 0, - 'amount_residual': 0 - }) + vals.update({"amount_depreciable_updated": 0, "amount_residual": 0}) else: non_residual_types = self.line_ids.get_non_residual_move_types() update_move_types = self.line_ids.get_update_move_types() amt_dep = self.amount_depreciable - vals.update({ - 'amount_depreciable_updated': amt_dep + sum([ - l.balance for l in self.line_ids - if l.move_type in update_move_types - ]), - 'amount_residual': amt_dep + sum([ - l.balance for l in self.line_ids - if l.move_type not in non_residual_types - ]) - }) + vals.update( + { + "amount_depreciable_updated": amt_dep + + sum( + [ + l.balance + for l in self.line_ids + if l.move_type in update_move_types + ] + ), + "amount_residual": amt_dep + + sum( + [ + l.balance + for l in self.line_ids + if l.move_type not in non_residual_types + ] + ), + } + ) return vals def get_depreciable_amount(self, dep_date=None): types = self.line_ids.get_update_move_types() - return self.amount_depreciable + sum([ - l.balance for l in self.line_ids - if l.move_type in types and (not dep_date or l.date <= dep_date) - ]) + return self.amount_depreciable + sum( + [ + l.balance + for l in self.line_ids + if l.move_type in types and (not dep_date or l.date <= dep_date) + ] + ) def get_depreciation_amount(self, dep_date): self.ensure_one() @@ -404,7 +397,7 @@ def get_depreciation_amount(self, dep_date): # Get depreciable amount, multiplier and digits amount = self.get_depreciable_amount(dep_date) multiplier = self.get_depreciation_amount_multiplier(dep_date) - digits = self.env['decimal.precision'].precision_get('Account') + digits = self.env["decimal.precision"].precision_get("Account") dep_amount = round(amount * multiplier, digits) # If amount_residual < dep_amount: use amount_residual as dep_amount @@ -425,15 +418,13 @@ def get_depreciation_amount_multiplier(self, dep_date): # Update multiplier from pro-rata temporis date_start = self.date_start if dep_date < date_start: - dt_start_str = fields.Date.from_string(date_start).strftime( - '%d-%m-%Y' - ) + dt_start_str = fields.Date.from_string(date_start).strftime("%d-%m-%Y") raise ValidationError( _("Depreciations cannot start before {}.").format(dt_start_str) ) - if self.pro_rata_temporis or self._context.get('force_prorata'): - fiscal_year_obj = self.env['account.fiscal.year'] + if self.pro_rata_temporis or self._context.get("force_prorata"): + fiscal_year_obj = self.env["account.fiscal.year"] fy_start = fiscal_year_obj.get_fiscal_year_by_date( date_start, company=self.company_id ) @@ -448,69 +439,65 @@ def get_depreciation_amount_multiplier(self, dep_date): fy_end = fields.Date.from_string(fy_dep.date_to) fy_start = fields.Date.from_string(fy_dep.date_from) lapse = (fy_end - fy_start).days + 1 - dep_multiplier = self.get_pro_rata_temporis_multiplier( - dep_date, 'dte' - ) + dep_multiplier = self.get_pro_rata_temporis_multiplier(dep_date, "dte") start_multiplier = self.get_pro_rata_temporis_multiplier( - self.date_start, 'dte' + self.date_start, "dte" ) multiplier *= start_multiplier - dep_multiplier + 1 / lapse else: # Otherwise, simply compute multiplier with respect to how # many days have passed since the beginning of the fiscal year - multiplier *= self.get_pro_rata_temporis_multiplier( - dep_date, 'std' - ) + multiplier *= self.get_pro_rata_temporis_multiplier(dep_date, "std") return multiplier def get_depreciation_state(self): self.ensure_one() - digits = self.env['decimal.precision'].precision_get('Account') + digits = self.env["decimal.precision"].precision_get("Account") depreciable = self.amount_depreciable residual = self.amount_residual updated = self.amount_depreciable_updated if float_is_zero(depreciable, digits): - return 'non_depreciated' + return "non_depreciated" elif float_is_zero(residual, digits): - return 'totally_depreciated' + return "totally_depreciated" elif float_compare(residual, updated, digits) < 0: - return 'partially_depreciated' + return "partially_depreciated" else: - return 'non_depreciated' + return "non_depreciated" def get_dismiss_account_move_line_vals(self): self.ensure_one() credit_line_vals = { - 'account_id': self.asset_id.category_id.asset_account_id.id, - 'credit': self.amount_depreciated, - 'debit': 0.0, - 'currency_id': self.currency_id.id, - 'name': _("Asset dismissal: ") + self.asset_id.make_name(), + "account_id": self.asset_id.category_id.asset_account_id.id, + "credit": self.amount_depreciated, + "debit": 0.0, + "currency_id": self.currency_id.id, + "name": _("Asset dismissal: ") + self.asset_id.make_name(), } debit_line_vals = { - 'account_id': self.asset_id.category_id.fund_account_id.id, - 'credit': 0.0, - 'debit': self.amount_depreciated, - 'currency_id': self.currency_id.id, - 'name': _("Asset dismissal: ") + self.asset_id.make_name(), + "account_id": self.asset_id.category_id.fund_account_id.id, + "credit": 0.0, + "debit": self.amount_depreciated, + "currency_id": self.currency_id.id, + "name": _("Asset dismissal: ") + self.asset_id.make_name(), } return [credit_line_vals, debit_line_vals] def get_dismiss_account_move_vals(self): self.ensure_one() return { - 'company_id': self.company_id.id, - 'date': self.asset_id.sale_date, - 'journal_id': self.asset_id.category_id.journal_id.id, - 'line_ids': [], - 'ref': _("Asset dismissal: ") + self.asset_id.make_name(), + "company_id": self.company_id.id, + "date": self.asset_id.sale_date, + "journal_id": self.asset_id.category_id.journal_id.id, + "line_ids": [], + "ref": _("Asset dismissal: ") + self.asset_id.make_name(), } def get_max_depreciation_nr(self): self.ensure_one() - num_lines = self.line_ids.filtered('requires_depreciation_nr') - nums = num_lines.mapped('depreciation_nr') + num_lines = self.line_ids.filtered("requires_depreciation_nr") + nums = num_lines.mapped("depreciation_nr") if not nums: nums = [0] return max(nums) @@ -531,23 +518,21 @@ def get_pro_rata_temporis_dates(self, date): _("Cannot compute pro rata temporis for unknown date.") ) - fiscal_year_obj = self.env['account.fiscal.year'] + fiscal_year_obj = self.env["account.fiscal.year"] fiscal_year = fiscal_year_obj.get_fiscal_year_by_date( date, company=self.company_id ) if not fiscal_year: - date_str = fields.Date.from_string(date).strftime('%d/%m/%Y') - raise ValidationError( - _("No fiscal year defined for date {}") + date_str - ) + date_str = fields.Date.from_string(date).strftime("%d/%m/%Y") + raise ValidationError(_("No fiscal year defined for date {}") + date_str) return ( fields.Date.from_string(fiscal_year.date_from), fields.Date.from_string(date), - fields.Date.from_string(fiscal_year.date_to) + fields.Date.from_string(fiscal_year.date_to), ) - def get_pro_rata_temporis_multiplier(self, date=None, mode='std'): + def get_pro_rata_temporis_multiplier(self, date=None, mode="std"): """ Computes and returns pro rata temporis multiplier according to given depreciation, date, fiscal year and mode @@ -559,19 +544,18 @@ def get_pro_rata_temporis_multiplier(self, date=None, mode='std'): date to fiscal year's last day """ self.ensure_one() - if not (self.pro_rata_temporis or self._context.get('force_prorata')): + if not (self.pro_rata_temporis or self._context.get("force_prorata")): return 1 dt_start, dt, dt_end = self.get_pro_rata_temporis_dates(date) lapse = (dt_end - dt_start).days + 1 - if mode == 'std': + if mode == "std": return ((dt - dt_start).days + 1) / lapse - elif mode == 'dte': + elif mode == "dte": return ((dt_end - dt).days + 1) / lapse elif mode: raise NotImplementedError( - _("Cannot get pro rata temporis multiplier for mode `{}`") - .format(mode) + _("Cannot get pro rata temporis multiplier for mode `{}`").format(mode) ) raise NotImplementedError( _("Cannot get pro rata temporis multiplier for unspecified mode") @@ -602,27 +586,25 @@ def normalize_first_dep_nr(self, force=False): Normalize first numbered line according to `first_dep_nr` value :param force: if True, force normalization """ - force = force or self._context.get('force_normalize_first_dep_nr') + force = force or self._context.get("force_normalize_first_dep_nr") for d in self: if force or d.need_normalize_first_dep_nr(): d.onchange_normalize_first_dep_nr() def post_generate_depreciation_lines(self, lines=None): - lines = lines or self.env['asset.depreciation.line'] - lines.filtered('requires_account_move').button_generate_account_move() + lines = lines or self.env["asset.depreciation.line"] + lines.filtered("requires_account_move").button_generate_account_move() def prepare_depreciation_line_vals(self, dep_date): self.ensure_one() if dep_date is None: - raise ValidationError( - _("Cannot create a depreciation line without a date") - ) - dep_amount = self._context.get('dep_amount') or 0.0 + raise ValidationError(_("Cannot create a depreciation line without a date")) + dep_amount = self._context.get("dep_amount") or 0.0 dep_year = fields.Date.from_string(dep_date).year return { - 'amount': dep_amount, - 'date': dep_date, - 'depreciation_id': self.id, - 'move_type': 'depreciated', - 'name': _("{} - Depreciation").format(dep_year) + "amount": dep_amount, + "date": dep_date, + "depreciation_id": self.id, + "move_type": "depreciated", + "name": _("{} - Depreciation").format(dep_year), } diff --git a/assets_management/models/asset_depreciation_line.py b/assets_management/models/asset_depreciation_line.py index f59439a9a8d8..9e703f8a29d1 100644 --- a/assets_management/models/asset_depreciation_line.py +++ b/assets_management/models/asset_depreciation_line.py @@ -7,30 +7,28 @@ class AssetDepreciationLine(models.Model): - _name = 'asset.depreciation.line' + _name = "asset.depreciation.line" _description = "Assets Depreciations Lines" - _order = 'date asc, name asc' + _order = "date asc, name asc" amount = fields.Monetary( string="Amount", ) asset_accounting_info_ids = fields.One2many( - 'asset.accounting.info', - 'dep_line_id', - string="Accounting Info" + "asset.accounting.info", "dep_line_id", string="Accounting Info" ) asset_id = fields.Many2one( - 'asset.asset', + "asset.asset", readonly=True, - related='depreciation_id.asset_id', + related="depreciation_id.asset_id", store=True, - string="Asset" + string="Asset", ) balance = fields.Monetary( - compute='_compute_balance', + compute="_compute_balance", store=True, string="Balance", ) @@ -40,15 +38,15 @@ class AssetDepreciationLine(models.Model): ) company_id = fields.Many2one( - 'res.company', + "res.company", readonly=True, - related='depreciation_id.company_id', + related="depreciation_id.company_id", ) currency_id = fields.Many2one( - 'res.currency', + "res.currency", readonly=True, - related='depreciation_id.currency_id', + related="depreciation_id.currency_id", ) date = fields.Date( @@ -57,16 +55,15 @@ class AssetDepreciationLine(models.Model): ) depreciation_id = fields.Many2one( - 'asset.depreciation', - ondelete='cascade', + "asset.depreciation", + ondelete="cascade", readonly=True, required=True, string="Asset depreciation", ) depreciation_line_type_id = fields.Many2one( - 'asset.depreciation.line.type', - string="Depreciation Type" + "asset.depreciation.line.type", string="Depreciation Type" ) depreciation_nr = fields.Integer( @@ -74,33 +71,32 @@ class AssetDepreciationLine(models.Model): ) depreciation_type_id = fields.Many2one( - 'asset.depreciation.type', + "asset.depreciation.type", readonly=True, - related='depreciation_id.type_id', + related="depreciation_id.type_id", store=True, string="Asset depreciation type", ) force_dep_nr = fields.Boolean( readonly=True, - related='depreciation_id.force_all_dep_nr', + related="depreciation_id.force_all_dep_nr", string="Force Dep. Num", ) - move_id = fields.Many2one( - 'account.move', - string="Move" - ) + move_id = fields.Many2one("account.move", string="Move") move_type = fields.Selection( - [('depreciated', 'Depreciation'), - ('historical', 'Historical'), - ('in', 'In'), - ('out', 'Out'), - ('loss', 'Capital Loss'), - ('gain', 'Capital Gain')], + [ + ("depreciated", "Depreciation"), + ("historical", "Historical"), + ("in", "In"), + ("out", "Out"), + ("loss", "Capital Loss"), + ("gain", "Capital Gain"), + ], string="Type", - required=True + required=True, ) name = fields.Char( @@ -108,34 +104,30 @@ class AssetDepreciationLine(models.Model): string="Name", ) - partial_dismissal = fields.Boolean( - string="Partial Dismissal" - ) + partial_dismissal = fields.Boolean(string="Partial Dismissal") - percentage = fields.Float( - string="%" - ) + percentage = fields.Float(string="%") requires_account_move = fields.Boolean( readonly=True, - related='depreciation_id.type_id.requires_account_move', + related="depreciation_id.type_id.requires_account_move", string="Required Account Move", ) requires_depreciation_nr = fields.Boolean( - compute='_compute_requires_depreciation_nr', - search='_search_requires_depreciation_nr_lines', - string="Requires Dep Num" + compute="_compute_requires_depreciation_nr", + search="_search_requires_depreciation_nr_lines", + string="Requires Dep Num", ) # Non-default parameter: set which `move_types` require numeration - _numbered_move_types = ('depreciated', 'historical') + _numbered_move_types = ("depreciated", "historical") # Non-default parameter: set which `move_types` do not concur to # asset.depreciation's `amount_residual` field compute - _non_residual_move_types = ('gain',) + _non_residual_move_types = ("gain",) # Non-default parameter: set which `move_types` get to update the # depreciable amount - _update_move_types = ('in', 'out') + _update_move_types = ("in", "out") @api.model def create(self, vals): @@ -154,58 +146,63 @@ def write(self, vals): @api.multi def unlink(self): - if self.mapped('asset_accounting_info_ids'): - lines = self.filtered('asset_accounting_info_ids') + if self.mapped("asset_accounting_info_ids"): + lines = self.filtered("asset_accounting_info_ids") name_list = "\n".join([l[-1] for l in lines.name_get()]) raise ValidationError( - _("The lines you you are trying to delete are currently" - " linked to accounting info. Please remove them if" - " necessary before removing these lines:\n") + name_list - ) - if any([m.state != 'draft' for m in self.mapped('move_id')]): - lines = self.filtered( - lambda l: l.move_id and l.move_id.state != 'draft' + _( + "The lines you you are trying to delete are currently" + " linked to accounting info. Please remove them if" + " necessary before removing these lines:\n" + ) + + name_list ) + if any([m.state != "draft" for m in self.mapped("move_id")]): + lines = self.filtered(lambda l: l.move_id and l.move_id.state != "draft") name_list = "\n".join([l[-1] for l in lines.name_get()]) raise ValidationError( - _("Following lines are linked to posted account moves, and" - " cannot be deleted:\n") + name_list + _( + "Following lines are linked to posted account moves, and" + " cannot be deleted:\n" + ) + + name_list ) - self.mapped('move_id').unlink() + self.mapped("move_id").unlink() return super().unlink() @api.multi def name_get(self): return [(line.id, line.make_name()) for line in self] - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for dep_line in self: - comp = dep_line.get_linked_aa_info_records().mapped('company_id') + comp = dep_line.get_linked_aa_info_records().mapped("company_id") if len(comp) > 1 or (comp and comp != dep_line.company_id): raise ValidationError( - _("`{}`: cannot change depreciation line's company once" - " it's already related to an asset.") - .format(dep_line.make_name()) + _( + "`{}`: cannot change depreciation line's company once" + " it's already related to an asset." + ).format(dep_line.make_name()) ) - @api.constrains('depreciation_nr') + @api.constrains("depreciation_nr") def check_depreciation_nr_coherence(self): - for dep in self.mapped('depreciation_id'): + for dep in self.mapped("depreciation_id"): # Check if any number is negative - num_lines = dep.line_ids.filtered('requires_depreciation_nr') - nums = num_lines.mapped('depreciation_nr') + num_lines = dep.line_ids.filtered("requires_depreciation_nr") + nums = num_lines.mapped("depreciation_nr") if nums and min(nums) < 0: raise ValidationError( _("Depreciation number can't be a negative number.") ) @api.multi - @api.depends('amount', 'move_type') + @api.depends("amount", "move_type") def _compute_balance(self): for line in self: - if line.move_type in ['out', 'depreciated', 'historical', 'loss']: - line.balance = - line.amount + if line.move_type in ["out", "depreciated", "historical", "loss"]: + line.balance = -line.amount else: line.balance = line.amount @@ -216,19 +213,17 @@ def _compute_requires_depreciation_nr(self): @api.multi def _search_requires_depreciation_nr_lines(self, operator, value): - if operator not in ('=', '!='): - raise ValidationError( - _("Invalid search operator!") - ) + if operator not in ("=", "!="): + raise ValidationError(_("Invalid search operator!")) - if (operator == '=' and value) or (operator == '!=' and not value): - return [('move_type', 'in', self.get_numbered_move_types())] + if (operator == "=" and value) or (operator == "!=" and not value): + return [("move_type", "in", self.get_numbered_move_types())] else: - return [('move_type', 'not in', self.get_numbered_move_types())] + return [("move_type", "not in", self.get_numbered_move_types())] - @api.onchange('move_type') + @api.onchange("move_type") def onchange_move_type(self): - if self.move_type not in ('in', 'out'): + if self.move_type not in ("in", "out"): self.depreciation_line_type_id = False def get_linked_aa_info_records(self): @@ -236,7 +231,7 @@ def get_linked_aa_info_records(self): return self.asset_accounting_info_ids def get_balances_grouped(self): - """ Groups balances of line in `self` by line.move_type """ + """Groups balances of line in `self` by line.move_type""" balances_grouped = {} for line in self: if line.move_type not in balances_grouped: @@ -245,10 +240,10 @@ def get_balances_grouped(self): return balances_grouped def get_depreciation_nr_dict(self): - """ Returns dict {line: new number} """ - dep = self.mapped('depreciation_id') + """Returns dict {line: new number}""" + dep = self.mapped("depreciation_id") dep.ensure_one() - lines = dep.line_ids.filtered('requires_depreciation_nr').sorted() + lines = dep.line_ids.filtered("requires_depreciation_nr").sorted() if not lines: return {} @@ -256,10 +251,7 @@ def get_depreciation_nr_dict(self): if dep.force_first_dep_nr and dep.first_dep_nr > 0: first_num = dep.first_dep_nr - return { - line: nr + first_num - for nr, line in enumerate(lines) - } + return {line: nr + first_num for nr, line in enumerate(lines)} def get_non_residual_move_types(self): """ @@ -269,7 +261,7 @@ def get_non_residual_move_types(self): return self._non_residual_move_types def get_numbered_move_types(self): - """ Returns list of `move_type` vals that require numeration """ + """Returns list of `move_type` vals that require numeration""" return self._numbered_move_types def get_update_move_types(self): @@ -280,24 +272,26 @@ def get_update_move_types(self): return self._update_move_types def is_depreciation_nr_required(self): - """ Defines if a line requires to be numbered """ + """Defines if a line requires to be numbered""" self.ensure_one() - return self.move_type in self.get_numbered_move_types() \ + return ( + self.move_type in self.get_numbered_move_types() and not self.partial_dismissal + ) def make_name(self): self.ensure_one() return "{} ({})".format(self.name, self.depreciation_id.make_name()) def need_normalize_depreciation_nr(self): - """ Check if numbers need to be normalized """ - dep = self.mapped('depreciation_id') + """Check if numbers need to be normalized""" + dep = self.mapped("depreciation_id") dep.ensure_one() if dep.force_all_dep_nr: return False - lines = dep.line_ids.filtered('requires_depreciation_nr').sorted() + lines = dep.line_ids.filtered("requires_depreciation_nr").sorted() if not lines: return False @@ -311,7 +305,7 @@ def need_normalize_depreciation_nr(self): if first_line.depreciation_nr != 1: return True - nrs = tuple(lines.mapped('depreciation_nr') or [0]) + nrs = tuple(lines.mapped("depreciation_nr") or [0]) if min(nrs) <= 0: return True @@ -328,19 +322,19 @@ def normalize_depreciation_nr(self, force=False): every non-depreciation line. :param force: force normalization for every depreciations' lines """ - for dep in self.mapped('depreciation_id'): + for dep in self.mapped("depreciation_id"): # Avoid if user chooses to use custom numbers if dep.force_all_dep_nr: continue - num_lines = dep.line_ids.filtered('requires_depreciation_nr') + num_lines = dep.line_ids.filtered("requires_depreciation_nr") if force or num_lines.need_normalize_depreciation_nr(): nr_dict = num_lines.get_depreciation_nr_dict() for num_line, nr in nr_dict.items(): if num_line.depreciation_nr != nr: num_line.depreciation_nr = nr - (dep.line_ids - num_lines).update({'depreciation_nr': 0}) + (dep.line_ids - num_lines).update({"depreciation_nr": 0}) ########################################################################## # # @@ -359,7 +353,7 @@ def button_regenerate_account_move(self): @api.multi def button_remove_account_move(self): - self.mapped('move_id').unlink() + self.mapped("move_id").unlink() def generate_account_move(self): for line in self.filtered(lambda l: l.needs_account_move()): @@ -367,30 +361,30 @@ def generate_account_move(self): def generate_account_move_single(self): self.ensure_one() - am_obj = self.env['account.move'] + am_obj = self.env["account.move"] vals = self.get_account_move_vals() - if 'line_ids' not in vals: - vals['line_ids'] = [] + if "line_ids" not in vals: + vals["line_ids"] = [] line_vals = self.get_account_move_line_vals() for v in line_vals: - vals['line_ids'].append((0, 0, v)) + vals["line_ids"].append((0, 0, v)) self.move_id = am_obj.create(vals) def get_account_move_vals(self): self.ensure_one() return { - 'company_id': self.company_id.id, - 'date': self.date, - 'journal_id': self.asset_id.category_id.journal_id.id, - 'line_ids': [], - 'ref': _("Asset: ") + self.asset_id.make_name(), + "company_id": self.company_id.id, + "date": self.date, + "journal_id": self.asset_id.category_id.journal_id.id, + "line_ids": [], + "ref": _("Asset: ") + self.asset_id.make_name(), } def get_account_move_line_vals(self): - """ Switcher between methods """ + """Switcher between methods""" method = self.get_account_move_line_vals_methods().get(self.move_type) if not method: raise NotImplementedError( @@ -404,8 +398,8 @@ def get_account_move_line_vals_methods(self): Maps line `move_type` to its own method for generating move lines. """ return { - t: getattr(self, 'get_{}_account_move_line_vals'.format(t), False) - for t in dict(self._fields['move_type'].selection).keys() + t: getattr(self, "get_{}_account_move_line_vals".format(t), False) + for t in dict(self._fields["move_type"].selection).keys() } def get_depreciated_account_move_line_vals(self): @@ -414,54 +408,51 @@ def get_depreciated_account_move_line_vals(self): # Asset depreciation if not self.partial_dismissal: credit_account_id = self.asset_id.category_id.fund_account_id.id - debit_account_id = self.asset_id.category_id \ - .depreciation_account_id.id + debit_account_id = self.asset_id.category_id.depreciation_account_id.id # Asset partial dismissal else: debit_account_id = self.asset_id.category_id.fund_account_id.id - credit_account_id = self.asset_id.category_id\ - .asset_account_id.id + credit_account_id = self.asset_id.category_id.asset_account_id.id amt = abs(self.amount) credit_line_vals = { - 'account_id': credit_account_id, - 'credit': amt, - 'debit': 0.0, - 'currency_id': self.currency_id.id, - 'name': " - ".join((self.asset_id.make_name(), self.name)), + "account_id": credit_account_id, + "credit": amt, + "debit": 0.0, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), } debit_line_vals = { - 'account_id': debit_account_id, - 'credit': 0.0, - 'debit': amt, - 'currency_id': self.currency_id.id, - 'name': " - ".join((self.asset_id.make_name(), self.name)), + "account_id": debit_account_id, + "credit": 0.0, + "debit": amt, + "currency_id": self.currency_id.id, + "name": " - ".join((self.asset_id.make_name(), self.name)), } return [credit_line_vals, debit_line_vals] def get_gain_account_move_line_vals(self): 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)), + "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)), + "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_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): @@ -472,18 +463,18 @@ def get_in_account_move_line_vals(self): def get_loss_account_move_line_vals(self): 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)), + "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)), + "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] @@ -497,9 +488,9 @@ def needs_account_move(self): return self.requires_account_move and not self.move_id and self.amount def post_dismiss_asset(self): - dep = self.mapped('depreciation_id') + dep = self.mapped("depreciation_id") dep.ensure_one() - types = ('gain', 'loss') + types = ("gain", "loss") gain_or_loss = self.filtered( lambda l: l.needs_account_move() and l.move_type in types ) @@ -508,9 +499,9 @@ def post_dismiss_asset(self): dep.generate_dismiss_account_move() def post_partial_dismiss_asset(self): - dep = self.mapped('depreciation_id') + dep = self.mapped("depreciation_id") dep.ensure_one() - types = ('depreciated', 'gain', 'loss') + types = ("depreciated", "gain", "loss") to_create_move = self.filtered( lambda l: l.needs_account_move() and l.move_type in types ) diff --git a/assets_management/models/asset_depreciation_line_type.py b/assets_management/models/asset_depreciation_line_type.py index 3d1ea579f8fe..950aa792eb84 100644 --- a/assets_management/models/asset_depreciation_line_type.py +++ b/assets_management/models/asset_depreciation_line_type.py @@ -7,45 +7,39 @@ class DepLineType(models.Model): - _name = 'asset.depreciation.line.type' + _name = "asset.depreciation.line.type" _description = "Depreciation Line Type" - _table = 'asset_dep_line_type' - _order = 'name asc, code asc' + _table = "asset_dep_line_type" + _order = "name asc, code asc" @api.model def get_default_company_id(self): return self.env.user.company_id - code = fields.Char( - string="Code" - ) + code = fields.Char(string="Code") company_id = fields.Many2one( - 'res.company', - default=get_default_company_id, - string="Company" + "res.company", default=get_default_company_id, string="Company" ) - name = fields.Char( - required=True, - string="Name" - ) + name = fields.Char(required=True, string="Name") type = fields.Selection( - [('in', 'In'), - ('out', 'Out')], + [("in", "In"), ("out", "Out")], string="Type", ) @api.multi def unlink(self): for line_type in self: - if self.env['asset.depreciation.line'].search([ - ('depreciation_line_type_id', '=', line_type.id) - ]): + if self.env["asset.depreciation.line"].search( + [("depreciation_line_type_id", "=", line_type.id)] + ): raise ValidationError( - _("Cannot remove type {}: there is some depreciation" - " line linked to it.".format(line_type.name)) + _( + "Cannot remove type {}: there is some depreciation" + " line linked to it.".format(line_type.name) + ) ) return super().unlink() @@ -60,7 +54,7 @@ def make_name(self): if self.code: name += "[{}] ".format(self.code) name += self.name - type_name = dict(self._fields['type'].selection).get(self.type) + type_name = dict(self._fields["type"].selection).get(self.type) if type_name: name += " - " + type_name return name.strip() diff --git a/assets_management/models/asset_depreciation_mode.py b/assets_management/models/asset_depreciation_mode.py index 5e9a57e1e419..996ddcacb455 100644 --- a/assets_management/models/asset_depreciation_mode.py +++ b/assets_management/models/asset_depreciation_mode.py @@ -7,28 +7,22 @@ class AssetDepreciationMode(models.Model): - _name = 'asset.depreciation.mode' + _name = "asset.depreciation.mode" _description = "Asset Depreciation Mode" - _order = 'name' + _order = "name" @api.model def get_default_company_id(self): return self.env.user.company_id company_id = fields.Many2one( - 'res.company', - default=get_default_company_id, - string="Company" + "res.company", default=get_default_company_id, string="Company" ) - default = fields.Boolean( - string="Default Mode" - ) + default = fields.Boolean(string="Default Mode") line_ids = fields.One2many( - 'asset.depreciation.mode.line', - 'mode_id', - string="Lines" + "asset.depreciation.mode.line", "mode_id", string="Lines" ) name = fields.Char( @@ -44,44 +38,48 @@ def get_default_company_id(self): @api.multi def copy(self, default=None): default = dict(default or []) - default.update({ - 'default': False, - 'line_ids': [ - (0, 0, l.copy_data({'mode_id': False})[0]) - for l in self.line_ids - ] - }) + default.update( + { + "default": False, + "line_ids": [ + (0, 0, l.copy_data({"mode_id": False})[0]) for l in self.line_ids + ], + } + ) return super().copy(default) @api.multi def unlink(self): - if self.env['asset.category.depreciation.type'].sudo().search([ - ('mode_id', 'in', self.ids) - ]): + if ( + self.env["asset.category.depreciation.type"] + .sudo() + .search([("mode_id", "in", self.ids)]) + ): raise UserError( - _("Cannot delete depreciation modes while they're still linked" - " to categories.") + _( + "Cannot delete depreciation modes while they're still linked" + " to categories." + ) ) - if self.env['asset.depreciation'].sudo().search([ - ('mode_id', 'in', self.ids) - ]): + if self.env["asset.depreciation"].sudo().search([("mode_id", "in", self.ids)]): raise UserError( - _("Cannot delete depreciation modes while they're still linked" - " to depreciations.") + _( + "Cannot delete depreciation modes while they're still linked" + " to depreciations." + ) ) return super().unlink() - @api.constrains('company_id', 'default') + @api.constrains("company_id", "default") def check_default_modes(self): - for company in self.mapped('company_id'): - domain = [ - ('company_id', '=', company.id), - ('default', '=', True) - ] + for company in self.mapped("company_id"): + domain = [("company_id", "=", company.id), ("default", "=", True)] if self.search_count(domain) > 1: raise ValidationError( - _("There can be no more than 1 default depreciation mode" - " for each company.") + _( + "There can be no more than 1 default depreciation mode" + " for each company." + ) ) def get_depreciation_amount_multiplier(self): @@ -92,7 +90,7 @@ def get_depreciation_amount_multiplier(self): self.ensure_one() # Update multiplier from used asset coefficient - used_asset = self._context.get('used_asset', False) + used_asset = self._context.get("used_asset", False) if self.used_asset_coeff and used_asset: multiplier *= self.used_asset_coeff diff --git a/assets_management/models/asset_depreciation_mode_line.py b/assets_management/models/asset_depreciation_mode_line.py index 78a24fec1071..9db1189ce43d 100644 --- a/assets_management/models/asset_depreciation_mode_line.py +++ b/assets_management/models/asset_depreciation_mode_line.py @@ -6,14 +6,13 @@ class AssetDepreciationModeLine(models.Model): - _name = 'asset.depreciation.mode.line' + _name = "asset.depreciation.mode.line" _description = "Asset Depreciation Mode Line" - _order = 'from_nr asc, to_nr asc' + _order = "from_nr asc, to_nr asc" application = fields.Selection( - [('coefficient', 'Coefficient'), - ('percentage', 'Percentage')], - default='coefficient', + [("coefficient", "Coefficient"), ("percentage", "Percentage")], + default="coefficient", required=True, string="Application by", ) @@ -23,10 +22,7 @@ class AssetDepreciationModeLine(models.Model): ) company_id = fields.Many2one( - 'res.company', - readonly=True, - related='mode_id.company_id', - string="Company" + "res.company", readonly=True, related="mode_id.company_id", string="Company" ) from_nr = fields.Integer( @@ -35,27 +31,25 @@ class AssetDepreciationModeLine(models.Model): ) mode_id = fields.Many2one( - 'asset.depreciation.mode', - ondelete='cascade', + "asset.depreciation.mode", + ondelete="cascade", required=True, readonly=True, string="Mode", ) - percentage = fields.Float( - string="Percentage" - ) + percentage = fields.Float(string="Percentage") to_nr = fields.Integer( string="To Nr", ) - @api.onchange('application') + @api.onchange("application") def onchange_application(self): if self.application: - if self.application == 'coefficient': + if self.application == "coefficient": self.percentage = 0 - elif self.application == 'percentage': + elif self.application == "percentage": self.coefficient = 0 else: self.coefficient = 0 @@ -63,7 +57,7 @@ def onchange_application(self): def get_depreciation_amount_multiplier(self): multiplier = 1 - nr = self._context.get('dep_nr') + nr = self._context.get("dep_nr") if nr is None: # Cannot compare to any line return multiplier @@ -75,9 +69,9 @@ def get_depreciation_amount_multiplier(self): return multiplier for line in lines: - if line.application == 'coefficient': + if line.application == "coefficient": multiplier *= line.coefficient - elif line.application == 'percentage': + elif line.application == "percentage": multiplier *= line.percentage / 100 return multiplier diff --git a/assets_management/models/asset_depreciation_type.py b/assets_management/models/asset_depreciation_type.py index facd5167022e..ff5fb86f275a 100644 --- a/assets_management/models/asset_depreciation_type.py +++ b/assets_management/models/asset_depreciation_type.py @@ -7,43 +7,40 @@ class AssetDepreciationType(models.Model): - _name = 'asset.depreciation.type' + _name = "asset.depreciation.type" _description = "Asset Depreciation Type" - _order = 'name' + _order = "name" @api.model def get_default_company_id(self): return self.env.user.company_id company_id = fields.Many2one( - 'res.company', - default=get_default_company_id, - string="Company" + "res.company", default=get_default_company_id, string="Company" ) - name = fields.Char( - required=True, - string="Name" - ) + name = fields.Char(required=True, string="Name") print_by_default = fields.Boolean( default=True, help="Defines whether a category should be added by default when" - " printing assets' reports.", - string="Print By Default" + " printing assets' reports.", + string="Print By Default", ) - requires_account_move = fields.Boolean( - string="Requires Account Move" - ) + requires_account_move = fields.Boolean(string="Requires Account Move") @api.multi def unlink(self): - if self.env['asset.category.depreciation.type'].sudo().search([ - ('depreciation_type_id', 'in', self.ids) - ]): + if ( + self.env["asset.category.depreciation.type"] + .sudo() + .search([("depreciation_type_id", "in", self.ids)]) + ): raise UserError( - _("Cannot delete depreciation types while they're still used" - " by categories.") + _( + "Cannot delete depreciation types while they're still used" + " by categories." + ) ) return super().unlink() diff --git a/assets_management/models/asset_tag.py b/assets_management/models/asset_tag.py index 9175a3fda9cc..c05b7ec15093 100644 --- a/assets_management/models/asset_tag.py +++ b/assets_management/models/asset_tag.py @@ -6,7 +6,7 @@ class AssetTag(models.Model): - _name = 'asset.tag' + _name = "asset.tag" _description = "Asset Tags" @api.model @@ -14,12 +14,7 @@ def get_default_company_id(self): return self.env.user.company_id company_id = fields.Many2one( - 'res.company', - default=get_default_company_id, - string="Company" + "res.company", default=get_default_company_id, string="Company" ) - name = fields.Char( - string="Name", - required=True - ) + name = fields.Char(string="Name", required=True) diff --git a/assets_management/report/asset_journal.py b/assets_management/report/asset_journal.py index c616ba21d8ae..1fd1750c48db 100644 --- a/assets_management/report/asset_journal.py +++ b/assets_management/report/asset_journal.py @@ -13,9 +13,9 @@ def format_date(rec, field_name, fmt): - """ Formats record's field value according to given format `fmt` """ + """Formats record's field value according to given format `fmt`""" if not rec[field_name]: - return '' + return "" return rec._fields[field_name].from_string(rec[field_name]).strftime(fmt) @@ -33,22 +33,23 @@ class Report(models.TransientModel): Asset and Depreciation Line by Year both have a relation to the section Accounting Data which stores sale/purchase data. """ - _name = 'report_asset_journal' - _inherit = 'account_financial_report_abstract' + + _name = "report_asset_journal" + _inherit = "account_financial_report_abstract" # Data fields asset_ids = fields.Many2many( - 'asset.asset', + "asset.asset", ) asset_order_fname = fields.Char() category_ids = fields.Many2many( - 'asset.category', + "asset.category", ) company_id = fields.Many2one( - 'res.company', + "res.company", ) date = fields.Date() @@ -58,34 +59,23 @@ class Report(models.TransientModel): show_category_totals = fields.Boolean() type_ids = fields.Many2many( - 'asset.depreciation.type', + "asset.depreciation.type", ) # Report structure fields - report_category_ids = fields.One2many( - 'report_asset_journal_category', - 'report_id' - ) + report_category_ids = fields.One2many("report_asset_journal_category", "report_id") - report_asset_ids = fields.One2many( - 'report_asset_journal_asset', - 'report_id' - ) + report_asset_ids = fields.One2many("report_asset_journal_asset", "report_id") report_depreciation_ids = fields.One2many( - 'report_asset_journal_depreciation', - 'report_id' + "report_asset_journal_depreciation", "report_id" ) report_depreciation_line_year_ids = fields.One2many( - 'report_asset_journal_depreciation_line_year', - 'report_id' + "report_asset_journal_depreciation_line_year", "report_id" ) - report_total_ids = fields.One2many( - 'report_asset_journal_totals', - 'report_id' - ) + report_total_ids = fields.One2many("report_asset_journal_totals", "report_id") # Fields to be printed report_footer_year = fields.Char() @@ -106,15 +96,14 @@ def print_report(self, report_type=None): :param report_type: string that represents the report type """ self.ensure_one() - report_type = report_type or 'qweb-pdf' - if report_type in ('qweb-pdf', 'xlsx'): + report_type = report_type or "qweb-pdf" + if report_type in ("qweb-pdf", "xlsx"): res = self.do_print(report_type) - elif report_type == 'qweb-html': + elif report_type == "qweb-html": res = self.view_report() elif report_type: raise ValidationError( - _("No report has been defined for type `{}`.") - .format(report_type) + _("No report has been defined for type `{}`.").format(report_type) ) else: raise ValidationError( @@ -124,40 +113,40 @@ def print_report(self, report_type=None): def do_print(self, report_type): self.ensure_one() - if report_type == 'qweb-pdf': - xml_id = 'assets_management.report_asset_journal_pdf' + if report_type == "qweb-pdf": + xml_id = "assets_management.report_asset_journal_pdf" else: - xml_id = 'assets_management.report_asset_journal_xlsx' + xml_id = "assets_management.report_asset_journal_xlsx" report = self.env.ref(xml_id) return report.report_action(self) @api.multi def view_report(self): - """ Launches view for HTML report """ + """Launches view for HTML report""" self.ensure_one() - xmlid = 'assets_management.act_client_asset_journal_report' + xmlid = "assets_management.act_client_asset_journal_report" [act] = self.env.ref(xmlid).read() - ctx = act.get('context', {}) + ctx = act.get("context", {}) if isinstance(ctx, string_types): ctx = safe_eval(ctx) # Call update twice to force 'active_id(s)' values to be overridden ctx.update(dict(self._context)) ctx.update(active_id=self.id, active_ids=self.ids) - act['context'] = ctx + act["context"] = ctx return act @api.model def get_html(self, given_context=None): - """ Method needed from JavaScript widget to render HTML view """ + """Method needed from JavaScript widget to render HTML view""" context = dict(self.env.context) context.update(given_context or {}) - report = self or self.browse(context.get('active_id')) - xml_id = 'assets_management.template_asset_journal_report' + report = self or self.browse(context.get("active_id")) + xml_id = "assets_management.template_asset_journal_report" result = {} if report: - context['o'] = report - result['html'] = self.env.ref(xml_id).render(context) + context["o"] = report + result["html"] = self.env.ref(xml_id).render(context) return result ########################### @@ -167,7 +156,7 @@ def get_html(self, given_context=None): ########################### def compute_data_for_report(self): - """ Compute data to be printed """ + """Compute data to be printed""" self.set_report_name() self.generate_structure() self.generate_data() @@ -182,14 +171,14 @@ def generate_data(self): def generate_structure(self): deps = self.get_depreciations() - dep_lines = deps.mapped('line_ids') - assets = deps.mapped('asset_id') + dep_lines = deps.mapped("line_ids") + assets = deps.mapped("asset_id") if self.date: assets = assets.filtered( lambda a: not a.purchase_date or a.purchase_date <= self.date ) dep_lines = dep_lines.filtered(lambda dl: dl.date <= self.date) - categories = assets.mapped('category_id') + categories = assets.mapped("category_id") if not (categories and assets and deps and dep_lines): raise ValidationError( @@ -197,132 +186,146 @@ def generate_structure(self): ) dep_lines_grouped = OrderedDict() - fiscal_year = self.env['account.fiscal.year'] - for dep_line in dep_lines.sorted('date'): + fiscal_year = self.env["account.fiscal.year"] + for dep_line in dep_lines.sorted("date"): dep = dep_line.depreciation_id fyear = fiscal_year.get_fiscal_year_by_date( dep_line.date, company=dep_line.company_id ) key = (dep, fyear) if key not in dep_lines_grouped: - dep_lines_grouped[key] = self.env['asset.depreciation.line'] + dep_lines_grouped[key] = self.env["asset.depreciation.line"] dep_lines_grouped[key] += dep_line - self.write({ - 'report_category_ids': [ - (0, 0, {'category_id': c.id, 'report_id': self.id}) - for c in categories.sorted('name') - ] - }) - for report_categ in self.report_category_ids: - report_categ.write({ - 'report_asset_ids': [ - (0, 0, {'asset_id': a.id, 'report_id': self.id}) - for a in self.sort_assets(assets) - if a.category_id == report_categ.category_id + self.write( + { + "report_category_ids": [ + (0, 0, {"category_id": c.id, "report_id": self.id}) + for c in categories.sorted("name") ] - }) + } + ) + for report_categ in self.report_category_ids: + report_categ.write( + { + "report_asset_ids": [ + (0, 0, {"asset_id": a.id, "report_id": self.id}) + for a in self.sort_assets(assets) + if a.category_id == report_categ.category_id + ] + } + ) for report_asset in self.report_asset_ids: - report_asset.write({ - 'report_depreciation_ids': [ - (0, 0, {'depreciation_id': d.id, 'report_id': self.id}) - for d in deps - if d.asset_id == report_asset.asset_id - ] - }) + report_asset.write( + { + "report_depreciation_ids": [ + (0, 0, {"depreciation_id": d.id, "report_id": self.id}) + for d in deps + if d.asset_id == report_asset.asset_id + ] + } + ) for report_dep in self.report_depreciation_ids: sequence = 0 for (dep, fyear), lines in dep_lines_grouped.items(): if dep == report_dep.depreciation_id: sequence += 1 - report_dep.write({ - 'report_depreciation_year_line_ids': [ - (0, 0, {'dep_line_ids': [(6, 0, lines.ids)], - 'fiscal_year_id': fyear.id, - 'report_id': self.id, - 'sequence': sequence}) - ] - }) + report_dep.write( + { + "report_depreciation_year_line_ids": [ + ( + 0, + 0, + { + "dep_line_ids": [(6, 0, lines.ids)], + "fiscal_year_id": fyear.id, + "report_id": self.id, + "sequence": sequence, + }, + ) + ] + } + ) def generate_totals(self): curr = self.company_id.currency_id - categ_totals = self.report_category_ids.mapped('report_total_ids') - fnames = self.env['report_asset_journal_totals']._total_fnames + categ_totals = self.report_category_ids.mapped("report_total_ids") + fnames = self.env["report_asset_journal_totals"]._total_fnames totals_by_dep_type = { - t: {fname: 0 for fname in fnames} - for t in categ_totals.mapped('type_id') + t: {fname: 0 for fname in fnames} for t in categ_totals.mapped("type_id") } for total in categ_totals: total_curr = total.get_currency() total_type = total.type_id for fname in fnames: - totals_by_dep_type[total_type][fname] += \ - total_curr.compute(total[fname], curr) - self.write({ - 'report_total_ids': [ - (0, 0, dict( - v, - name=_("General Total"), - type_name=t.name_get()[0][-1], - type_id=t.id - )) - for t, v in totals_by_dep_type.items() - ] - }) + totals_by_dep_type[total_type][fname] += total_curr.compute( + total[fname], curr + ) + self.write( + { + "report_total_ids": [ + ( + 0, + 0, + dict( + v, + name=_("General Total"), + type_name=t.name_get()[0][-1], + type_id=t.id, + ), + ) + for t, v in totals_by_dep_type.items() + ] + } + ) def get_depreciations(self): domain = [] if self.asset_ids: - domain += [('asset_id', 'in', self.asset_ids.ids)] + domain += [("asset_id", "in", self.asset_ids.ids)] if self.category_ids: - domain += [('asset_id.category_id', 'in', self.category_ids.ids)] + domain += [("asset_id.category_id", "in", self.category_ids.ids)] if self.company_id: - domain += [('company_id', '=', self.company_id.id)] + domain += [("company_id", "=", self.company_id.id)] if self.date: - domain += [('date_start', '<=', self.date)] + domain += [("date_start", "<=", self.date)] if self.type_ids: - domain += [('type_id', 'in', self.type_ids.ids)] - return self.env['asset.depreciation'].search(domain) + domain += [("type_id", "in", self.type_ids.ids)] + return self.env["asset.depreciation"].search(domain) def set_report_name(self): report_name = _("Assets Depreciations ") if self.date: - report_name += _("to date {}").format( - format_date(self, 'date', '%d-%m-%Y') - ) + report_name += _("to date {}").format(format_date(self, "date", "%d-%m-%Y")) self.report_name = report_name.strip() def sort_assets(self, assets): sortable_assets = assets.filtered(self.asset_order_fname) - sorted_assets = sortable_assets.sorted(self.asset_order_fname) \ + sorted_assets = ( + sortable_assets.sorted(self.asset_order_fname) + (assets - sortable_assets).sorted() + ) return sorted_assets class ReportCategory(models.TransientModel): - _name = 'report_asset_journal_category' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_journal_category" + _inherit = "account_financial_report_abstract" # Data fields - category_id = fields.Many2one( - 'asset.category', - ondelete='cascade', - required=True - ) + category_id = fields.Many2one("asset.category", ondelete="cascade", required=True) # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) report_asset_ids = fields.One2many( - 'report_asset_journal_asset', - 'report_category_id' + "report_asset_journal_asset", "report_category_id" ) report_total_ids = fields.One2many( - 'report_asset_journal_totals', - 'report_category_id' + "report_asset_journal_totals", "report_category_id" ) # Fields to be printed @@ -334,93 +337,93 @@ def generate_data(self): def get_report_categ_data(self): self.ensure_one() - return {'category_name': self.category_id.name} + return {"category_name": self.category_id.name} def generate_totals(self): for categ in self: curr = categ.report_id.company_id.currency_id report_date = categ.report_id.date - report_deps = categ.report_asset_ids\ - .mapped('report_depreciation_ids') - fnames = categ.env['report_asset_journal_totals']._total_fnames + report_deps = categ.report_asset_ids.mapped("report_depreciation_ids") + fnames = categ.env["report_asset_journal_totals"]._total_fnames totals_by_dep_type = { t: {fname: 0 for fname in fnames} - for t in report_deps.mapped('depreciation_id.type_id') + for t in report_deps.mapped("depreciation_id.type_id") } - for report_dep in report_deps.filtered( - 'report_depreciation_year_line_ids' - ): + for report_dep in report_deps.filtered("report_depreciation_year_line_ids"): dep_type = report_dep.depreciation_id.type_id last_line = report_dep.report_depreciation_year_line_ids[-1] line_curr = last_line.get_currency() fy_start = last_line.fiscal_year_id.date_from fy_end = last_line.fiscal_year_id.date_to for fname in fnames: - if fname == 'amount_depreciation_fund_prev_year': + if fname == "amount_depreciation_fund_prev_year": if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) elif fname in ( - 'amount_in_total', - 'amount_out_total', - 'gain_loss_total' + "amount_in_total", + "amount_out_total", + "gain_loss_total", ): if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) elif report_date < fy_start: totals_by_dep_type[dep_type][fname] = 0 - elif fname == 'amount_depreciated': + elif fname == "amount_depreciated": if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) else: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) - categ.write({ - 'report_total_ids': [ - (0, 0, dict( - v, - name=categ.category_id.name_get()[0][-1], - type_name=t.name_get()[0][-1], - type_id=t.id - )) - for t, v in totals_by_dep_type.items() - ] - }) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) + categ.write( + { + "report_total_ids": [ + ( + 0, + 0, + dict( + v, + name=categ.category_id.name_get()[0][-1], + type_name=t.name_get()[0][-1], + type_id=t.id, + ), + ) + for t, v in totals_by_dep_type.items() + ] + } + ) class ReportAsset(models.TransientModel): - _name = 'report_asset_journal_asset' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_journal_asset" + _inherit = "account_financial_report_abstract" # Data fields - asset_id = fields.Many2one( - 'asset.asset', - ondelete='cascade', - required=True - ) + asset_id = fields.Many2one("asset.asset", ondelete="cascade", required=True) # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) - report_category_id = fields.Many2one( - 'report_asset_journal_category' - ) + report_category_id = fields.Many2one("report_asset_journal_category") report_depreciation_ids = fields.One2many( - 'report_asset_journal_depreciation', - 'report_asset_id' + "report_asset_journal_depreciation", "report_asset_id" ) report_purchase_doc_id = fields.Many2one( - 'report_asset_journal_accounting_doc', + "report_asset_journal_accounting_doc", ) report_sale_doc_id = fields.Many2one( - 'report_asset_journal_accounting_doc', + "report_asset_journal_accounting_doc", ) # Fields to be printed @@ -446,70 +449,80 @@ def get_currency(self): def get_report_asset_data(self): self.ensure_one() asset = self.asset_id - states_dict = dict(asset._fields['state'].selection) + states_dict = dict(asset._fields["state"].selection) vals = { - 'asset_code': asset.code or "/", - 'asset_name': asset.name, - 'asset_purchase_amount': asset.purchase_amount, - 'asset_state': states_dict.get(asset.state) or _("Unknown"), - 'asset_used': _("Used") if asset.used else _("New"), + "asset_code": asset.code or "/", + "asset_name": asset.name, + "asset_purchase_amount": asset.purchase_amount, + "asset_state": states_dict.get(asset.state) or _("Unknown"), + "asset_used": _("Used") if asset.used else _("New"), } - acc_doc = self.env['report_asset_journal_accounting_doc'] + acc_doc = self.env["report_asset_journal_accounting_doc"] purchase_vals = self.get_purchase_vals() if purchase_vals: - vals.update({ - 'report_purchase_doc_id': acc_doc.create(purchase_vals).id, - }) + vals.update( + { + "report_purchase_doc_id": acc_doc.create(purchase_vals).id, + } + ) sale_vals = self.get_sale_vals() if sale_vals: - vals.update({ - 'report_sale_doc_id': acc_doc.create(sale_vals).id, - }) + vals.update( + { + "report_sale_doc_id": acc_doc.create(sale_vals).id, + } + ) return vals def get_purchase_vals(self): asset = self.asset_id purchase_vals = { - 'partner_name': asset.supplier_id.name or "/", - 'partner_vat': asset.supplier_id.vat or "/", + "partner_name": asset.supplier_id.name or "/", + "partner_vat": asset.supplier_id.vat or "/", } if asset.purchase_date: - purchase_vals['document_date'] = format_date( - asset, 'purchase_date', '%d-%m-%Y' + purchase_vals["document_date"] = format_date( + asset, "purchase_date", "%d-%m-%Y" ) if asset.supplier_ref: - purchase_vals['partner_ref'] = asset.supplier_ref + purchase_vals["partner_ref"] = asset.supplier_ref elif asset.purchase_invoice_id.reference: - purchase_vals['partner_ref'] = asset.purchase_invoice_id.reference + purchase_vals["partner_ref"] = asset.purchase_invoice_id.reference elif asset.purchase_move_id.ref: - purchase_vals['partner_ref'] = asset.purchase_move_id.ref + purchase_vals["partner_ref"] = asset.purchase_move_id.ref else: - purchase_vals['partner_ref'] = "/" + purchase_vals["partner_ref"] = "/" if asset.purchase_invoice_id: - purchase_vals.update({ - 'document_nr': asset.purchase_invoice_id.number or "/", - 'res_id': asset.purchase_invoice_id.id, - 'res_model': 'account.invoice', - }) + purchase_vals.update( + { + "document_nr": asset.purchase_invoice_id.number or "/", + "res_id": asset.purchase_invoice_id.id, + "res_model": "account.invoice", + } + ) elif asset.purchase_move_id: - purchase_vals.update({ - 'document_nr': asset.purchase_move_id.name or "/", - 'res_id': asset.purchase_move_id.id, - 'res_model': 'account.move', - }) + purchase_vals.update( + { + "document_nr": asset.purchase_move_id.name or "/", + "res_id": asset.purchase_move_id.id, + "res_model": "account.move", + } + ) else: - purchase_vals.update({ - 'document_nr': "/", - 'res_id': asset.id, - 'res_model': 'asset.asset', - }) + purchase_vals.update( + { + "document_nr": "/", + "res_id": asset.id, + "res_model": "asset.asset", + } + ) return purchase_vals @@ -519,56 +532,57 @@ def get_sale_vals(self): return {} sale_vals = { - 'document_date': format_date(asset, 'sale_date', '%d-%m-%Y'), - 'partner_name': asset.customer_id.name, - 'partner_vat': asset.customer_id.vat or "/", + "document_date": format_date(asset, "sale_date", "%d-%m-%Y"), + "partner_name": asset.customer_id.name, + "partner_vat": asset.customer_id.vat or "/", } if asset.sale_invoice_id: - sale_vals.update({ - 'document_nr': asset.sale_invoice_id.number or "/", - 'res_id': asset.sale_invoice_id.id, - 'res_model': 'account.invoice', - }) + sale_vals.update( + { + "document_nr": asset.sale_invoice_id.number or "/", + "res_id": asset.sale_invoice_id.id, + "res_model": "account.invoice", + } + ) elif asset.sale_move_id: - sale_vals.update({ - 'document_nr': asset.sale_move_id.name or "/", - 'res_id': asset.sale_move_id.id, - 'res_model': 'account.move', - }) + sale_vals.update( + { + "document_nr": asset.sale_move_id.name or "/", + "res_id": asset.sale_move_id.id, + "res_model": "account.move", + } + ) else: - sale_vals.update({ - 'document_nr': "/", - 'res_id': asset.id, - 'res_model': 'asset.asset', - }) + sale_vals.update( + { + "document_nr": "/", + "res_id": asset.id, + "res_model": "asset.asset", + } + ) return sale_vals class ReportDepreciation(models.TransientModel): - _name = 'report_asset_journal_depreciation' - _inherit = 'account_financial_report_abstract' - _order = 'type_name asc' + _name = "report_asset_journal_depreciation" + _inherit = "account_financial_report_abstract" + _order = "type_name asc" # Data fields depreciation_id = fields.Many2one( - 'asset.depreciation', - ondelete='cascade', - required=True + "asset.depreciation", ondelete="cascade", required=True ) # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) - report_asset_id = fields.Many2one( - 'report_asset_journal_asset' - ) + report_asset_id = fields.Many2one("report_asset_journal_asset") report_depreciation_year_line_ids = fields.One2many( - 'report_asset_journal_depreciation_line_year', - 'report_depreciation_id' + "report_asset_journal_depreciation_line_year", "report_depreciation_id" ) # Fields to be printed @@ -596,47 +610,42 @@ def get_report_dep_data(self): self.ensure_one() dep = self.depreciation_id if dep.pro_rata_temporis: - dep_pro_rata_temporis = u"\u2612" # checked ballot box -> ☒ + dep_pro_rata_temporis = "\u2612" # checked ballot box -> ☒ else: - dep_pro_rata_temporis = u"\u2610" # empty ballot box -> ☐ + dep_pro_rata_temporis = "\u2610" # empty ballot box -> ☐ return { - 'dep_amount_depreciable': dep.amount_depreciable, - 'dep_date_start': format_date(dep, 'date_start', '%d-%m-%Y'), - 'dep_percentage': dep.percentage, - 'dep_pro_rata_temporis': dep_pro_rata_temporis, - 'mode_name': dep.mode_id.name_get()[0][-1] if dep.mode_id else "", - 'type_name': dep.type_id.name_get()[0][-1] if dep.type_id else "" + "dep_amount_depreciable": dep.amount_depreciable, + "dep_date_start": format_date(dep, "date_start", "%d-%m-%Y"), + "dep_percentage": dep.percentage, + "dep_pro_rata_temporis": dep_pro_rata_temporis, + "mode_name": dep.mode_id.name_get()[0][-1] if dep.mode_id else "", + "type_name": dep.type_id.name_get()[0][-1] if dep.type_id else "", } class ReportDepreciationLineByYear(models.TransientModel): - _name = 'report_asset_journal_depreciation_line_year' - _inherit = 'account_financial_report_abstract' - _order = 'sequence asc' + _name = "report_asset_journal_depreciation_line_year" + _inherit = "account_financial_report_abstract" + _order = "sequence asc" # Data fields dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - relation='report_journal_line_year_dep_line' + "asset.depreciation.line", relation="report_journal_line_year_dep_line" ) - fiscal_year_id = fields.Many2one( - 'account.fiscal.year' - ) + fiscal_year_id = fields.Many2one("account.fiscal.year") # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) - report_depreciation_id = fields.Many2one( - 'report_asset_journal_depreciation' - ) + report_depreciation_id = fields.Many2one("report_asset_journal_depreciation") report_accounting_doc_ids = fields.Many2many( - 'report_asset_journal_accounting_doc', - relation='year_dep_line_accounting_doc_rel' + "report_asset_journal_accounting_doc", + relation="year_dep_line_accounting_doc_rel", ) sequence = fields.Integer() @@ -688,32 +697,34 @@ def get_report_dep_line_year_data(self): grouped_amounts = self.dep_line_ids.get_balances_grouped() amount_depreciable = report_dep.dep_amount_depreciable - amount_gain = grouped_amounts.get('gain') or 0.0 + amount_gain = grouped_amounts.get("gain") or 0.0 amount_gain_total = amount_gain - amount_historical = abs(grouped_amounts.get('historical') or 0.0) - amount_in = abs(grouped_amounts.get('in') or 0.0) + amount_historical = abs(grouped_amounts.get("historical") or 0.0) + amount_in = abs(grouped_amounts.get("in") or 0.0) amount_in_total = amount_in - amount_loss = grouped_amounts.get('loss') or 0.0 + amount_loss = grouped_amounts.get("loss") or 0.0 amount_loss_total = amount_loss - amount_out = abs(grouped_amounts.get('out') or 0.0) + amount_out = abs(grouped_amounts.get("out") or 0.0) amount_out_total = amount_out gain_loss = amount_gain + amount_loss gain_loss_total = gain_loss - amount_depreciated = sum([ - line.amount - for line in self.dep_line_ids.filtered( - lambda l: l.move_type == 'depreciated' - and not l.partial_dismissal - ) - ]) - amount_dismissal = sum([ - line.amount - for line in self.dep_line_ids.filtered( - lambda l: l.move_type == 'depreciated' - and l.partial_dismissal - ) - ]) + amount_depreciated = sum( + [ + line.amount + for line in self.dep_line_ids.filtered( + lambda l: l.move_type == "depreciated" and not l.partial_dismissal + ) + ] + ) + amount_dismissal = sum( + [ + line.amount + for line in self.dep_line_ids.filtered( + lambda l: l.move_type == "depreciated" and l.partial_dismissal + ) + ] + ) prev_year_line = report_dep.report_depreciation_year_line_ids.filtered( lambda l: l.sequence == self.sequence - 1 @@ -721,46 +732,52 @@ def get_report_dep_line_year_data(self): asset = self.report_depreciation_id.report_asset_id.asset_id fy_start = self.fiscal_year_id.date_from fy_end = self.fiscal_year_id.date_to - if asset.sold and asset.sale_date \ - and fy_start <= asset.sale_date <= fy_end: + if asset.sold and asset.sale_date and fy_start <= asset.sale_date <= fy_end: amount_depreciable_upd = 0.0 depreciation_fund_curr_year = 0.0 amount_residual = 0.0 if prev_year_line: - depreciation_fund_prev_year = prev_year_line\ - .amount_depreciation_fund_curr_year + depreciation_fund_prev_year = ( + prev_year_line.amount_depreciation_fund_curr_year + ) amount_in_total += prev_year_line.amount_in_total amount_out_total += prev_year_line.amount_out_total else: depreciation_fund_prev_year = 0.0 else: if prev_year_line: - depreciation_fund_prev_year = prev_year_line\ - .amount_depreciation_fund_curr_year + depreciation_fund_prev_year = ( + prev_year_line.amount_depreciation_fund_curr_year + ) prev_year_resid = prev_year_line.amount_residual - amount_depreciable_upd = prev_year_line.\ - amount_depreciable_updated + amount_in - amount_out + amount_depreciable_upd = ( + prev_year_line.amount_depreciable_updated + amount_in - amount_out + ) amount_in_total += prev_year_line.amount_in_total amount_out_total += prev_year_line.amount_out_total else: depreciation_fund_prev_year = 0.0 prev_year_resid = amount_depreciable - amount_depreciable_upd = amount_depreciable + amount_in \ - - amount_out + amount_depreciable_upd = amount_depreciable + amount_in - amount_out - depreciation_fund_curr_year = depreciation_fund_prev_year \ - + amount_depreciated + amount_dismissal - amount_residual = prev_year_resid + amount_in - amount_out \ - - amount_depreciated - amount_dismissal + depreciation_fund_curr_year = ( + depreciation_fund_prev_year + amount_depreciated + amount_dismissal + ) + amount_residual = ( + prev_year_resid + + amount_in + - amount_out + - amount_depreciated + - amount_dismissal + ) if prev_year_line: amount_gain_total += prev_year_line.amount_gain_total amount_loss_total += prev_year_line.amount_loss_total gain_loss_total += prev_year_line.gain_loss_total - type_mapping = {'in': {}, 'out': {}} + type_mapping = {"in": {}, "out": {}} for dep_line in self.dep_line_ids.filtered( - lambda l: l.move_type in ('in', 'out') - and l.depreciation_line_type_id + lambda l: l.move_type in ("in", "out") and l.depreciation_line_type_id ): dep_type = dep_line.depreciation_line_type_id if dep_type not in type_mapping[dep_line.move_type]: @@ -769,54 +786,52 @@ def get_report_dep_line_year_data(self): amount_in_detail = amount_out_detail = "" has_amount_detail = False - if type_mapping['in']: - amount_in_detail = "; ".join([ - "{}: {}".format(dep_type.name, self.format_amount(amount)) - for dep_type, amount in sorted(list( - type_mapping['in'].items())) - ]) + if type_mapping["in"]: + amount_in_detail = "; ".join( + [ + "{}: {}".format(dep_type.name, self.format_amount(amount)) + for dep_type, amount in sorted(list(type_mapping["in"].items())) + ] + ) has_amount_detail = True - if type_mapping['out']: - amount_out_detail = "; ".join([ - "{}: {}".format(dep_type.name, self.format_amount(amount)) - for dep_type, amount in sorted(list( - type_mapping['out'].items())) - ]) + if type_mapping["out"]: + amount_out_detail = "; ".join( + [ + "{}: {}".format(dep_type.name, self.format_amount(amount)) + for dep_type, amount in sorted(list(type_mapping["out"].items())) + ] + ) has_amount_detail = True accounting_doc_vals = [] for dep_line in self.dep_line_ids.filtered( - lambda l: l.move_type in ('in', 'out') + lambda l: l.move_type in ("in", "out") ): for num, aa_info in enumerate(dep_line.asset_accounting_info_ids): vals = {} if aa_info.invoice_line_id: inv = aa_info.invoice_line_id.invoice_id vals = { - 'document_date': format_date( - dep_line, 'date', '%d-%m-%Y' - ), - 'document_nr': inv.number or "/", - 'partner_name': inv.partner_id.name or "/", - 'partner_ref': inv.reference or "/", - 'partner_vat': inv.partner_id.vat or "/", - 'res_id': inv.id, - 'res_model': 'account.invoice', - 'sequence': num + 1, + "document_date": format_date(dep_line, "date", "%d-%m-%Y"), + "document_nr": inv.number or "/", + "partner_name": inv.partner_id.name or "/", + "partner_ref": inv.reference or "/", + "partner_vat": inv.partner_id.vat or "/", + "res_id": inv.id, + "res_model": "account.invoice", + "sequence": num + 1, } elif aa_info.move_id: move = aa_info.move_id vals = { - 'document_date': format_date( - dep_line, 'date', '%d-%m-%Y' - ), - 'document_nr': move.name or "/", - 'partner_name': move.partner_id.name or "/", - 'partner_ref': move.ref or "/", - 'partner_vat': move.partner_id.vat or "/", - 'res_id': move.id, - 'res_model': 'account.move', - 'sequence': num + 1, + "document_date": format_date(dep_line, "date", "%d-%m-%Y"), + "document_nr": move.name or "/", + "partner_name": move.partner_id.name or "/", + "partner_ref": move.ref or "/", + "partner_vat": move.partner_id.vat or "/", + "res_id": move.id, + "res_model": "account.move", + "sequence": num + 1, } if vals: accounting_doc_vals.append((0, 0, vals)) @@ -829,40 +844,40 @@ def get_report_dep_line_year_data(self): year = "{} - {}".format(start, end) return { - 'amount_depreciable': amount_depreciable, - 'amount_depreciable_updated': amount_depreciable_upd, - 'amount_depreciated': amount_depreciated, - 'amount_depreciation_fund_curr_year': depreciation_fund_curr_year, - 'amount_depreciation_fund_prev_year': depreciation_fund_prev_year, - 'amount_gain': amount_gain, - 'amount_historical': amount_historical, - 'amount_in': amount_in, - 'amount_in_detail': amount_in_detail, - 'amount_in_total': amount_in_total, - 'amount_loss': amount_loss, - 'amount_out': amount_out, - 'amount_out_detail': amount_out_detail, - 'amount_out_total': amount_out_total, - 'amount_residual': amount_residual, - 'date_start': report_dep.dep_date_start, - 'gain_loss': gain_loss, - 'gain_loss_total': gain_loss_total, - 'has_amount_detail': has_amount_detail, - 'percentage': report_dep.dep_percentage, - 'report_accounting_doc_ids': accounting_doc_vals, - 'type_name': report_dep.type_name, - 'year': year, + "amount_depreciable": amount_depreciable, + "amount_depreciable_updated": amount_depreciable_upd, + "amount_depreciated": amount_depreciated, + "amount_depreciation_fund_curr_year": depreciation_fund_curr_year, + "amount_depreciation_fund_prev_year": depreciation_fund_prev_year, + "amount_gain": amount_gain, + "amount_historical": amount_historical, + "amount_in": amount_in, + "amount_in_detail": amount_in_detail, + "amount_in_total": amount_in_total, + "amount_loss": amount_loss, + "amount_out": amount_out, + "amount_out_detail": amount_out_detail, + "amount_out_total": amount_out_total, + "amount_residual": amount_residual, + "date_start": report_dep.dep_date_start, + "gain_loss": gain_loss, + "gain_loss_total": gain_loss_total, + "has_amount_detail": has_amount_detail, + "percentage": report_dep.dep_percentage, + "report_accounting_doc_ids": accounting_doc_vals, + "type_name": report_dep.type_name, + "year": year, } class ReportAccountingDoc(models.TransientModel): - _name = 'report_asset_journal_accounting_doc' - _inherit = 'account_financial_report_abstract' - _order = 'sequence asc' + _name = "report_asset_journal_accounting_doc" + _inherit = "account_financial_report_abstract" + _order = "sequence asc" # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) # Fields to be printed @@ -877,34 +892,32 @@ class ReportAccountingDoc(models.TransientModel): class ReportTotals(models.TransientModel): - _name = 'report_asset_journal_totals' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_journal_totals" + _inherit = "account_financial_report_abstract" _total_fnames = [ - 'amount_depreciable_updated', - 'amount_depreciated', - 'amount_depreciation_fund_curr_year', - 'amount_depreciation_fund_prev_year', - 'amount_gain', - 'amount_in_total', - 'amount_loss', - 'amount_out_total', - 'amount_residual', - 'gain_loss_total', + "amount_depreciable_updated", + "amount_depreciated", + "amount_depreciation_fund_curr_year", + "amount_depreciation_fund_prev_year", + "amount_gain", + "amount_in_total", + "amount_loss", + "amount_out_total", + "amount_residual", + "gain_loss_total", ] # Data fields type_id = fields.Many2one( - 'asset.depreciation.type', + "asset.depreciation.type", ) # Report structure fields report_id = fields.Many2one( - 'report_asset_journal', + "report_asset_journal", ) - report_category_id = fields.Many2one( - 'report_asset_journal_category' - ) + report_category_id = fields.Many2one("report_asset_journal_category") # Fields to be printed amount_depreciable_updated = fields.Float() diff --git a/assets_management/report/asset_journal_xlsx.py b/assets_management/report/asset_journal_xlsx.py index 6479fa385d1a..3b3127d5a97e 100644 --- a/assets_management/report/asset_journal_xlsx.py +++ b/assets_management/report/asset_journal_xlsx.py @@ -8,11 +8,11 @@ class AssetJournalXslx(models.AbstractModel): - _name = 'report.assets_management.report_asset_journal_xlsx' - _inherit = 'report.account_financial_report.abstract_report_xlsx' + _name = "report.assets_management.report_asset_journal_xlsx" + _inherit = "report.account_financial_report.abstract_report_xlsx" def __init__(self, pool, cr): - """ Adds new attributes """ + """Adds new attributes""" super().__init__(pool, cr) # Add report objects @@ -52,7 +52,7 @@ def __init__(self, pool, cr): self.format_title = None def generate_xlsx_report(self, workbook, data, objects): - """ Set wb, data and report attributes """ + """Set wb, data and report attributes""" self.workbook = workbook self.data = data self.report = objects @@ -61,66 +61,82 @@ def generate_xlsx_report(self, workbook, data, objects): super().generate_xlsx_report(workbook, data, objects) def set_formats(self): - """ Defines custom formats """ + """Defines custom formats""" # 1- Category formats - self.format_category_name = self.workbook.add_format({ - 'align': 'center', - 'bg_color': '#337AB7', - 'bold': True, - 'font_color': '#FFFFFF', - 'font_size': 16, - }) + self.format_category_name = self.workbook.add_format( + { + "align": "center", + "bg_color": "#337AB7", + "bold": True, + "font_color": "#FFFFFF", + "font_size": 16, + } + ) # 2- Asset formats - self.format_asset_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_color': '#337AB7', - 'font_size': 14, - }) - self.format_asset_value = self.workbook.add_format({ - 'align': 'center', - 'font_color': '#337AB7', - 'font_size': 14, - }) + self.format_asset_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_color": "#337AB7", + "font_size": 14, + } + ) + self.format_asset_value = self.workbook.add_format( + { + "align": "center", + "font_color": "#337AB7", + "font_size": 14, + } + ) # 3- Depreciations formats - self.format_depreciation_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_size': 12, - }) - self.format_depreciation_value = self.workbook.add_format({ - 'align': 'center', - 'font_size': 12, - }) + self.format_depreciation_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_size": 12, + } + ) + self.format_depreciation_value = self.workbook.add_format( + { + "align": "center", + "font_size": 12, + } + ) # 4- Depreciation yearly and amount details formats - self.format_depreciation_year_line_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_size': 12, - }) - self.format_depreciation_year_line_value_center = self.workbook \ - .add_format({ - 'align': 'center', - 'font_size': 12, - }) - self.format_depreciation_year_line_value_right = self.workbook \ - .add_format({ - 'align': 'right', - 'font_size': 12, - }) + self.format_depreciation_year_line_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_size": 12, + } + ) + self.format_depreciation_year_line_value_center = self.workbook.add_format( + { + "align": "center", + "font_size": 12, + } + ) + self.format_depreciation_year_line_value_right = self.workbook.add_format( + { + "align": "right", + "font_size": 12, + } + ) # 5- Report title - self.format_title = self.workbook.add_format({ - 'align': 'center', - 'bg_color': '#337AB7', - 'bold': True, - 'font_color': 'white', - 'font_size': 20, - }) + self.format_title = self.workbook.add_format( + { + "align": "center", + "bg_color": "#337AB7", + "bold": True, + "font_color": "white", + "font_size": 20, + } + ) def set_report_data(self): self.set_category_data() @@ -137,10 +153,12 @@ def set_category_data(self): def generate_category_data(self): data = ( - {'title': _("Category"), - 'field': 'category_name', - 'tstyle': self.format_category_name, - 'vstyle': self.format_category_name}, + { + "title": _("Category"), + "field": "category_name", + "tstyle": self.format_category_name, + "vstyle": self.format_category_name, + }, ) return dict(enumerate(data)) @@ -149,56 +167,75 @@ def set_asset_data(self): def generate_asset_data(self): data = ( - {'title': _("Asset"), - 'field': 'asset_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Code"), - 'field': 'asset_code', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Purchase Amount"), - 'field': 'asset_purchase_amount', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Purchased as New / Used"), - 'field': 'asset_used', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Status"), - 'field': 'asset_state', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Asset"), + "field": "asset_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Code"), + "field": "asset_code", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Purchase Amount"), + "field": "asset_purchase_amount", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Purchased as New / Used"), + "field": "asset_used", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Status"), + "field": "asset_state", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return dict(enumerate(data)) def set_asset_accounting_doc_data(self): - self.asset_accounting_doc_data = \ - self.generate_asset_accounting_doc_data() + self.asset_accounting_doc_data = self.generate_asset_accounting_doc_data() def generate_asset_accounting_doc_data(self): data = ( - {'title': _("Partner"), - 'field': 'partner_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("VAT"), - 'field': 'partner_vat', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Document Nr"), - 'field': 'document_nr', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Document Date"), - 'field': 'document_date', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Supplier Ref"), - 'field': 'partner_ref', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Partner"), + "field": "partner_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("VAT"), + "field": "partner_vat", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Document Nr"), + "field": "document_nr", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Document Date"), + "field": "document_date", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Supplier Ref"), + "field": "partner_ref", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return {n + 1: d for n, d in enumerate(data)} @@ -207,130 +244,175 @@ def set_depreciation_data(self): def generate_depreciation_data(self): data = ( - {'title': _("Depreciation Type"), - 'field': 'type_name', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Depreciation Mode"), - 'field': 'mode_name', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Depreciable Amount"), - 'field': 'dep_amount_depreciable', - 'type': 'amount', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Starting From"), - 'field': 'dep_date_start', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Dep. Percentage (%)"), - 'field': 'dep_percentage', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Pro Rata Temporis"), - 'field': 'dep_pro_rata_temporis', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, + { + "title": _("Depreciation Type"), + "field": "type_name", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Depreciation Mode"), + "field": "mode_name", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Depreciable Amount"), + "field": "dep_amount_depreciable", + "type": "amount", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Starting From"), + "field": "dep_date_start", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Dep. Percentage (%)"), + "field": "dep_percentage", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Pro Rata Temporis"), + "field": "dep_pro_rata_temporis", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, ) return {n + 1: d for n, d in enumerate(data)} def set_depreciation_line_year_data(self): - self.depreciation_line_year_data = \ - self.generate_depreciation_line_year_data() + self.depreciation_line_year_data = self.generate_depreciation_line_year_data() def generate_depreciation_line_year_data(self): data = ( - {'title': _("Year"), - 'field': 'year', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Amount"), - 'field': 'amount_depreciable_updated', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("In Amount"), - 'field': 'amount_in', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Out Amount"), - 'field': 'amount_out', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Prev. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_prev_year', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Depreciation"), - 'field': 'amount_depreciated', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Curr. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_curr_year', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Gain / Loss"), - 'field': 'gain_loss', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Residual"), - 'field': 'amount_residual', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, + { + "title": _("Year"), + "field": "year", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Amount"), + "field": "amount_depreciable_updated", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("In Amount"), + "field": "amount_in", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Out Amount"), + "field": "amount_out", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Prev. Year Dep. Fund"), + "field": "amount_depreciation_fund_prev_year", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Depreciation"), + "field": "amount_depreciated", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Curr. Year Dep. Fund"), + "field": "amount_depreciation_fund_curr_year", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Gain / Loss"), + "field": "gain_loss", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Residual"), + "field": "amount_residual", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, ) return {n + 1: d for n, d in enumerate(data)} def set_depreciation_line_amount_detail_data(self): - self.depreciation_line_amount_detail_data = \ + self.depreciation_line_amount_detail_data = ( self.generate_depreciation_line_amount_detail_data() + ) def generate_depreciation_line_amount_detail_data(self): data = ( - {'title': _("In Amount - Detail"), - 'field': 'amount_in_detail', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Out Amount - Detail"), - 'field': 'amount_out_detail', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, + { + "title": _("In Amount - Detail"), + "field": "amount_in_detail", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Out Amount - Detail"), + "field": "amount_out_detail", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, ) return {n + 3: d for n, d in enumerate(data)} def set_depreciation_line_accounting_doc_data(self): - self.depreciation_line_accounting_doc_data = \ + self.depreciation_line_accounting_doc_data = ( self.generate_depreciation_line_accounting_doc_data() + ) def generate_depreciation_line_accounting_doc_data(self): data = ( - {'title': _("Partner"), - 'field': 'partner_name', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("VAT"), - 'field': 'partner_vat', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Document Nr"), - 'field': 'document_nr', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Document Date"), - 'field': 'document_date', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Supplier Ref"), - 'field': 'partner_ref', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, + { + "title": _("Partner"), + "field": "partner_name", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("VAT"), + "field": "partner_vat", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Document Nr"), + "field": "document_nr", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Document Date"), + "field": "document_date", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Supplier Ref"), + "field": "partner_ref", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, ) return {n + 3: d for n, d in enumerate(data)} @@ -339,99 +421,124 @@ def set_totals_data(self): def get_totals_data(self): data = ( - {'title': _("Total"), - 'field': 'name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Type"), - 'field': 'type_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Amount"), - 'field': 'amount_depreciable_updated', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("In Amount"), - 'field': 'amount_in_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Out Amount"), - 'field': 'amount_out_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Prev. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_prev_year', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Depreciation"), - 'field': 'amount_depreciated', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Curr. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_curr_year', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Gain / Loss"), - 'field': 'gain_loss_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Residual"), - 'field': 'amount_residual', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Total"), + "field": "name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Type"), + "field": "type_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Amount"), + "field": "amount_depreciable_updated", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("In Amount"), + "field": "amount_in_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Out Amount"), + "field": "amount_out_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Prev. Year Dep. Fund"), + "field": "amount_depreciation_fund_prev_year", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Depreciation"), + "field": "amount_depreciated", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Curr. Year Dep. Fund"), + "field": "amount_depreciation_fund_curr_year", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Gain / Loss"), + "field": "gain_loss_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Residual"), + "field": "amount_residual", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return {n: d for n, d in enumerate(data)} def _set_column_width(self): - """ Override to force every column to width 25 at least """ + """Override to force every column to width 25 at least""" max_width = self.get_max_width_dict() for col, width in max_width.items(): self.sheet.set_column(col, col, max(width, 25)) def get_max_width_dict(self): - min_col = min([ - min(self.category_data.keys()), - min(self.asset_data.keys()), - min(self.asset_accounting_doc_data.keys()), - min(self.depreciation_data.keys()), - min(self.depreciation_line_year_data.keys()), - min(self.depreciation_line_amount_detail_data.keys()), - min(self.depreciation_line_accounting_doc_data.keys()), - min(self.totals_data.keys()), - ]) - max_col = max([ - max(self.category_data.keys()), - max(self.asset_data.keys()), - max(self.asset_accounting_doc_data.keys()), - max(self.depreciation_data.keys()), - max(self.depreciation_line_year_data.keys()), - max(self.depreciation_line_amount_detail_data.keys()), - max(self.depreciation_line_accounting_doc_data.keys()), - max(self.totals_data.keys()), - ]) + min_col = min( + [ + min(self.category_data.keys()), + min(self.asset_data.keys()), + min(self.asset_accounting_doc_data.keys()), + min(self.depreciation_data.keys()), + min(self.depreciation_line_year_data.keys()), + min(self.depreciation_line_amount_detail_data.keys()), + min(self.depreciation_line_accounting_doc_data.keys()), + min(self.totals_data.keys()), + ] + ) + max_col = max( + [ + max(self.category_data.keys()), + max(self.asset_data.keys()), + max(self.asset_accounting_doc_data.keys()), + max(self.depreciation_data.keys()), + max(self.depreciation_line_year_data.keys()), + max(self.depreciation_line_amount_detail_data.keys()), + max(self.depreciation_line_accounting_doc_data.keys()), + max(self.totals_data.keys()), + ] + ) return { - col: max([ - self.category_data.get(col, {}).get('width') or 0, - self.asset_data.get(col, {}).get('width') or 0, - self.asset_accounting_doc_data.get(col, {}).get('width') or 0, - self.depreciation_data.get(col, {}).get('width') or 0, - self.depreciation_line_year_data.get(col, {}) - .get('width') or 0, - self.depreciation_line_amount_detail_data.get(col, {}) - .get('width') or 0, - self.depreciation_line_accounting_doc_data.get(col, {}) - .get('width') or 0, - self.totals_data.get(col, {}).get('width') or 0, - ]) + col: max( + [ + self.category_data.get(col, {}).get("width") or 0, + self.asset_data.get(col, {}).get("width") or 0, + self.asset_accounting_doc_data.get(col, {}).get("width") or 0, + self.depreciation_data.get(col, {}).get("width") or 0, + self.depreciation_line_year_data.get(col, {}).get("width") or 0, + self.depreciation_line_amount_detail_data.get(col, {}).get("width") + or 0, + self.depreciation_line_accounting_doc_data.get(col, {}).get("width") + or 0, + self.totals_data.get(col, {}).get("width") or 0, + ] + ) for col in range(min_col, max_col + 1) } @@ -448,13 +555,12 @@ def _write_report_title(self, title): Writes report title on current line using all defined columns width """ self.sheet.merge_range( - self.row_pos, 0, self.row_pos, 9, - title, self.format_title + self.row_pos, 0, self.row_pos, 9, title, self.format_title ) self.row_pos += 3 def _generate_report_content(self, workbook, report): - """ Creates actual xls report """ + """Creates actual xls report""" for categ_section in report.report_category_ids: self.write_all(self.category_data, categ_section) @@ -464,7 +570,7 @@ def _generate_report_content(self, workbook, report): if asset_section.report_purchase_doc_id: self.write_all( self.asset_accounting_doc_data, - asset_section.report_purchase_doc_id + asset_section.report_purchase_doc_id, ) for dep_section in asset_section.report_depreciation_ids: @@ -472,9 +578,7 @@ def _generate_report_content(self, workbook, report): self.write_header(self.depreciation_line_year_data) for year in dep_section.report_depreciation_year_line_ids: - self.write_value( - self.depreciation_line_year_data, year - ) + self.write_value(self.depreciation_line_year_data, year) if year.has_amount_detail: self.write_value( self.depreciation_line_amount_detail_data, year @@ -486,8 +590,7 @@ def _generate_report_content(self, workbook, report): if asset_section.report_sale_doc_id: self.write_all( - self.asset_accounting_doc_data, - asset_section.report_sale_doc_id + self.asset_accounting_doc_data, asset_section.report_sale_doc_id ) self.row_pos += 1 @@ -512,17 +615,17 @@ def write_all(self, data, obj): def write_header(self, data): pos = self.row_pos for col, data in data.items(): - self.sheet.write(pos, col, data['title'], data['tstyle']) + self.sheet.write(pos, col, data["title"], data["tstyle"]) self.row_pos += 1 def write_value(self, data, obj): pos = self.row_pos for col, data in data.items(): - value, style = getattr(obj, data['field']), data['vstyle'] - if data.get('type') == 'amount': - value = getattr(obj, 'format_amount')(value) + value, style = getattr(obj, data["field"]), data["vstyle"] + if data.get("type") == "amount": + value = getattr(obj, "format_amount")(value) if value in (False, None): - value = '/' + value = "/" self.sheet.write(pos, col, value, style) self.row_pos += 1 @@ -533,21 +636,18 @@ def write_value(self, data, obj): ######################################################## def _get_report_filters(self, report): - """ Override original method even if not used to avoid errors """ + """Override original method even if not used to avoid errors""" return [] def _get_report_columns(self, report): - """ Override original method even if not used to avoid errors """ + """Override original method even if not used to avoid errors""" return {} def _get_col_count_filter_name(self): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" def _get_col_count_filter_value(self): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" def _write_filters(self, filters): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" diff --git a/assets_management/report/asset_previsional.py b/assets_management/report/asset_previsional.py index fa25a817bc87..633c937d9e78 100644 --- a/assets_management/report/asset_previsional.py +++ b/assets_management/report/asset_previsional.py @@ -14,9 +14,9 @@ def format_date(rec, field_name, fmt): - """ Formats record's field value according to given format `fmt` """ + """Formats record's field value according to given format `fmt`""" if not rec[field_name]: - return '' + return "" return rec._fields[field_name].from_string(rec[field_name]).strftime(fmt) @@ -34,22 +34,23 @@ class Report(models.TransientModel): Asset has a relation to the section Accounting Data which stores sale/purchase data. """ - _name = 'report_asset_previsional' - _inherit = 'account_financial_report_abstract' + + _name = "report_asset_previsional" + _inherit = "account_financial_report_abstract" # Data fields asset_ids = fields.Many2many( - 'asset.asset', + "asset.asset", ) asset_order_fname = fields.Char() category_ids = fields.Many2many( - 'asset.category', + "asset.category", ) company_id = fields.Many2one( - 'res.company', + "res.company", ) date = fields.Date() @@ -59,38 +60,27 @@ class Report(models.TransientModel): show_category_totals = fields.Boolean() type_ids = fields.Many2many( - 'asset.depreciation.type', + "asset.depreciation.type", ) # Report structure fields - previsional_line_ids = fields.Many2many( - 'asset.depreciation.line' - ) + previsional_line_ids = fields.Many2many("asset.depreciation.line") report_category_ids = fields.One2many( - 'report_asset_previsional_category', - 'report_id' + "report_asset_previsional_category", "report_id" ) - report_asset_ids = fields.One2many( - 'report_asset_previsional_asset', - 'report_id' - ) + report_asset_ids = fields.One2many("report_asset_previsional_asset", "report_id") report_depreciation_ids = fields.One2many( - 'report_asset_previsional_depreciation', - 'report_id' + "report_asset_previsional_depreciation", "report_id" ) report_depreciation_line_year_ids = fields.One2many( - 'report_asset_previsional_depreciation_line_year', - 'report_id' + "report_asset_previsional_depreciation_line_year", "report_id" ) - report_total_ids = fields.One2many( - 'report_asset_previsional_totals', - 'report_id' - ) + report_total_ids = fields.One2many("report_asset_previsional_totals", "report_id") # Fields to be printed report_footer_year = fields.Char() @@ -111,15 +101,14 @@ def print_report(self, report_type=None): :param report_type: string that represents the report type """ self.ensure_one() - report_type = report_type or 'qweb-pdf' - if report_type in ('qweb-pdf', 'xlsx'): + report_type = report_type or "qweb-pdf" + if report_type in ("qweb-pdf", "xlsx"): res = self.do_print(report_type) - elif report_type == 'qweb-html': + elif report_type == "qweb-html": res = self.view_report() elif report_type: raise ValidationError( - _("No report has been defined for type `{}`.") - .format(report_type) + _("No report has been defined for type `{}`.").format(report_type) ) else: raise ValidationError( @@ -129,40 +118,40 @@ def print_report(self, report_type=None): def do_print(self, report_type): self.ensure_one() - if report_type == 'qweb-pdf': - xml_id = 'assets_management.report_asset_previsional_pdf' + if report_type == "qweb-pdf": + xml_id = "assets_management.report_asset_previsional_pdf" else: - xml_id = 'assets_management.report_asset_previsional_xlsx' + xml_id = "assets_management.report_asset_previsional_xlsx" report = self.env.ref(xml_id) return report.report_action(self) @api.multi def view_report(self): - """ Launches view for HTML report """ + """Launches view for HTML report""" self.ensure_one() - xmlid = 'assets_management.act_client_asset_previsional_report' + xmlid = "assets_management.act_client_asset_previsional_report" [act] = self.env.ref(xmlid).read() - ctx = act.get('context', {}) + ctx = act.get("context", {}) if isinstance(ctx, string_types): ctx = safe_eval(ctx) # Call update twice to force 'active_id(s)' values to be overridden ctx.update(dict(self._context)) ctx.update(active_id=self.id, active_ids=self.ids) - act['context'] = ctx + act["context"] = ctx return act @api.model def get_html(self, given_context=None): - """ Method needed from JavaScript widget to render HTML view """ + """Method needed from JavaScript widget to render HTML view""" context = dict(self.env.context) context.update(given_context or {}) - report = self or self.browse(context.get('active_id')) - xml_id = 'assets_management.template_asset_previsional_report' + report = self or self.browse(context.get("active_id")) + xml_id = "assets_management.template_asset_previsional_report" result = {} if report: - context['o'] = report - result['html'] = self.env.ref(xml_id).render(context) + context["o"] = report + result["html"] = self.env.ref(xml_id).render(context) return result ########################### @@ -172,7 +161,7 @@ def get_html(self, given_context=None): ########################### def compute_data_for_report(self): - """ Compute data to be printed """ + """Compute data to be printed""" self.set_report_name() self.generate_structure() self.generate_data() @@ -190,8 +179,8 @@ def generate_data(self): def generate_structure(self): assets = self.get_assets() - categories = assets.mapped('category_id') - deps = assets.mapped('depreciation_ids') + categories = assets.mapped("category_id") + deps = assets.mapped("depreciation_ids") if self.type_ids: deps = deps.filtered(lambda d: d.type_id in self.type_ids) if not (categories and assets and deps): @@ -199,28 +188,30 @@ def generate_structure(self): _("There is nothing to print according to current settings!") ) - dep_lines = deps.mapped('line_ids') + dep_lines = deps.mapped("line_ids") if self.date: dep_lines = dep_lines.filtered(lambda dl: dl.date <= self.date) - fy_domain = [('company_id', '=', self.company_id.id)] + fy_domain = [("company_id", "=", self.company_id.id)] if self.date: - fy_domain += [('date_from', '<=', self.date)] + fy_domain += [("date_from", "<=", self.date)] # Create an ordered dict where each key is a fiscal year, sorting # them for starting date => every fiscal year must have its own # depreciation lines or previsional ones - dep_line_obj = self.env['asset.depreciation.line'] + dep_line_obj = self.env["asset.depreciation.line"] dep_lines_grouped = { - dep: OrderedDict({ - fy: dep_line_obj - for fy in self.env['account.fiscal.year'].search( - fy_domain, order='date_from asc' - ) - }) + dep: OrderedDict( + { + fy: dep_line_obj + for fy in self.env["account.fiscal.year"].search( + fy_domain, order="date_from asc" + ) + } + ) for dep in deps } - fiscal_year = self.env['account.fiscal.year'] + fiscal_year = self.env["account.fiscal.year"] for dep_line in dep_lines: dep = dep_line.depreciation_id fyear = fiscal_year.get_fiscal_year_by_date( @@ -228,28 +219,34 @@ def generate_structure(self): ) dep_lines_grouped[dep][fyear] += dep_line - self.write({ - 'report_category_ids': [ - (0, 0, {'category_id': c.id, 'report_id': self.id}) - for c in categories.sorted('name') - ] - }) - for report_categ in self.report_category_ids: - report_categ.write({ - 'report_asset_ids': [ - (0, 0, {'asset_id': a.id, 'report_id': self.id}) - for a in self.sort_assets(assets) - if a.category_id == report_categ.category_id + self.write( + { + "report_category_ids": [ + (0, 0, {"category_id": c.id, "report_id": self.id}) + for c in categories.sorted("name") ] - }) + } + ) + for report_categ in self.report_category_ids: + report_categ.write( + { + "report_asset_ids": [ + (0, 0, {"asset_id": a.id, "report_id": self.id}) + for a in self.sort_assets(assets) + if a.category_id == report_categ.category_id + ] + } + ) for report_asset in self.report_asset_ids: - report_asset.write({ - 'report_depreciation_ids': [ - (0, 0, {'depreciation_id': d.id, 'report_id': self.id}) - for d in deps - if d.asset_id == report_asset.asset_id - ] - }) + report_asset.write( + { + "report_depreciation_ids": [ + (0, 0, {"depreciation_id": d.id, "report_id": self.id}) + for d in deps + if d.asset_id == report_asset.asset_id + ] + } + ) for report_dep in self.report_depreciation_ids: sequence = 0 for dep, lines_by_fyear in dep_lines_grouped.items(): @@ -257,66 +254,77 @@ def generate_structure(self): for fyear, lines in lines_by_fyear.items(): if fyear.date_to >= dep.date_start: prev = not lines or not any( - l.move_type == 'depreciated' - and not l.partial_dismissal + l.move_type == "depreciated" and not l.partial_dismissal for l in lines ) sequence += 1 line_ids = lines.ids - report_dep.write({ - 'report_depreciation_year_line_ids': [ - (0, 0, {'dep_line_ids': [(6, 0, line_ids)], - 'fiscal_year_id': fyear.id, - 'needs_previsional': prev, - 'report_id': self.id, - 'sequence': sequence}) - ] - }) + report_dep.write( + { + "report_depreciation_year_line_ids": [ + ( + 0, + 0, + { + "dep_line_ids": [(6, 0, line_ids)], + "fiscal_year_id": fyear.id, + "needs_previsional": prev, + "report_id": self.id, + "sequence": sequence, + }, + ) + ] + } + ) def generate_totals(self): curr = self.company_id.currency_id - categ_totals = self.report_category_ids.mapped('report_total_ids') - fnames = self.env['report_asset_previsional_totals']._total_fnames + categ_totals = self.report_category_ids.mapped("report_total_ids") + fnames = self.env["report_asset_previsional_totals"]._total_fnames totals_by_dep_type = { - t: {fname: 0 for fname in fnames} - for t in categ_totals.mapped('type_id') + t: {fname: 0 for fname in fnames} for t in categ_totals.mapped("type_id") } for total in categ_totals: total_curr = total.get_currency() total_type = total.type_id for fname in fnames: - totals_by_dep_type[total_type][fname] += \ - total_curr.compute(total[fname], curr) - self.write({ - 'report_total_ids': [ - (0, 0, dict( - v, - name=_("General Total"), - type_name=t.name_get()[0][-1], - type_id=t.id - )) - for t, v in totals_by_dep_type.items() - ] - }) + totals_by_dep_type[total_type][fname] += total_curr.compute( + total[fname], curr + ) + self.write( + { + "report_total_ids": [ + ( + 0, + 0, + dict( + v, + name=_("General Total"), + type_name=t.name_get()[0][-1], + type_id=t.id, + ), + ) + for t, v in totals_by_dep_type.items() + ] + } + ) def get_assets(self): domain = [] if self.asset_ids: - domain += [('id', 'in', self.asset_ids.ids)] + domain += [("id", "in", self.asset_ids.ids)] if self.category_ids: - domain += [('category_id', 'in', self.category_ids.ids)] + domain += [("category_id", "in", self.category_ids.ids)] if self.company_id: - domain += [('company_id', '=', self.company_id.id)] + domain += [("company_id", "=", self.company_id.id)] if self.date: - domain += [('purchase_date', '<=', self.date)] - return self.env['asset.asset'].search(domain) + domain += [("purchase_date", "<=", self.date)] + return self.env["asset.asset"].search(domain) def set_report_name(self): report_name = _("Assets Previsional Depreciations ") if self.date: - report_name += _("to date {}").format( - format_date(self, 'date', '%d-%m-%Y') - ) + report_name += _("to date {}").format(format_date(self, "date", "%d-%m-%Y")) self.report_name = report_name.strip() def sort_assets(self, assets): @@ -325,35 +333,30 @@ def sort_assets(self, assets): # If the given sortable_assets = assets.filtered(self.asset_order_fname) unsortable_assets = assets - sortable_assets - sorted_assets = sortable_assets.sorted(self.asset_order_fname) \ - + unsortable_assets.sorted() + sorted_assets = ( + sortable_assets.sorted(self.asset_order_fname) + unsortable_assets.sorted() + ) return sorted_assets class ReportCategory(models.TransientModel): - _name = 'report_asset_previsional_category' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_previsional_category" + _inherit = "account_financial_report_abstract" # Data fields - category_id = fields.Many2one( - 'asset.category', - ondelete='cascade', - required=True - ) + category_id = fields.Many2one("asset.category", ondelete="cascade", required=True) # Report structure fields report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) report_asset_ids = fields.One2many( - 'report_asset_previsional_asset', - 'report_category_id' + "report_asset_previsional_asset", "report_category_id" ) report_total_ids = fields.One2many( - 'report_asset_previsional_totals', - 'report_category_id' + "report_asset_previsional_totals", "report_category_id" ) # Fields to be printed @@ -365,93 +368,93 @@ def generate_data(self): def get_report_categ_data(self): self.ensure_one() - return {'category_name': self.category_id.name} + return {"category_name": self.category_id.name} def generate_totals(self): for categ in self: curr = categ.report_id.company_id.currency_id report_date = categ.report_id.date - report_deps = categ.report_asset_ids\ - .mapped('report_depreciation_ids') - fnames = categ.env['report_asset_previsional_totals']._total_fnames + report_deps = categ.report_asset_ids.mapped("report_depreciation_ids") + fnames = categ.env["report_asset_previsional_totals"]._total_fnames totals_by_dep_type = { t: {fname: 0 for fname in fnames} - for t in report_deps.mapped('depreciation_id.type_id') + for t in report_deps.mapped("depreciation_id.type_id") } - for report_dep in report_deps.filtered( - 'report_depreciation_year_line_ids' - ): + for report_dep in report_deps.filtered("report_depreciation_year_line_ids"): dep_type = report_dep.depreciation_id.type_id last_line = report_dep.report_depreciation_year_line_ids[-1] line_curr = last_line.get_currency() fy_start = last_line.fiscal_year_id.date_from fy_end = last_line.fiscal_year_id.date_to for fname in fnames: - if fname == 'amount_depreciation_fund_prev_year': + if fname == "amount_depreciation_fund_prev_year": if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) elif fname in ( - 'amount_in_total', - 'amount_out_total', - 'gain_loss_total' + "amount_in_total", + "amount_out_total", + "gain_loss_total", ): if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) elif report_date < fy_start: totals_by_dep_type[dep_type][fname] = 0 - elif fname == 'amount_depreciated': + elif fname == "amount_depreciated": if fy_start <= report_date <= fy_end: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) else: - totals_by_dep_type[dep_type][fname] += \ - line_curr.compute(last_line[fname], curr) - categ.write({ - 'report_total_ids': [ - (0, 0, dict( - v, - name=categ.category_id.name_get()[0][-1], - type_name=t.name_get()[0][-1], - type_id=t.id - )) - for t, v in totals_by_dep_type.items() - ] - }) + totals_by_dep_type[dep_type][fname] += line_curr.compute( + last_line[fname], curr + ) + categ.write( + { + "report_total_ids": [ + ( + 0, + 0, + dict( + v, + name=categ.category_id.name_get()[0][-1], + type_name=t.name_get()[0][-1], + type_id=t.id, + ), + ) + for t, v in totals_by_dep_type.items() + ] + } + ) class ReportAsset(models.TransientModel): - _name = 'report_asset_previsional_asset' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_previsional_asset" + _inherit = "account_financial_report_abstract" # Data fields - asset_id = fields.Many2one( - 'asset.asset', - ondelete='cascade', - required=True - ) + asset_id = fields.Many2one("asset.asset", ondelete="cascade", required=True) # Report structure fields report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) - report_category_id = fields.Many2one( - 'report_asset_previsional_category' - ) + report_category_id = fields.Many2one("report_asset_previsional_category") report_depreciation_ids = fields.One2many( - 'report_asset_previsional_depreciation', - 'report_asset_id' + "report_asset_previsional_depreciation", "report_asset_id" ) report_purchase_doc_id = fields.Many2one( - 'report_asset_previsional_accounting_doc', + "report_asset_previsional_accounting_doc", ) report_sale_doc_id = fields.Many2one( - 'report_asset_previsional_accounting_doc', + "report_asset_previsional_accounting_doc", ) # Fields to be printed @@ -477,70 +480,80 @@ def get_currency(self): def get_report_asset_data(self): self.ensure_one() asset = self.asset_id - states_dict = dict(asset._fields['state'].selection) + states_dict = dict(asset._fields["state"].selection) vals = { - 'asset_code': asset.code or "/", - 'asset_name': asset.name, - 'asset_purchase_amount': asset.purchase_amount, - 'asset_state': states_dict.get(asset.state) or _("Unknown"), - 'asset_used': _("Used") if asset.used else _("New"), + "asset_code": asset.code or "/", + "asset_name": asset.name, + "asset_purchase_amount": asset.purchase_amount, + "asset_state": states_dict.get(asset.state) or _("Unknown"), + "asset_used": _("Used") if asset.used else _("New"), } - acc_doc = self.env['report_asset_previsional_accounting_doc'] + acc_doc = self.env["report_asset_previsional_accounting_doc"] purchase_vals = self.get_purchase_vals() if purchase_vals: - vals.update({ - 'report_purchase_doc_id': acc_doc.create(purchase_vals).id, - }) + vals.update( + { + "report_purchase_doc_id": acc_doc.create(purchase_vals).id, + } + ) sale_vals = self.get_sale_vals() if sale_vals: - vals.update({ - 'report_sale_doc_id': acc_doc.create(sale_vals).id, - }) + vals.update( + { + "report_sale_doc_id": acc_doc.create(sale_vals).id, + } + ) return vals def get_purchase_vals(self): asset = self.asset_id purchase_vals = { - 'partner_name': asset.supplier_id.name or "/", - 'partner_vat': asset.supplier_id.vat or "/", + "partner_name": asset.supplier_id.name or "/", + "partner_vat": asset.supplier_id.vat or "/", } if asset.purchase_date: - purchase_vals['document_date'] = format_date( - asset, 'purchase_date', '%d-%m-%Y' + purchase_vals["document_date"] = format_date( + asset, "purchase_date", "%d-%m-%Y" ) if asset.supplier_ref: - purchase_vals['partner_ref'] = asset.supplier_ref + purchase_vals["partner_ref"] = asset.supplier_ref elif asset.purchase_invoice_id.reference: - purchase_vals['partner_ref'] = asset.purchase_invoice_id.reference + purchase_vals["partner_ref"] = asset.purchase_invoice_id.reference elif asset.purchase_move_id.ref: - purchase_vals['partner_ref'] = asset.purchase_move_id.ref + purchase_vals["partner_ref"] = asset.purchase_move_id.ref else: - purchase_vals['partner_ref'] = "/" + purchase_vals["partner_ref"] = "/" if asset.purchase_invoice_id: - purchase_vals.update({ - 'document_nr': asset.purchase_invoice_id.number or "/", - 'res_id': asset.purchase_invoice_id.id, - 'res_model': 'account.invoice', - }) + purchase_vals.update( + { + "document_nr": asset.purchase_invoice_id.number or "/", + "res_id": asset.purchase_invoice_id.id, + "res_model": "account.invoice", + } + ) elif asset.purchase_move_id: - purchase_vals.update({ - 'document_nr': asset.purchase_move_id.name or "/", - 'res_id': asset.purchase_move_id.id, - 'res_model': 'account.move', - }) + purchase_vals.update( + { + "document_nr": asset.purchase_move_id.name or "/", + "res_id": asset.purchase_move_id.id, + "res_model": "account.move", + } + ) else: - purchase_vals.update({ - 'document_nr': "/", - 'res_id': asset.id, - 'res_model': 'asset.asset', - }) + purchase_vals.update( + { + "document_nr": "/", + "res_id": asset.id, + "res_model": "asset.asset", + } + ) return purchase_vals @@ -550,56 +563,57 @@ def get_sale_vals(self): return {} sale_vals = { - 'document_date': format_date(asset, 'sale_date', '%d-%m-%Y'), - 'partner_name': asset.customer_id.name, - 'partner_vat': asset.customer_id.vat or "/", + "document_date": format_date(asset, "sale_date", "%d-%m-%Y"), + "partner_name": asset.customer_id.name, + "partner_vat": asset.customer_id.vat or "/", } if asset.sale_invoice_id: - sale_vals.update({ - 'document_nr': asset.sale_invoice_id.number or "/", - 'res_id': asset.sale_invoice_id.id, - 'res_model': 'account.invoice', - }) + sale_vals.update( + { + "document_nr": asset.sale_invoice_id.number or "/", + "res_id": asset.sale_invoice_id.id, + "res_model": "account.invoice", + } + ) elif asset.sale_move_id: - sale_vals.update({ - 'document_nr': asset.sale_move_id.name or "/", - 'res_id': asset.sale_move_id.id, - 'res_model': 'account.move', - }) + sale_vals.update( + { + "document_nr": asset.sale_move_id.name or "/", + "res_id": asset.sale_move_id.id, + "res_model": "account.move", + } + ) else: - sale_vals.update({ - 'document_nr': "/", - 'res_id': asset.id, - 'res_model': 'asset.asset', - }) + sale_vals.update( + { + "document_nr": "/", + "res_id": asset.id, + "res_model": "asset.asset", + } + ) return sale_vals class ReportDepreciation(models.TransientModel): - _name = 'report_asset_previsional_depreciation' - _inherit = 'account_financial_report_abstract' - _order = 'type_name asc' + _name = "report_asset_previsional_depreciation" + _inherit = "account_financial_report_abstract" + _order = "type_name asc" # Data fields depreciation_id = fields.Many2one( - 'asset.depreciation', - ondelete='cascade', - required=True + "asset.depreciation", ondelete="cascade", required=True ) # Report structure fields report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) - report_asset_id = fields.Many2one( - 'report_asset_previsional_asset' - ) + report_asset_id = fields.Many2one("report_asset_previsional_asset") report_depreciation_year_line_ids = fields.One2many( - 'report_asset_previsional_depreciation_line_year', - 'report_depreciation_id' + "report_asset_previsional_depreciation_line_year", "report_depreciation_id" ) # Fields to be printed @@ -627,45 +641,40 @@ def get_report_dep_data(self): self.ensure_one() dep = self.depreciation_id if dep.pro_rata_temporis: - dep_pro_rata_temporis = u"\u2612" # checked ballot box -> ☒ + dep_pro_rata_temporis = "\u2612" # checked ballot box -> ☒ else: - dep_pro_rata_temporis = u"\u2610" # empty ballot box -> ☐ + dep_pro_rata_temporis = "\u2610" # empty ballot box -> ☐ return { - 'dep_amount_depreciable': dep.amount_depreciable, - 'dep_date_start': format_date(dep, 'date_start', '%d-%m-%Y'), - 'dep_percentage': dep.percentage, - 'dep_pro_rata_temporis': dep_pro_rata_temporis, - 'mode_name': dep.mode_id.name_get()[0][-1] if dep.mode_id else "", - 'type_name': dep.type_id.name_get()[0][-1] if dep.type_id else "" + "dep_amount_depreciable": dep.amount_depreciable, + "dep_date_start": format_date(dep, "date_start", "%d-%m-%Y"), + "dep_percentage": dep.percentage, + "dep_pro_rata_temporis": dep_pro_rata_temporis, + "mode_name": dep.mode_id.name_get()[0][-1] if dep.mode_id else "", + "type_name": dep.type_id.name_get()[0][-1] if dep.type_id else "", } class ReportDepreciationLineByYear(models.TransientModel): - _name = 'report_asset_previsional_depreciation_line_year' - _inherit = 'account_financial_report_abstract' - _order = 'sequence asc' + _name = "report_asset_previsional_depreciation_line_year" + _inherit = "account_financial_report_abstract" + _order = "sequence asc" # Data fields dep_line_ids = fields.Many2many( - 'asset.depreciation.line', - relation='report_previsional_line_year_dep_line' + "asset.depreciation.line", relation="report_previsional_line_year_dep_line" ) - fiscal_year_id = fields.Many2one( - 'account.fiscal.year' - ) + fiscal_year_id = fields.Many2one("account.fiscal.year") # Report structure fields hidden = fields.Boolean() report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) - report_depreciation_id = fields.Many2one( - 'report_asset_previsional_depreciation' - ) + report_depreciation_id = fields.Many2one("report_asset_previsional_depreciation") sequence = fields.Integer() @@ -701,14 +710,17 @@ def clean_unused(self): def do_clean(self): self.ensure_one() - digits = self.env['decimal.precision'].precision_get('Account') - if not self.dep_line_ids \ - and float_is_zero(self.amount_residual, digits) \ - and self.sequence > 1: - previous_line = self.report_depreciation_id \ - .report_depreciation_year_line_ids.filtered( + digits = self.env["decimal.precision"].precision_get("Account") + if ( + not self.dep_line_ids + and float_is_zero(self.amount_residual, digits) + and self.sequence > 1 + ): + previous_line = ( + self.report_depreciation_id.report_depreciation_year_line_ids.filtered( lambda l: l.sequence == self.sequence - 1 ) + ) if float_is_zero(previous_line.amount_residual, digits): return True return False @@ -730,7 +742,7 @@ def get_currency(self): def generate_previsional_lines(self): lines_grouped = dict() - for line in self.filtered('needs_previsional'): + for line in self.filtered("needs_previsional"): dep = line.report_depreciation_id.depreciation_id if dep not in lines_grouped: lines_grouped[dep] = line @@ -759,32 +771,34 @@ def get_report_dep_line_year_data(self): grouped_amounts = self.dep_line_ids.get_balances_grouped() amount_depreciable = report_dep.dep_amount_depreciable - amount_gain = grouped_amounts.get('gain') or 0.0 + amount_gain = grouped_amounts.get("gain") or 0.0 amount_gain_total = amount_gain - amount_historical = abs(grouped_amounts.get('historical') or 0.0) - amount_in = abs(grouped_amounts.get('in') or 0.0) + amount_historical = abs(grouped_amounts.get("historical") or 0.0) + amount_in = abs(grouped_amounts.get("in") or 0.0) amount_in_total = amount_in - amount_loss = grouped_amounts.get('loss') or 0.0 + amount_loss = grouped_amounts.get("loss") or 0.0 amount_loss_total = amount_loss - amount_out = abs(grouped_amounts.get('out') or 0.0) + amount_out = abs(grouped_amounts.get("out") or 0.0) amount_out_total = amount_out gain_loss = amount_gain + amount_loss gain_loss_total = gain_loss - amount_depreciated = sum([ - line.amount - for line in self.dep_line_ids.filtered( - lambda l: l.move_type == 'depreciated' - and not l.partial_dismissal - ) - ]) - amount_dismissal = sum([ - line.amount - for line in self.dep_line_ids.filtered( - lambda l: l.move_type == 'depreciated' - and l.partial_dismissal - ) - ]) + amount_depreciated = sum( + [ + line.amount + for line in self.dep_line_ids.filtered( + lambda l: l.move_type == "depreciated" and not l.partial_dismissal + ) + ] + ) + amount_dismissal = sum( + [ + line.amount + for line in self.dep_line_ids.filtered( + lambda l: l.move_type == "depreciated" and l.partial_dismissal + ) + ] + ) prev_year_line = report_dep.report_depreciation_year_line_ids.filtered( lambda l: l.sequence == self.sequence - 1 @@ -792,46 +806,52 @@ def get_report_dep_line_year_data(self): asset = self.report_depreciation_id.report_asset_id.asset_id fy_start = self.fiscal_year_id.date_from fy_end = self.fiscal_year_id.date_to - if asset.sold and asset.sale_date \ - and fy_start <= asset.sale_date <= fy_end: + if asset.sold and asset.sale_date and fy_start <= asset.sale_date <= fy_end: amount_depreciable_upd = 0.0 depreciation_fund_curr_year = 0.0 amount_residual = 0.0 if prev_year_line: - depreciation_fund_prev_year = prev_year_line\ - .amount_depreciation_fund_curr_year + depreciation_fund_prev_year = ( + prev_year_line.amount_depreciation_fund_curr_year + ) amount_in_total += prev_year_line.amount_in_total amount_out_total += prev_year_line.amount_out_total else: depreciation_fund_prev_year = 0.0 else: if prev_year_line: - depreciation_fund_prev_year = prev_year_line\ - .amount_depreciation_fund_curr_year + depreciation_fund_prev_year = ( + prev_year_line.amount_depreciation_fund_curr_year + ) prev_year_resid = prev_year_line.amount_residual - amount_depreciable_upd = prev_year_line.\ - amount_depreciable_updated + amount_in - amount_out + amount_depreciable_upd = ( + prev_year_line.amount_depreciable_updated + amount_in - amount_out + ) amount_in_total += prev_year_line.amount_in_total amount_out_total += prev_year_line.amount_out_total else: depreciation_fund_prev_year = 0.0 prev_year_resid = amount_depreciable - amount_depreciable_upd = amount_depreciable + amount_in \ - - amount_out + amount_depreciable_upd = amount_depreciable + amount_in - amount_out - depreciation_fund_curr_year = depreciation_fund_prev_year \ - + amount_depreciated + amount_dismissal - amount_residual = prev_year_resid + amount_in - amount_out \ - - amount_depreciated - amount_dismissal + depreciation_fund_curr_year = ( + depreciation_fund_prev_year + amount_depreciated + amount_dismissal + ) + amount_residual = ( + prev_year_resid + + amount_in + - amount_out + - amount_depreciated + - amount_dismissal + ) if prev_year_line: amount_gain_total += prev_year_line.amount_gain_total amount_loss_total += prev_year_line.amount_loss_total gain_loss_total += prev_year_line.gain_loss_total - type_mapping = {'in': {}, 'out': {}} + type_mapping = {"in": {}, "out": {}} for dep_line in self.dep_line_ids.filtered( - lambda l: l.move_type in ('in', 'out') - and l.depreciation_line_type_id + lambda l: l.move_type in ("in", "out") and l.depreciation_line_type_id ): dep_type = dep_line.depreciation_line_type_id if dep_type not in type_mapping[dep_line.move_type]: @@ -840,19 +860,21 @@ def get_report_dep_line_year_data(self): amount_in_detail = amount_out_detail = "" has_amount_detail = False - if type_mapping['in']: - amount_in_detail = "; ".join([ - "{}: {}".format(dep_type.name, self.format_amount(amount)) - for dep_type, amount in sorted(list( - type_mapping['in'].items())) - ]) + if type_mapping["in"]: + amount_in_detail = "; ".join( + [ + "{}: {}".format(dep_type.name, self.format_amount(amount)) + for dep_type, amount in sorted(list(type_mapping["in"].items())) + ] + ) has_amount_detail = True - if type_mapping['out']: - amount_out_detail = "; ".join([ - "{}: {}".format(dep_type.name, self.format_amount(amount)) - for dep_type, amount in sorted(list( - type_mapping['out'].items())) - ]) + if type_mapping["out"]: + amount_out_detail = "; ".join( + [ + "{}: {}".format(dep_type.name, self.format_amount(amount)) + for dep_type, amount in sorted(list(type_mapping["out"].items())) + ] + ) has_amount_detail = True start = fields.Date.from_string(self.fiscal_year_id.date_from).year @@ -863,39 +885,39 @@ def get_report_dep_line_year_data(self): year = "{} - {}".format(start, end) return { - 'amount_depreciable': amount_depreciable, - 'amount_depreciable_updated': amount_depreciable_upd, - 'amount_depreciated': amount_depreciated, - 'amount_depreciation_fund_curr_year': depreciation_fund_curr_year, - 'amount_depreciation_fund_prev_year': depreciation_fund_prev_year, - 'amount_gain': amount_gain, - 'amount_historical': amount_historical, - 'amount_in': amount_in, - 'amount_in_detail': amount_in_detail, - 'amount_in_total': amount_in_total, - 'amount_loss': amount_loss, - 'amount_out': amount_out, - 'amount_out_detail': amount_out_detail, - 'amount_out_total': amount_out_total, - 'amount_residual': amount_residual, - 'date_start': report_dep.dep_date_start, - 'gain_loss': gain_loss, - 'gain_loss_total': gain_loss_total, - 'has_amount_detail': has_amount_detail, - 'percentage': report_dep.dep_percentage, - 'type_name': report_dep.type_name, - 'year': year, + "amount_depreciable": amount_depreciable, + "amount_depreciable_updated": amount_depreciable_upd, + "amount_depreciated": amount_depreciated, + "amount_depreciation_fund_curr_year": depreciation_fund_curr_year, + "amount_depreciation_fund_prev_year": depreciation_fund_prev_year, + "amount_gain": amount_gain, + "amount_historical": amount_historical, + "amount_in": amount_in, + "amount_in_detail": amount_in_detail, + "amount_in_total": amount_in_total, + "amount_loss": amount_loss, + "amount_out": amount_out, + "amount_out_detail": amount_out_detail, + "amount_out_total": amount_out_total, + "amount_residual": amount_residual, + "date_start": report_dep.dep_date_start, + "gain_loss": gain_loss, + "gain_loss_total": gain_loss_total, + "has_amount_detail": has_amount_detail, + "percentage": report_dep.dep_percentage, + "type_name": report_dep.type_name, + "year": year, } class ReportAccountingDoc(models.TransientModel): - _name = 'report_asset_previsional_accounting_doc' - _inherit = 'account_financial_report_abstract' - _order = 'sequence asc' + _name = "report_asset_previsional_accounting_doc" + _inherit = "account_financial_report_abstract" + _order = "sequence asc" # Report structure fields report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) # Fields to be printed @@ -910,34 +932,32 @@ class ReportAccountingDoc(models.TransientModel): class ReportTotals(models.TransientModel): - _name = 'report_asset_previsional_totals' - _inherit = 'account_financial_report_abstract' + _name = "report_asset_previsional_totals" + _inherit = "account_financial_report_abstract" _total_fnames = [ - 'amount_depreciable_updated', - 'amount_depreciated', - 'amount_depreciation_fund_curr_year', - 'amount_depreciation_fund_prev_year', - 'amount_gain', - 'amount_in_total', - 'amount_loss', - 'amount_out_total', - 'amount_residual', - 'gain_loss_total', + "amount_depreciable_updated", + "amount_depreciated", + "amount_depreciation_fund_curr_year", + "amount_depreciation_fund_prev_year", + "amount_gain", + "amount_in_total", + "amount_loss", + "amount_out_total", + "amount_residual", + "gain_loss_total", ] # Data fields type_id = fields.Many2one( - 'asset.depreciation.type', + "asset.depreciation.type", ) # Report structure fields report_id = fields.Many2one( - 'report_asset_previsional', + "report_asset_previsional", ) - report_category_id = fields.Many2one( - 'report_asset_previsional_category' - ) + report_category_id = fields.Many2one("report_asset_previsional_category") # Fields to be printed amount_depreciable_updated = fields.Float() diff --git a/assets_management/report/asset_previsional_xlsx.py b/assets_management/report/asset_previsional_xlsx.py index 8310de281fd0..b8172509fd4e 100644 --- a/assets_management/report/asset_previsional_xlsx.py +++ b/assets_management/report/asset_previsional_xlsx.py @@ -8,11 +8,11 @@ class AssetJournalXslx(models.AbstractModel): - _name = 'report.assets_management.report_asset_previsional_xlsx' - _inherit = 'report.account_financial_report.abstract_report_xlsx' + _name = "report.assets_management.report_asset_previsional_xlsx" + _inherit = "report.account_financial_report.abstract_report_xlsx" def __init__(self, pool, cr): - """ Adds new attributes """ + """Adds new attributes""" super().__init__(pool, cr) # Add report objects @@ -51,7 +51,7 @@ def __init__(self, pool, cr): self.format_title = None def generate_xlsx_report(self, workbook, data, objects): - """ Set wb, data and report attributes """ + """Set wb, data and report attributes""" self.workbook = workbook self.data = data self.report = objects @@ -60,66 +60,82 @@ def generate_xlsx_report(self, workbook, data, objects): super().generate_xlsx_report(workbook, data, objects) def set_formats(self): - """ Defines custom formats """ + """Defines custom formats""" # 1- Category formats - self.format_category_name = self.workbook.add_format({ - 'align': 'center', - 'bg_color': '#337AB7', - 'bold': True, - 'font_color': '#FFFFFF', - 'font_size': 16, - }) + self.format_category_name = self.workbook.add_format( + { + "align": "center", + "bg_color": "#337AB7", + "bold": True, + "font_color": "#FFFFFF", + "font_size": 16, + } + ) # 2- Asset formats - self.format_asset_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_color': '#337AB7', - 'font_size': 14, - }) - self.format_asset_value = self.workbook.add_format({ - 'align': 'center', - 'font_color': '#337AB7', - 'font_size': 14, - }) + self.format_asset_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_color": "#337AB7", + "font_size": 14, + } + ) + self.format_asset_value = self.workbook.add_format( + { + "align": "center", + "font_color": "#337AB7", + "font_size": 14, + } + ) # 3- Depreciations formats - self.format_depreciation_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_size': 12, - }) - self.format_depreciation_value = self.workbook.add_format({ - 'align': 'center', - 'font_size': 12, - }) + self.format_depreciation_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_size": 12, + } + ) + self.format_depreciation_value = self.workbook.add_format( + { + "align": "center", + "font_size": 12, + } + ) # 4- Depreciation yearly and amount details formats - self.format_depreciation_year_line_header = self.workbook.add_format({ - 'align': 'center', - 'bold': True, - 'font_size': 12, - }) - self.format_depreciation_year_line_value_center = self.workbook \ - .add_format({ - 'align': 'center', - 'font_size': 12, - }) - self.format_depreciation_year_line_value_right = self.workbook \ - .add_format({ - 'align': 'right', - 'font_size': 12, - }) + self.format_depreciation_year_line_header = self.workbook.add_format( + { + "align": "center", + "bold": True, + "font_size": 12, + } + ) + self.format_depreciation_year_line_value_center = self.workbook.add_format( + { + "align": "center", + "font_size": 12, + } + ) + self.format_depreciation_year_line_value_right = self.workbook.add_format( + { + "align": "right", + "font_size": 12, + } + ) # 5- Report title - self.format_title = self.workbook.add_format({ - 'align': 'center', - 'bg_color': '#337AB7', - 'bold': True, - 'font_color': 'white', - 'font_size': 20, - }) + self.format_title = self.workbook.add_format( + { + "align": "center", + "bg_color": "#337AB7", + "bold": True, + "font_color": "white", + "font_size": 20, + } + ) def set_report_data(self): self.set_category_data() @@ -135,10 +151,12 @@ def set_category_data(self): def generate_category_data(self): data = ( - {'title': _("Category"), - 'field': 'category_name', - 'tstyle': self.format_category_name, - 'vstyle': self.format_category_name}, + { + "title": _("Category"), + "field": "category_name", + "tstyle": self.format_category_name, + "vstyle": self.format_category_name, + }, ) return dict(enumerate(data)) @@ -147,56 +165,75 @@ def set_asset_data(self): def generate_asset_data(self): data = ( - {'title': _("Asset"), - 'field': 'asset_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Code"), - 'field': 'asset_code', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Purchase Amount"), - 'field': 'asset_purchase_amount', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Purchased as New / Used"), - 'field': 'asset_used', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Status"), - 'field': 'asset_state', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Asset"), + "field": "asset_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Code"), + "field": "asset_code", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Purchase Amount"), + "field": "asset_purchase_amount", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Purchased as New / Used"), + "field": "asset_used", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Status"), + "field": "asset_state", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return dict(enumerate(data)) def set_asset_accounting_doc_data(self): - self.asset_accounting_doc_data = \ - self.generate_asset_accounting_doc_data() + self.asset_accounting_doc_data = self.generate_asset_accounting_doc_data() def generate_asset_accounting_doc_data(self): data = ( - {'title': _("Partner"), - 'field': 'partner_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("VAT"), - 'field': 'partner_vat', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Document Nr"), - 'field': 'document_nr', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Document Date"), - 'field': 'document_date', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Supplier Ref"), - 'field': 'partner_ref', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Partner"), + "field": "partner_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("VAT"), + "field": "partner_vat", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Document Nr"), + "field": "document_nr", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Document Date"), + "field": "document_date", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Supplier Ref"), + "field": "partner_ref", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return {n + 1: d for n, d in enumerate(data)} @@ -205,101 +242,135 @@ def set_depreciation_data(self): def generate_depreciation_data(self): data = ( - {'title': _("Depreciation Type"), - 'field': 'type_name', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Depreciation Mode"), - 'field': 'mode_name', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Depreciable Amount"), - 'field': 'dep_amount_depreciable', - 'type': 'amount', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Starting From"), - 'field': 'dep_date_start', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Dep. Percentage (%)"), - 'field': 'dep_percentage', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, - {'title': _("Pro Rata Temporis"), - 'field': 'dep_pro_rata_temporis', - 'tstyle': self.format_depreciation_header, - 'vstyle': self.format_depreciation_value}, + { + "title": _("Depreciation Type"), + "field": "type_name", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Depreciation Mode"), + "field": "mode_name", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Depreciable Amount"), + "field": "dep_amount_depreciable", + "type": "amount", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Starting From"), + "field": "dep_date_start", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Dep. Percentage (%)"), + "field": "dep_percentage", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, + { + "title": _("Pro Rata Temporis"), + "field": "dep_pro_rata_temporis", + "tstyle": self.format_depreciation_header, + "vstyle": self.format_depreciation_value, + }, ) return {n + 1: d for n, d in enumerate(data)} def set_depreciation_line_year_data(self): - self.depreciation_line_year_data = \ - self.generate_depreciation_line_year_data() + self.depreciation_line_year_data = self.generate_depreciation_line_year_data() def generate_depreciation_line_year_data(self): data = ( - {'title': _("Year"), - 'field': 'year', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Amount"), - 'field': 'amount_depreciable_updated', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("In Amount"), - 'field': 'amount_in', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Out Amount"), - 'field': 'amount_out', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Prev. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_prev_year', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Depreciation"), - 'field': 'amount_depreciated', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Curr. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_curr_year', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Gain / Loss"), - 'field': 'gain_loss', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, - {'title': _("Residual"), - 'field': 'amount_residual', - 'type': 'amount', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_right}, + { + "title": _("Year"), + "field": "year", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Amount"), + "field": "amount_depreciable_updated", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("In Amount"), + "field": "amount_in", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Out Amount"), + "field": "amount_out", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Prev. Year Dep. Fund"), + "field": "amount_depreciation_fund_prev_year", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Depreciation"), + "field": "amount_depreciated", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Curr. Year Dep. Fund"), + "field": "amount_depreciation_fund_curr_year", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Gain / Loss"), + "field": "gain_loss", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, + { + "title": _("Residual"), + "field": "amount_residual", + "type": "amount", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_right, + }, ) return {n + 1: d for n, d in enumerate(data)} def set_depreciation_line_amount_detail_data(self): - self.depreciation_line_amount_detail_data = \ + self.depreciation_line_amount_detail_data = ( self.generate_depreciation_line_amount_detail_data() + ) def generate_depreciation_line_amount_detail_data(self): data = ( - {'title': _("In Amount - Detail"), - 'field': 'amount_in_detail', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, - {'title': _("Out Amount - Detail"), - 'field': 'amount_out_detail', - 'tstyle': self.format_depreciation_year_line_header, - 'vstyle': self.format_depreciation_year_line_value_center}, + { + "title": _("In Amount - Detail"), + "field": "amount_in_detail", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, + { + "title": _("Out Amount - Detail"), + "field": "amount_out_detail", + "tstyle": self.format_depreciation_year_line_header, + "vstyle": self.format_depreciation_year_line_value_center, + }, ) return {n + 3: d for n, d in enumerate(data)} @@ -308,95 +379,120 @@ def set_totals_data(self): def get_totals_data(self): data = ( - {'title': _("Total"), - 'field': 'name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Type"), - 'field': 'type_name', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Amount"), - 'field': 'amount_depreciable_updated', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("In Amount"), - 'field': 'amount_in_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Out Amount"), - 'field': 'amount_out_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Prev. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_prev_year', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Depreciation"), - 'field': 'amount_depreciated', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Curr. Year Dep. Fund"), - 'field': 'amount_depreciation_fund_curr_year', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Gain / Loss"), - 'field': 'gain_loss_total', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, - {'title': _("Residual"), - 'field': 'amount_residual', - 'type': 'amount', - 'tstyle': self.format_asset_header, - 'vstyle': self.format_asset_value}, + { + "title": _("Total"), + "field": "name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Type"), + "field": "type_name", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Amount"), + "field": "amount_depreciable_updated", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("In Amount"), + "field": "amount_in_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Out Amount"), + "field": "amount_out_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Prev. Year Dep. Fund"), + "field": "amount_depreciation_fund_prev_year", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Depreciation"), + "field": "amount_depreciated", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Curr. Year Dep. Fund"), + "field": "amount_depreciation_fund_curr_year", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Gain / Loss"), + "field": "gain_loss_total", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, + { + "title": _("Residual"), + "field": "amount_residual", + "type": "amount", + "tstyle": self.format_asset_header, + "vstyle": self.format_asset_value, + }, ) return {n: d for n, d in enumerate(data)} def _set_column_width(self): - """ Override to force every column to width 25 at least """ + """Override to force every column to width 25 at least""" max_width = self.get_max_width_dict() for col, width in max_width.items(): self.sheet.set_column(col, col, max(width, 25)) def get_max_width_dict(self): - min_col = min([ - min(self.category_data.keys()), - min(self.asset_data.keys()), - min(self.asset_accounting_doc_data.keys()), - min(self.depreciation_data.keys()), - min(self.depreciation_line_year_data.keys()), - min(self.depreciation_line_amount_detail_data.keys()), - min(self.totals_data.keys()), - ]) - max_col = max([ - max(self.category_data.keys()), - max(self.asset_data.keys()), - max(self.asset_accounting_doc_data.keys()), - max(self.depreciation_data.keys()), - max(self.depreciation_line_year_data.keys()), - max(self.depreciation_line_amount_detail_data.keys()), - max(self.totals_data.keys()), - ]) + min_col = min( + [ + min(self.category_data.keys()), + min(self.asset_data.keys()), + min(self.asset_accounting_doc_data.keys()), + min(self.depreciation_data.keys()), + min(self.depreciation_line_year_data.keys()), + min(self.depreciation_line_amount_detail_data.keys()), + min(self.totals_data.keys()), + ] + ) + max_col = max( + [ + max(self.category_data.keys()), + max(self.asset_data.keys()), + max(self.asset_accounting_doc_data.keys()), + max(self.depreciation_data.keys()), + max(self.depreciation_line_year_data.keys()), + max(self.depreciation_line_amount_detail_data.keys()), + max(self.totals_data.keys()), + ] + ) return { - col: max([ - self.category_data.get(col, {}).get('width') or 0, - self.asset_data.get(col, {}).get('width') or 0, - self.asset_accounting_doc_data.get(col, {}).get('width') or 0, - self.depreciation_data.get(col, {}).get('width') or 0, - self.depreciation_line_year_data.get(col, {}) - .get('width') or 0, - self.depreciation_line_amount_detail_data.get(col, {}) - .get('width') or 0, - self.totals_data.get(col, {}).get('width') or 0, - ]) + col: max( + [ + self.category_data.get(col, {}).get("width") or 0, + self.asset_data.get(col, {}).get("width") or 0, + self.asset_accounting_doc_data.get(col, {}).get("width") or 0, + self.depreciation_data.get(col, {}).get("width") or 0, + self.depreciation_line_year_data.get(col, {}).get("width") or 0, + self.depreciation_line_amount_detail_data.get(col, {}).get("width") + or 0, + self.totals_data.get(col, {}).get("width") or 0, + ] + ) for col in range(min_col, max_col + 1) } @@ -413,13 +509,12 @@ def _write_report_title(self, title): Writes report title on current line using all defined columns width """ self.sheet.merge_range( - self.row_pos, 0, self.row_pos, 9, - title, self.format_title + self.row_pos, 0, self.row_pos, 9, title, self.format_title ) self.row_pos += 3 def _generate_report_content(self, workbook, report): - """ Creates actual xls report """ + """Creates actual xls report""" for categ_section in report.report_category_ids: self.write_all(self.category_data, categ_section) @@ -429,7 +524,7 @@ def _generate_report_content(self, workbook, report): if asset_section.report_purchase_doc_id: self.write_all( self.asset_accounting_doc_data, - asset_section.report_purchase_doc_id + asset_section.report_purchase_doc_id, ) for dep_section in asset_section.report_depreciation_ids: @@ -437,9 +532,7 @@ def _generate_report_content(self, workbook, report): self.write_header(self.depreciation_line_year_data) for year in dep_section.report_depreciation_year_line_ids: - self.write_value( - self.depreciation_line_year_data, year - ) + self.write_value(self.depreciation_line_year_data, year) if year.has_amount_detail: self.write_value( self.depreciation_line_amount_detail_data, year @@ -447,8 +540,7 @@ def _generate_report_content(self, workbook, report): if asset_section.report_sale_doc_id: self.write_all( - self.asset_accounting_doc_data, - asset_section.report_sale_doc_id + self.asset_accounting_doc_data, asset_section.report_sale_doc_id ) self.row_pos += 1 @@ -473,17 +565,17 @@ def write_all(self, data, obj): def write_header(self, data): pos = self.row_pos for col, data in data.items(): - self.sheet.write(pos, col, data['title'], data['tstyle']) + self.sheet.write(pos, col, data["title"], data["tstyle"]) self.row_pos += 1 def write_value(self, data, obj): pos = self.row_pos for col, data in data.items(): - value, style = getattr(obj, data['field']), data['vstyle'] - if data.get('type') == 'amount': - value = getattr(obj, 'format_amount')(value) + value, style = getattr(obj, data["field"]), data["vstyle"] + if data.get("type") == "amount": + value = getattr(obj, "format_amount")(value) if value in (False, None): - value = '/' + value = "/" self.sheet.write(pos, col, value, style) self.row_pos += 1 @@ -494,21 +586,18 @@ def write_value(self, data, obj): ######################################################## def _get_report_filters(self, report): - """ Override original method even if not used to avoid errors """ + """Override original method even if not used to avoid errors""" return [] def _get_report_columns(self, report): - """ Override original method even if not used to avoid errors """ + """Override original method even if not used to avoid errors""" return {} def _get_col_count_filter_name(self): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" def _get_col_count_filter_value(self): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" def _write_filters(self, filters): - """ Override original method even if not used to avoid errors """ - pass + """Override original method even if not used to avoid errors""" diff --git a/assets_management/report/layout.xml b/assets_management/report/layout.xml index 3ac4ad1edaec..c26cd24befb6 100644 --- a/assets_management/report/layout.xml +++ b/assets_management/report/layout.xml @@ -1,53 +1,63 @@ - +