Files
enterprise-addons/account_reports_cash_basis/models/account_move.py
T

48 lines
2.0 KiB
Python

from odoo import fields, models
from odoo.tools import SQL
class AccountMove(models.Model):
_inherit = "account.move"
impacting_cash_basis = fields.Boolean(store=False, search='_search_impacting_cash_basis')
def _search_impacting_cash_basis(self, operator, value):
"""
Searches moves that impact the cash basis:
- Move with cash or bank journals
- Move without any receivable or payable line
- Move with a receivable or payable line and a partial is associated, specifically with a receivable or payable line
"""
if operator != 'in':
return NotImplemented
sql = SQL("""(
WITH moves_with_receivable_payable AS (
SELECT DISTINCT aml.move_id as id
FROM account_move_line aml
JOIN account_account account ON aml.account_id = account.id
WHERE account.account_type IN ('asset_receivable', 'liability_payable')
),
reconciled_move_on_receivable_payable AS (
SELECT DISTINCT aml.move_id as id
FROM account_partial_reconcile part
JOIN account_move_line aml ON aml.id = part.debit_move_id OR aml.id = part.credit_move_id
JOIN account_account account ON aml.account_id = account.id
WHERE account.account_type IN ('asset_receivable', 'liability_payable')
)
SELECT DISTINCT move.id
FROM account_move move
LEFT JOIN account_journal journal ON journal.id = move.journal_id
LEFT JOIN moves_with_receivable_payable move_rp on move_rp.id = move.id
LEFT JOIN reconciled_move_on_receivable_payable rec_move on rec_move.id = move.id
WHERE
journal.type IN ('cash', 'bank')
OR
move_rp.id IS NULL
OR
rec_move.id IS NOT NULL
)""")
return [('id', 'in', sql)]