add payable/receiver log for import account.move

This commit is contained in:
Florian du Garage Num 2025-08-28 21:35:19 +02:00
parent 8f0d5775a6
commit 5b809b83c4

View File

@ -1,4 +1,6 @@
from odoo import models, fields, api
import logging
_logger = logging.getLogger(__name__)
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
@ -21,3 +23,19 @@ class AccountMoveLine(models.Model):
readonly=False,
help='Credit journal items that are matched with this journal item.',
)
@api.constrains('account_id', 'display_type')
def _check_payable_receivable(self):
for line in self:
account_type = line.account_id.account_type
if line.move_id.is_sale_document(include_receipts=True):
if account_type == 'liability_payable':
raise UserError(_("Account %s is of payable type, but is used in a sale operation.", line.account_id.code))
if (line.display_type == 'payment_term') ^ (account_type == 'asset_receivable'):
_logger.debug("Error receivable on %s: %s - %s (%s)", line.name, line.date_maturity, line.account_id.code, line.account_id.account_type)
raise UserError(_("Any journal item on a receivable account must have a due date and vice versa."))
if line.move_id.is_purchase_document(include_receipts=True):
if account_type == 'asset_receivable':
raise UserError(_("Account %s is of receivable type, but is used in a purchase operation.", line.account_id.code))
if (line.display_type == 'payment_term') ^ (account_type == 'liability_payable'):
_logger.debug("Error payable on %s: %s - %s (%s)", line.date, line.date_maturity, line.account_id.code, line.account_id.account_type)
raise UserError(_("Any journal item on a payable account must have a due date and vice versa."))