@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 14a8858
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 22:00 UTC

refactor(invoice): reuse existing product-select hydration instead of duplicating renderer (#216)

davoodmehraban89 committed Nov 22, 2026 at 01:54 UTC 14a88586c7bf95491707d6368699c1438ed56a47
1 file changed +5 -14
js/invoices.js
+5 -14
@@ -717,22 +717,13 @@ function cancelInvoiceEdit(){
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;
720 + // Reuse the existing searchable-select option sync, which preserves row
721 + // selection and handles its current user product catalog. Do not recreate
722 + // rows or duplicate the product-option renderer here.
723 + if(!currentUser||typeof finoraRefreshSearchableSelect!=='function')return;
724 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);
726 + finoraRefreshSearchableSelect(select);
727 });
728 }
729 function renderInvoices(){