def METHOD_NAME(self):
    apoo = self.env["account.payment.order"]
    result_payorder_ids = set()
    action_payment_type = "debit"
    for move in self:
        if move.state != "posted":
            raise UserError(_("The invoice %s is not in Posted state") % move.name)
        applicable_lines = move.line_ids.filtered(
            lambda x: (
                not x.reconciled
                and x.payment_mode_id.payment_order_ok
                and x.account_id.internal_type in ("receivable", "payable")
                and not any(
                    p_state in ("draft", "open", "generated")
                    for p_state in x.payment_line_ids.mapped("state")
                )
            )
        )
        if not applicable_lines:
            raise UserError(
                _(
                    "No Payment Line created for invoice %s because "
                    "it already exists or because this invoice is "
                    "already paid."
                )
                % move.name
            )
        payment_modes = applicable_lines.mapped("payment_mode_id")
        if not payment_modes:
            raise UserError(_("No Payment Mode on invoice %s") % move.name)
        for payment_mode in payment_modes:
            payorder = apoo.search(
                move.get_account_payment_domain(payment_mode), limit=1
            )
            new_payorder = False
            if not payorder:
                payorder = apoo.create(
                    move._prepare_new_payment_order(payment_mode)
                )
                new_payorder = True
            result_payorder_ids.add(payorder.id)
            action_payment_type = payorder.payment_type
            count = 0
            for line in applicable_lines.filtered(
                lambda x: x.payment_mode_id == payment_mode
            ):
                line.create_payment_line_from_move_line(payorder)
                count += 1
            if new_payorder:
                move.message_post(
                    body=_(
                        "%d payment lines added to the new draft payment "
                        "order <a href=# data-oe-model=account.payment.order "
                        "data-oe-id=%d>%s</a> which has been automatically created."
                    )
                    % (count, payorder.id, payorder.display_name)
                )
            else:
                move.message_post(
                    body=_(
                        "%d payment lines added to the existing draft "
                        "payment order "
                        "<a href=# data-oe-model=account.payment.order "
                        "data-oe-id=%d>%s</a>."
                    )
                    % (count, payorder.id, payorder.display_name)
                )
    action = self.env["ir.actions.act_window"]._for_xml_id(
        "account_payment_order.account_payment_order_%s_action"
        % action_payment_type,
    )
    if len(result_payorder_ids) == 1:
        action.update(
            {
                "view_mode": "form,tree,pivot,graph",
                "res_id": payorder.id,
                "views": False,
            }
        )
    else:
        action.update(
            {
                "view_mode": "tree,form,pivot,graph",
                "domain": "[('id', 'in', %s)]" % list(result_payorder_ids),
                "views": False,
            }
        )
    return action