Skip to content

Commit

Permalink
[IMP] assets_management: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato authored and SirAionTech committed Jan 15, 2024
1 parent 481b865 commit f89e572
Show file tree
Hide file tree
Showing 57 changed files with 5,627 additions and 4,690 deletions.
89 changes: 44 additions & 45 deletions assets_management/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
4 changes: 2 additions & 2 deletions assets_management/data/asset_data.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="0">

<!-- Natura ammortamento -->
Expand Down Expand Up @@ -36,7 +36,7 @@
<field name="used_asset_coeff">1</field>
</record>
<record id="ad_mode_materiale_line" model="asset.depreciation.mode.line">
<field name="mode_id" ref="ad_mode_materiale"/>
<field name="mode_id" ref="ad_mode_materiale" />
<field name="from_nr">1</field>
<field name="to_nr">1</field>
<field name="coefficient">0.5</field>
Expand Down
10 changes: 5 additions & 5 deletions assets_management/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="clean_asset_accounting_info_cron" model="ir.cron">
<field name="name">Vacuum Empty Asset Accounting Info</field>
<field name="active" eval="False"/>
<field name="user_id" ref="base.user_root"/>
<field name="active" eval="False" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="True"/>
<field name="model_id" ref="model_asset_accounting_info"/>
<field name="doall" eval="True" />
<field name="model_id" ref="model_asset_accounting_info" />
<field name="state">code</field>
<field name="code">model.cron_vacuum_table()</field>
</record>
Expand Down
36 changes: 22 additions & 14 deletions assets_management/models/account_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 4 additions & 6 deletions assets_management/models/account_fiscal_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
110 changes: 55 additions & 55 deletions assets_management/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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")
Loading

0 comments on commit f89e572

Please sign in to comment.