@davoodmehraban89 / Factor-easy / commits / 4f05bed
Fork 0

سامانه صدور فاکتور و حسابداری

fix(invoice): hydrate prelogin product options without replacing unsaved rows (#216)

davoodmehraban89 committed Nov 22, 2026 at 01:52 UTC 4f05beddcafd76e547a5a79016b231a40ad1b371
1 file changed +23
js/invoices.js
+23
@@ -713,7 +713,30 @@ function cancelInvoiceEdit(){
713 addInvoiceItemRow();
714 applyDefaultSettingsToForm();
715 }
716 +// The initial empty invoice row is constructed before sign-in. Its product
717 +// options must be hydrated after tenant records load without recreating the
718 +// row (which would discard a user's unsaved quantity/price or custom notes).
719 +function hydrateEmptyInvoiceProductSelectors(){
720 + if(!currentUser)return;
721 + const products=getMyProducts();
722 + if(!products.length)return;
723 + document.querySelectorAll('#invoice-items-table-body select.row-product-select').forEach(select=>{
724 + // Only hydrate the pre-login placeholder; never rewrite an existing row.
725 + if(select.options.length!==1||select.value)return;
726 + products.forEach(p=>{
727 + const option=document.createElement('option');
728 + option.value=p.id;
729 + option.textContent=p.name+(p.spec?' ('+p.spec+')':'');
730 + option.dataset.price=String(p.sale_price||0);
731 + option.dataset.unit=p.unit||'عدد';
732 + option.dataset.search=[p.code,p.name,p.spec,p.barcode,p.internal_id,p.official_id,p.category,p.subcategory].filter(Boolean).join(' ').toLowerCase();
733 + select.add(option);
734 + });
735 + if(typeof finoraRefreshSearchableSelect==='function')finoraRefreshSearchableSelect(select);
736 + });
737 +}
738 function renderInvoices(){
739 + hydrateEmptyInvoiceProductSelectors();
740 const tbody=document.getElementById('invoice-archive-table-body');
741 if(!tbody)return;
742 // Filtering is authoritative from Settings; no independent ALL/stale filter.