When creating a customer payment, the journal entry is comprised of a debit to the bank account that is set on account.journal and a credit to the receivable account that is set on res.partner.
I want to override those defaults if a custom boolean field (trust_account_deposit) I have created on account.payment is set to true.
I have also created booleans for account.account to mark an account as 'trust_bank_account' and another account as 'trust_receivable_account', and I want the customer payment to generate a journal entry that uses those accounts for the debit and credit items.
Below is the code I have so far. How can I achieve the setting of custom accounts in the journal entry?
class AccountAccount(models.Model):
_inherit = 'account.account'
trust_bank_account = fields.Boolean("Trust Bank Account", default=False)
trust_receivable_account = fields.Boolean("Trust Receivable Account", default=False)
@api.constrains('trust_bank_account','trust_receivable_account')
def _check_unique_trust_accounts(self):
for record in self:
if record.trust_bank_account and record.trust_receivable_account:
raise ValidationError("An account cannot be both Trust Bank Account and Trust Receivable Account.")
if record.trust_bank_account:
existing_trust_bank_account = self.env['account.account'].search([
('trust_bank_account', '=', True),
('id', '!=', record.id),
])
if existing_trust_account_journal:
raise ValidationError("There can be only one Trust Account Journal.")
class AccountPayment(models.Model):
_inherit = 'account.payment'
trust_account_deposit = fields.Boolean("Trust Account Deposit", default=False)
trust_account_transfer = fields.Boolean("Trust Account Transfer", default=False)
@api.constrains('trust_account_deposit', 'trust_account_transfer')
def _check_unique_trust_payment_type(self):
for record in self:
if record.trust_account_deposit and record.trust_account_transfer:
raise ValidationError("A payment record cannot be both Trust Account Deposit and Trust Account Transfer.")