{"record":{"id":"465c6e4937012344","repo":"odoo/odoo","slug":"please-define-a-payment-method-line-on-your-paymen","errorCode":null,"errorMessage":"Please define a payment method line on your payment.","messagePattern":"Please define a payment method line on your payment\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"addons/account/models/account_payment.py","lineNumber":870,"sourceCode":"\n    def _inverse_memo(self):\n        for payment in self:\n            move = payment.move_id\n            if move:\n                move.ref = payment.memo\n\n    # -------------------------------------------------------------------------\n    # CONSTRAINT METHODS\n    # -------------------------------------------------------------------------\n\n    @api.constrains('payment_method_line_id')\n    def _check_payment_method_line_id(self):\n        ''' Ensure the 'payment_method_line_id' field is not null.\n        Can't be done using the regular 'required=True' because the field is a computed editable stored one.\n        '''\n        for pay in self:\n            if not pay.payment_method_line_id:\n                raise ValidationError(_(\"Please define a payment method line on your payment.\"))\n            elif pay.payment_method_line_id.journal_id and pay.payment_method_line_id.journal_id != pay.journal_id:\n                raise ValidationError(_(\"The selected payment method is not available for this payment, please select the payment method again.\"))\n\n    @api.constrains('state', 'move_id')\n    def _check_move_id(self):\n        for payment in self:\n            if (\n                payment.state not in ('draft', 'canceled')\n                and not payment.move_id\n                and payment.outstanding_account_id\n            ):\n                raise ValidationError(_(\"A payment with an outstanding account cannot be confirmed without having a journal entry.\"))\n\n    # -------------------------------------------------------------------------\n    # LOW-LEVEL METHODS\n    # -------------------------------------------------------------------------\n\n    @api.model_create_multi","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/account/models/account_payment.py#L852-L888","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Enable at least one payment method of the right type (Manual/Bank transfer...) on the journal so a default payment method line exists.","When creating payments programmatically, pass a valid payment_method_line_id (an account.payment.method.line record of the journal matching the payment_type).","Check any override of the computed field _compute_payment_method_line_id that may return an empty recordset."],"exampleFix":"// before\nself.env['account.payment'].create({'amount': 100, 'payment_type': 'inbound', 'partner_id': partner.id, 'journal_id': journal.id})\n// after\nmethod_line = journal.inbound_payment_method_line_ids[:1]\nself.env['account.payment'].create({'amount': 100, 'payment_type': 'inbound', 'partner_id': partner.id, 'journal_id': journal.id, 'payment_method_line_id': method_line.id})","handlingStrategy":"validation","validationCode":"def default_method_line(journal, payment_type):\n    lines = journal.inbound_payment_method_line_ids if payment_type == 'inbound' else journal.outbound_payment_method_line_ids\n    if not lines:\n        raise SetupError(f'Journal {journal.name} has no {payment_type} payment method lines')\n    return lines[0]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass payment_method_line_id explicitly when creating payments via API.","Provision journals with at least the 'Manual' method enabled for both directions.","Test overrides of _compute_payment_method_line_id with journals lacking method lines."],"tags":["accounting","payment","constraint","configuration"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}