Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3188 Lượt xem

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.")
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 24
2234
6
thg 1 22
80827
4
thg 12 19
19537
4
thg 10 16
5533
1
thg 5 24
1805