odoo/odoo · error · ValidationError

Please define a payment method line on your payment.

Error message

Please define a payment method line on your payment.

What it means

A python constraint (_check_payment_method_line_id) on account.payment that fires when payment_method_line_id is null. The field is computed-editable-stored, so it cannot use required=True; the constraint enforces presence at flush/validation time instead.

Source

Thrown at addons/account/models/account_payment.py:870

    def _inverse_memo(self):
        for payment in self:
            move = payment.move_id
            if move:
                move.ref = payment.memo

    # -------------------------------------------------------------------------
    # CONSTRAINT METHODS
    # -------------------------------------------------------------------------

    @api.constrains('payment_method_line_id')
    def _check_payment_method_line_id(self):
        ''' Ensure the 'payment_method_line_id' field is not null.
        Can't be done using the regular 'required=True' because the field is a computed editable stored one.
        '''
        for pay in self:
            if not pay.payment_method_line_id:
                raise ValidationError(_("Please define a payment method line on your payment."))
            elif pay.payment_method_line_id.journal_id and pay.payment_method_line_id.journal_id != pay.journal_id:
                raise ValidationError(_("The selected payment method is not available for this payment, please select the payment method again."))

    @api.constrains('state', 'move_id')
    def _check_move_id(self):
        for payment in self:
            if (
                payment.state not in ('draft', 'canceled')
                and not payment.move_id
                and payment.outstanding_account_id
            ):
                raise ValidationError(_("A payment with an outstanding account cannot be confirmed without having a journal entry."))

    # -------------------------------------------------------------------------
    # LOW-LEVEL METHODS
    # -------------------------------------------------------------------------

    @api.model_create_multi

View on GitHub (pinned to 1e661df964)

Solutions

  1. Enable at least one payment method of the right type (Manual/Bank transfer...) on the journal so a default payment method line exists.
  2. When creating payments programmatically, pass a valid payment_method_line_id (an account.payment.method.line record of the journal matching the payment_type).
  3. Check any override of the computed field _compute_payment_method_line_id that may return an empty recordset.

Example fix

// before
self.env['account.payment'].create({'amount': 100, 'payment_type': 'inbound', 'partner_id': partner.id, 'journal_id': journal.id})
// after
method_line = journal.inbound_payment_method_line_ids[:1]
self.env['account.payment'].create({'amount': 100, 'payment_type': 'inbound', 'partner_id': partner.id, 'journal_id': journal.id, 'payment_method_line_id': method_line.id})
Defensive patterns

Strategy: validation

Validate before calling

def default_method_line(journal, payment_type):
    lines = journal.inbound_payment_method_line_ids if payment_type == 'inbound' else journal.outbound_payment_method_line_ids
    if not lines:
        raise SetupError(f'Journal {journal.name} has no {payment_type} payment method lines')
    return lines[0]

Prevention

When it happens

Trigger: Creating or writing an account.payment where payment_method_line_id computes to empty (e.g. available_payment_method_line_ids on the journal is empty for the payment type, or code explicitly wrote False/omitted it), then flushing/validating records triggers the constraint.

Common situations: Journal has no payment method lines enabled for the payment direction (inbound/outbound); XML-RPC or import scripts that create payments without payment_method_line_id; modules overriding _compute_payment_method_line_id incorrectly.

Related errors


AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15). Data as JSON: /api/errors/465c6e4937012344. Report an issue: GitHub.