31 lines
1.8 KiB
Python
31 lines
1.8 KiB
Python
from odoo import api, models
|
|
from odoo.exceptions import UserError
|
|
from odoo.tools.translate import _
|
|
|
|
class AccountMoveLine(models.Model):
|
|
_inherit = 'account.move.line'
|
|
|
|
@api.depends('move_id', 'account_id', 'tax_line_id')
|
|
def _compute_display_type(self):
|
|
super()._compute_display_type()
|
|
for line in self:
|
|
if line.display_type == 'product' and line.move_id.is_invoice():
|
|
if line.account_id and line.account_id.account_type == 'liability_current':
|
|
line.display_type = 'payment_term'
|
|
|
|
@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 in ('liability_payable', 'liability_current'):
|
|
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'):
|
|
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))
|
|
# Patch: Allow 'liability_current' to also act as a payment_term
|
|
if (line.display_type == 'payment_term') ^ (account_type in ('liability_payable', 'liability_current')):
|
|
raise UserError(_("Any journal item on a payable account must have a due date and vice versa."))
|