Skip to Content
Menu
This question has been flagged
1 Reply
2975 Views

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.")
Avatar
Discard
Best Answer

Override this method to adjust the receivable/payable account based on your needs
don`t forget you type your code in model = account.payment
EX:
def _prepare_move_line_default_vals(self, write_off_line_vals=None, force_balance=None):
res = super(AccountPaymentInherit2, self)._prepare_move_line_default_vals(write_off_line_vals, force_balance)
if res:
if self.advance_payment == True:
# print('advance_payment', res)
if self.payment_type == 'outbound': # Vendor Payment (Payable)
res[0]['account_id'] = self.outstanding_account_id.id
res[1]['account_id'] = self.partner_id.property_advance_account_payable_id.id
elif self.payment_type == 'inbound': # Customer Payment (Receivable)
res[0]['account_id'] = self.outstanding_account_id.id
res[1]['account_id'] = self.partner_id.property_advance_account_receivable_id.id
return res

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
2111
6
Jan 22
80607
4
Dec 19
19374
4
Oct 16
5374
1
May 24
1672