Steps to reproduce issue: 1. Have Sales installed 2. Enable Analytic Accounting and create two Projects 3. Go into both Project Settings and add distinct Analytic Accounts 4. Create a Vendor Bill 5. Add a Product Line and put both accounts in the Analytic Distribution 6. Add an account in another column to one of the existing Analytic Distribution Lines 7. Go to Projects and open the Project Updates of the Project whose account was alone in the Analytic Distribution Line 8. You get the error: > invalid literal for int() with base 10: '[int],[int]' Explanation: With commit odoo@dc696c8ed4850a83b6af721002a90f2944891923, the way IDs are stored changed. They are now computed in a csv string. A part of the Analytic Accounting pipeline didn't get updated after that change, making a lot of the features not working properly. Suggested fix: - We must take into account the multiple analytic plans in any order possible in the ID search. - Because the amount of `account.move.line` can increase rapidly, the new ID search must be indexable. - We reworked the counting query to avoid `account.move` being counted multiple times. opw-3626619 closes odoo/odoo#147664 Related: odoo/enterprise#54311 Signed-off-by: William André (wan) <wan@odoo.com>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# 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
|
|
|
|
|
|
class AccountAnalyticApplicability(models.Model):
|
|
_inherit = 'account.analytic.applicability'
|
|
_description = "Analytic Plan's Applicabilities"
|
|
|
|
business_domain = fields.Selection(
|
|
selection_add=[
|
|
('expense', 'Expense'),
|
|
],
|
|
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 AccountAnalyticAccount(models.Model):
|
|
_inherit = 'account.analytic.account'
|
|
|
|
@api.ondelete(at_uninstall=False)
|
|
def _unlink_except_account_in_analytic_distribution(self):
|
|
self.env.cr.execute(
|
|
SQL(
|
|
r"""
|
|
SELECT id FROM hr_expense
|
|
WHERE %s && %s
|
|
LIMIT 1
|
|
""",
|
|
[str(id) for 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."))
|