mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-25 01:32:05 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools import SQL
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
|
|
@ -16,17 +17,29 @@ class AccountAnalyticApplicability(models.Model):
|
|||
ondelete={'expense': 'cascade'},
|
||||
)
|
||||
|
||||
@api.depends('business_domain')
|
||||
def _compute_display_account_prefix(self):
|
||||
super()._compute_display_account_prefix()
|
||||
for applicability in self.filtered(lambda rec: rec.business_domain == 'expense'):
|
||||
applicability.display_account_prefix = True
|
||||
|
||||
class AnalyticAccount(models.Model):
|
||||
|
||||
class AccountAnalyticAccount(models.Model):
|
||||
_inherit = 'account.analytic.account'
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_account_in_analytic_distribution(self):
|
||||
self.env.cr.execute("""
|
||||
SELECT id FROM hr_expense
|
||||
WHERE analytic_distribution::jsonb ?| array[%s]
|
||||
LIMIT 1
|
||||
""", ([str(id) for id in self.ids],))
|
||||
self.env.cr.execute(
|
||||
SQL(
|
||||
r"""
|
||||
SELECT id FROM hr_expense
|
||||
WHERE %s && %s
|
||||
LIMIT 1
|
||||
""",
|
||||
[str(account_id) for account_id in self.ids],
|
||||
self.env['hr.expense']._query_analytic_accounts(),
|
||||
)
|
||||
)
|
||||
expense_ids = self.env.cr.fetchall()
|
||||
if expense_ids:
|
||||
raise UserError(_("You cannot delete an analytic account that is used in an expense."))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue