我需要隐藏帐户日记下拉列表中的某些条目并仅显示少数项目。
我尝试继承 account_ payment 模型来更改如下所示的字段,但它不起作用
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'))])
我如何实现这一目标? 谢谢
当付款类型更改时,日记帐字段的域会更新。要使用自定义域,您可以重写 _onchange_ payment_type 函数:
@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