سامانه صدور فاکتور و حسابداری
fix(purchase): finalize existing temporary voucher only
davoodmehraban89 committed
Nov 18, 2026 at 09:05 UTC
42bea043744c6de01ad1010639c5f0a4d7b9c934
1 file changed
+4
-4
js/purchases.js
+4
-4
@@ -187,14 +187,14 @@
187
window.finalizePurchasePilotDraft=async function(id){
188
if(!requireWrite())throw new Error('مجوز قطعیسازی ندارید.');
189
const p=myPurchases().find(x=>x.id===id&&x.companyId===afCompanyId());
190
- if(!p||purchaseDocumentStatus(p)!=='draft'||p.journalVoucherId)
191
- throw new Error('فقط پیشنویس خرید بدون سند قطعی قابل قطعیسازی است.');
190
+ if(!p||purchaseDocumentStatus(p)!=='draft'||!p.journalVoucherId)
191
+ throw new Error('فقط پیشنویس خریدی که سند حسابداری موقت آن موجود و قابل قطعیسازی است، قابل قطعیسازی است.');
192
const fy=jeFiscalForDate(p.date);
193
if(!fy||fy.status==='locked')throw new Error('تاریخ خرید در سال مالی باز نیست.');
194
if(!p.supplierId||!p.items?.length||!Number.isFinite(p.grandTotal)||p.grandTotal<=0)
195
throw new Error('اطلاعات تأمینکننده و مبلغ خرید نامعتبر است.');
196
- // Persist the purchase draft first; the server derives and posts the
197
- // accounting lines atomically. Generic sync only persists the source link.
196
+ // The purchase already owns a server-created draft voucher. Posting is the
197
+ // explicit approval transition; no new voucher identity is allocated here.
198
const voucher=await jeRpcAutoPost('purchase',id);
199
const savedPurchase=myPurchases().find(x=>x.id===id);
200
if(!savedPurchase||savedPurchase.journalVoucherId!==voucher.id||purchaseDocumentStatus(savedPurchase)!=='posted')