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

Hi Guys,Is there any way to calculate the total outstanding credits of a customer,I have a Balance smart button I have to compute the total outstanding credits of a particular customer

Avatar
Discard
Best Answer

Hi,
Use this code,


account_types = []
receivable_type = self.env.ref('account.data_account_type_receivable').id
payable_type = self.env.ref('account.data_account_type_payable').id
account_types.extend([receivable_type, payable_type])
domain = [('partner_id', '=', self.id), ('amount_residual', '!=', 0),
('account_id.user_type_id', 'in', account_types)]
domain += [('move_id.state', '=', 'posted')]
customer_balance = sum([x.amount_residual for x in self.env['account.move.line'].search(domain)])

Thanks

Avatar
Discard