Auto heir John Francis Dodge, who walked out of prison before his scheduled release because of a court clerk’s paper work error, must return to jail for two more weeks or longer to finish his sentence, a judge ruled on Monday.

But Palm Beach County Circuit Judge Harold Cohen told Dodge, 34, that he did not have to go back to the Loxahatchee Road Prison until July 1 so he could settle a child-custody battle with his ex-wife over the couple’s 6-year-old son.

The youngest grandson of auto magnate Horace Dodge Sr., Dodge now has temporary custody of his son and faces a final custody hearing on June 30, which Cohen’s ruling will allow him to attend.

Cohen said Dodge “has a debt to society which he needs to pay,” but added, “I don’t want to upset the life of a 6-year-old boy.”

Sentenced to a year in jail for violating probation following a 1985 drug- trafficking case, Dodge was released by the Department of Corrections on May 26 after he served just 56 days of his prison term.

The shortened stay was due in part to “gain time” — time subtracted from prison sentences because of prison overcrowding and Corrections Department policies — and the administrative mistake that misled corrections officials into thinking Dodge entered jail almost three months sooner than he actually had.

His sentence had been deferred so he could handle child-custody matters. Dodge was supposed to go to prison on Jan. 6, but started serving the sentence on April 1.

Corrections officials have said they were not been informed of the deferral.

Although Dodge’s attorney, David Roth, calculated the time remaining on his sentence as two weeks, prison officials and Assistant State Attorney Trey Hester, who prosecuted the case, say that is questionable.

Cohen denied a request from Roth to free Dodge from the remainder of the sentence because a trip back to the minimum- to medium-security prison would break up the reunion of father and son and cause the boy, John Francis Dodge Jr., emotional turmoil.

“Look at the damage that will be done to a 6-year-old child. His intention is to take care of his child,” Roth said.

Hester argued it was not within the realm of the court to decide that matter.

“He’s rehabilitated himself,” Roth said of Dodge. “Now the system says he owes us two weeks.”

Loxahatchee Road Prison Maj. Charles Bitzer said corrections officials probably would not be able to determine how much time Dodge owed until “he actually comes back into the (prison) system.”

He said Dodge had been “figured for a release date sometime in August.”

Dodge’s son attended the hearing on Monday morning.

Roth said the boy is not living with his mother, Karen Christine Dodge, in West Palm Beach, because he “wants to be with his daddy.”