File: //tmp/fix_docno.py
import re
with open('/var/www/magobridge/scripts/mago_export.py', 'r') as f:
content = f.read()
# Sostituisci la funzione get_next_docno
old = """def get_next_docno(cursor, doc_type):
cursor.execute(\"\"\"
SELECT ISNULL(MAX(CAST(DocNo AS INT)), 0) + 1
FROM MA_SaleDoc
WHERE DocumentType = ? AND DocNo NOT LIKE '%/%' AND ISNUMERIC(DocNo) = 1
\"\"\", [doc_type])
return str(cursor.fetchone()[0]).zfill(6)"""
new = """def get_next_docno(cursor, doc_type):
from datetime import datetime
year_suffix = datetime.now().strftime('%y') + 'F'
cursor.execute(\"\"\"
SELECT ISNULL(MAX(CAST(LEFT(DocNo, CHARINDEX('/', DocNo + '/') - 1) AS INT)), 0) + 1
FROM MA_SaleDoc
WHERE DocumentType = ? AND DocNo LIKE ?
\"\"\", [doc_type, '%/' + year_suffix])
next_num = cursor.fetchone()[0]
return str(next_num).zfill(6) + '/' + year_suffix"""
content = content.replace(old, new)
with open('/var/www/magobridge/scripts/mago_export.py', 'w') as f:
f.write(content)
print('OK')