You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _, Command
class AccountMove(models.Model):
_inherit = "account.move"
# _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin', 'sequence.mixin']
# _description = "Journal Entry"
# _order = 'date desc, name desc, id desc'
# _mail_post_access = 'read'
# _check_company_auto = True
# _sequence_index = "journal_id"
# _rec_names_search = ['name', 'partner_id.name', 'ref']
invoice_has_matching_suspense_amount = fields.Boolean(compute='_compute_has_matching_suspense_amount',
groups='account.group_account_invoice,account.group_account_readonly',
help="Technical field used to display an alert on invoices if there is at least a matching amount in any supsense account.")
def _get_domain_matching_suspense_moves(self):
self.ensure_one()
domain = self.env['account.move.line']._get_suspense_moves_domain()
domain += ['|', ('partner_id', '=?', self.partner_id.id), ('partner_id', '=', False)]
if self.is_inbound():
domain.append(('balance', '=', -self.amount_residual))
else:
domain.append(('balance', '=', self.amount_residual))
return domain
def _compute_has_matching_suspense_amount(self):
for r in self:
res = False
if r.state == 'posted' and r.is_invoice() and r.payment_state == 'not_paid':
domain = r._get_domain_matching_suspense_moves()
#there are more than one but less than 5 suspense moves matching the residual amount
if (0 < self.env['account.move.line'].search_count(domain) < 5):
domain2 = [
('payment_state', '=', 'not_paid'),
('state', '=', 'posted'),
('amount_residual', '=', r.amount_residual),
('move_type', '=', r.move_type)]
#there are less than 5 other open invoices of the same type with the same residual
if self.env['account.move'].search_count(domain2) < 5:
res = True
r.invoice_has_matching_suspense_amount = res