odooodoo-10

Hide some options from Account Journal dropdown in Account Payment popup form


I need to hide certain entries from the Account Journal dropdown and show only a few items.

I've tried inheriting account_payment model to alter the field like below, but it doesn't work

class account_payment(models.Model):
    _name = "account.payment"
    _inherit = "account.payment"

    journal_id = fields.Many2one('account.journal', string='Payment Journal',
                                 domain=[('name', 'in', ('Cash','Insurance','Bank', 'UPI Payment'))])

How do I achieve this? Thanks


Solution

  • The domain of the journal field is updated when the payment type changes. To use a custom domain, you can rewrite the _onchange_payment_type function:

    @api.onchange('payment_type')
    def _onchange_payment_type(self):
        if not self.invoice_ids:
            # Set default partner type for the payment type
            if self.payment_type == 'inbound':
                self.partner_type = 'customer'
            elif self.payment_type == 'outbound':
                self.partner_type = 'supplier'
            else:
                self.partner_type = False
        # Set payment method domain
        res = self._onchange_journal()
        if not res.get('domain', {}):
            res['domain'] = {}
        res['domain']['journal_id'] = self.payment_type == 'inbound' and [('at_least_one_inbound', '=', True)] or self.payment_type == 'outbound' and [('at_least_one_outbound', '=', True)] or []
        res['domain']['journal_id'].append(('type', 'in', ('bank', 'cash')))
        return res