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

Fix company Edit action in published Pages

Quinn White committed Oct 28, 2026 at 20:58 UTC 2be8650c5c87d22954377db4546c6dc9299f1f0a
4 files changed +38 -11
PROJECT_STATE.md
+4
@@ -161,3 +161,7 @@
161 - Owner screenshots show the login heading cropped above the viewport on a laptop. Extend the current login-presentation fix with responsive vertical spacing and safe overflow from the beginning of the form, including short desktops, mobile and reduced CSS viewports under zoom. Preserve all buttons, readable fields, existing brand, normal/recovery authentication and financial behavior. Reproduce with bounding-box/scroll tests before CSS changes, verify source and generated strict-CSP Pages. Moving static buttons also requires verifying generated-handler cache identity so old cached handlers cannot bind to a new DOM order.
162 - Separate new requests remain active: investigate company Edit being unavailable with a real rendered-button test; prepare owner-requested direct password assignment in central users/licenses, restricted to the existing global software-admin role. Organization managers retain recovery-link scope. These are separate scoped fixes, with no production account/password mutation authorized by testing the feature. Production Auth-function activation requires the existing separate explicit approval boundary after a concrete reviewed result.
163 - **Local verification complete2026-10-28:** the new height/scroll browser cases reproduced clipped top at `920×600`, `1024×600`, `1366×650` and lost scroll start at a short desktop before CSS repair. Compact desktop login layout and scroll-from-top now pass source and generated Pages at desktop `920×600`, `1024×600`, `1366×650`, overflow desktop `1024×450`, `680×400` and mobile `390×568`. Full existing browser workflow **191/191 PASS**, generated focused startup/recovery/branding **37/37 PASS**, all **51** static/behavioral/server/release-safety checks PASS including **45/45** server cases and Golden, and diff check PASS. The separate handler-version regression failed on unmodified main because its URL had no content version; generated Pages now use SHA-256 of the generated handler source, and the test confirms the exact downloaded script matches that URL hash and normal synthetic login executes once. The owner has reported a successful site login before this presentation update; post-publication physical-device viewport and intermittent owner-network behavior remain NOT VERIFIED. No account/password, Auth, configuration, SQL, RLS, financial data or dependency change occurred in this presentation PR.
164 +
165 +### 2026-10-28 — Company Edit button repair
166 +- Owner reports that company selection works but the company-table Edit action does not open the editor; requests actual button verification. Separate branch `fix/company-edit-action-20261028` is now based on protected main `c95da47bca863be5b8ead47d49a5a6a8ff30d382`; login layout and central-admin password feature remain separate.
167 +- **Root cause confirmed and local verification complete:** the hardened Pages dispatcher does not support `this.dataset.companyId`, so the rendered Edit button could not call `editCompany`. A narrow `editCompanyFromButton(this)` adapter reads the existing data attribute in application code; the generated button now escapes its ID. Expanded real-DOM tests click Edit, Cancel, Edit, Save, select the default company, log out/reload/edit again, and verify an expired license prevents a save. Source and generated Pages tests **5/5 PASS**; `git diff --check` PASS. No production company record was touched. Protected PR and post-deployment Pages verification are pending.
index.html
+1 -1
@@ -920,7 +920,7 @@ body{background:#f6f9fc}
920 <script src="js/contacts.js?v=20260928-roles-v3"></script>
921 <script src="js/cheques.js"></script>
922 <script src="js/expenses.js"></script>
923 -<script src="js/companies.js?v=20260928-integrity-v4"></script>
923 +<script src="js/companies.js?v=20261028-company-edit-v1"></script>
924 <script src="js/backup.js?v=20260928-data-v3"></script>
925 <script src="js/words.js"></script>
926 <script src="js/bootstrap.js?v=20261025-password-recovery-v1"></script>
js/companies.js
+3 -1
@@ -63,6 +63,8 @@ function resetCompanyForm(){
63 companyEditBaseline='';updateCompanyFormAction();
64 }
65
66 +// Pages dispatches DOM elements safely; read the data attribute inside the handler.
67 +function editCompanyFromButton(button){editCompany(button.dataset.companyId);}
68 function editCompany(id){
69 if(!currentUser)return;
70 const comp=getMyCompanies().find(c=>c.id===id);
@@ -134,7 +136,7 @@ function renderCompanies(){
136 if(myCompanies.length===0){
137 tbody.innerHTML='<tr><td colspan="7" style="text-align:center;color:var(--text-muted);padding:20px">هیچ شرکتی ثبت نشده است. لطفاً ابتدا شرکت خود را ثبت کنید.</td></tr>';
138 }else{
137 - tbody.innerHTML=myCompanies.map(c=>`<tr><td><strong>${esc(c.name)}</strong></td><td>${esc(companyLegalSummary(c))}</td><td>${esc(COMPANY_ACTIVITY_LABELS[c.activityType||'trading']||c.activityType||'—')}</td><td>${esc(c.national_id||'—')}</td><td>${esc(c.economic_code||'—')}</td><td>${c.id===defCompId?'<span class="badge badge-success">پیش‌فرض</span>':`<button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px" onclick="setDefaultCompany('${c.id}')">انتخاب</button>`}</td><td><button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px;margin-left:5px" data-company-id="${c.id}" onclick="editCompany(this.dataset.companyId)">✏️ اصلاح</button>${myCompanies.length>1?`<button class="btn btn-danger btn-inline" style="padding:2px 8px;font-size:11px" onclick="deleteCompany('${c.id}')">حذف</button>`:'—'}</td></tr>`).join('');
139 + tbody.innerHTML=myCompanies.map(c=>`<tr><td><strong>${esc(c.name)}</strong></td><td>${esc(companyLegalSummary(c))}</td><td>${esc(COMPANY_ACTIVITY_LABELS[c.activityType||'trading']||c.activityType||'—')}</td><td>${esc(c.national_id||'—')}</td><td>${esc(c.economic_code||'—')}</td><td>${c.id===defCompId?'<span class="badge badge-success">پیش‌فرض</span>':`<button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px" onclick="setDefaultCompany('${c.id}')">انتخاب</button>`}</td><td><button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px;margin-left:5px" data-company-id="${esc(c.id)}" onclick="editCompanyFromButton(this)">✏️ اصلاح</button>${myCompanies.length>1?`<button class="btn btn-danger btn-inline" style="padding:2px 8px;font-size:11px" onclick="deleteCompany('${c.id}')">حذف</button>`:'—'}</td></tr>`).join('');
140 }
141 }
142 // Company selection is owned by Settings, not the invoice archive or
scripts/phase0-invoice-persistence.spec.js
+30 -9
@@ -26,8 +26,8 @@ async function installHarness(page,server){
26 });
27 await page.route(/https:\/\/[^/]*supabase\.co\//,route=>route.abort());
28 }
29 -async function authenticatedMockBrowser(page,companyId='QA_CO'){
30 - await page.goto(BASE,{waitUntil:'domcontentloaded'});
29 +async function authenticatedMockBrowser(page,companyId='QA_CO',url=BASE){
30 + await page.goto(url,{waitUntil:'domcontentloaded'});
31 // Mock identity must be injected only after the async organization wrapper
32 // and all ERP extensions have finished installing. Test-only readiness guard.
33 await page.waitForFunction(()=>typeof enterApp==='function'&&typeof commitSaveInvoice==='function'&&
@@ -173,11 +173,23 @@ test('invoice defaults preserve zero VAT, document kind and every currency mode
173 expect([...server.records.values()].filter(r=>['purchases','journalVouchers','journalLines'].includes(r.collection))).toHaveLength(0);
174 });
175
176 -test('company settings and active company survive save, logout and restored cloud reads without applying a chart',async({page})=>{
176 +for(const [layout,url] of [['source',BASE],['published Pages',new URL('/_site/index.html',BASE).href]])
177 +test(layout+': company Edit and Save buttons persist settings and active company through logout without applying a chart',async({page})=>{
178 const server=fakeServer();
179 + Object.assign(server.records.get('settings|main').data,{professional_role:'accountant',user_display_name:'Company QA'});
180 server.records.set('companies|QA_CO2',{collection:'companies',id:'QA_CO2',data:{name:'شرکت دوم آزمون',entity_type:'legal'}});
181 await installHarness(page,server);
180 - await authenticatedMockBrowser(page);
182 + await authenticatedMockBrowser(page,'QA_CO',url);
183 + const errors=[];page.on('pageerror',e=>errors.push(e.message));
184 + await page.evaluate(()=>navigateShell('settings','view-settings','company'));
185 + await page.locator('#companies-table-body [data-company-id="QA_CO"]').click();
186 + await expect(page.locator('#company-name-input')).toHaveValue('شرکت آزمون ایزوله');
187 + await expect(page.locator('#company-save-btn')).toBeDisabled();
188 + await page.locator('#company-phone-input').fill('02100000000');
189 + await expect(page.locator('#company-save-btn')).toBeEnabled();
190 + await page.locator('#company-edit-cancel-btn').click();
191 + await expect(page.locator('#company-name-input')).toHaveValue('');
192 + await page.locator('#companies-table-body [data-company-id="QA_CO"]').click();
193 const form={
194 'company-entity-type':'legal','company-sector':'cooperative','company-legal-form':'limited_liability',
195 'company-organization-role':'standalone','company-parent-id':'','company-activity-type':'service',
@@ -187,22 +199,31 @@ test('company settings and active company survive save, logout and restored clou
199 'company-address-input':'نشانی ساختگی آزمون','company-footer-input':'متن پایانی آزمون'
200 };
201 await page.evaluate(form=>{
190 - switchView('view-settings');editCompany('QA_CO');
202 for(const [id,value] of Object.entries(form)){const el=document.getElementById(id);el.value=value;el.dispatchEvent(new Event('input',{bubbles:true}));}
203 document.getElementById('company-accounting-template').value='empty';
193 - document.getElementById('company-save-btn').click();
204 },form);
205 + await page.locator('#company-save-btn').click();
206 await expect.poll(()=>server.records.get('companies|QA_CO')?.data.footer).toBe(form['company-footer-input']);
196 - await page.evaluate(()=>setDefaultCompany('QA_CO2'));
207 + await page.locator('#companies-table-body tr').filter({hasText:'شرکت دوم آزمون'}).getByRole('button',{name:'انتخاب',exact:true}).click();
208 await expect.poll(()=>server.records.get('settings|main')?.data.default_company_id).toBe('QA_CO2');
209 await expect.poll(()=>page.evaluate(()=>syncPending||syncRunning)).toBe(false);
210 await page.evaluate(()=>{sb.auth.signOut=async()=>({error:null});});
211 await Promise.all([page.waitForEvent('load'),page.evaluate(()=>handleLogout())]);
201 - await authenticatedMockBrowser(page,'QA_CO2');
212 + await authenticatedMockBrowser(page,'QA_CO2',url);
213 + await page.evaluate(()=>navigateShell('settings','view-settings','company'));
214 + await page.locator('#companies-table-body [data-company-id="QA_CO"]').click();
215 expect(await page.evaluate(()=>getMySettings().default_company_id)).toBe('QA_CO2');
216 await expect(page.locator('#invoice-company-id')).toHaveValue('QA_CO2');
217 expect(await page.evaluate(ids=>{
205 - editCompany('QA_CO');return Object.fromEntries(ids.map(id=>[id,document.getElementById(id).value]));
218 + return Object.fromEntries(ids.map(id=>[id,document.getElementById(id).value]));
219 },Object.keys(form))).toEqual(form);
220 + const writes=server.rpcCount;
221 + await page.evaluate(()=>{currentUser.subscription.status='expired';updateCompanyFormAction();});
222 + await page.locator('#company-phone-input').fill('02199999999');
223 + await expect(page.locator('#company-save-btn')).toBeDisabled();
224 + await page.evaluate(()=>commitSaveCompany());
225 + expect(server.rpcCount).toBe(writes);
226 + expect(server.records.get('companies|QA_CO').data.phone).toBe(form['company-phone-input']);
227 + expect(errors).toEqual([]);
228 expect([...server.records.values()].filter(r=>['accounts','invoices','purchases','journalVouchers','journalLines'].includes(r.collection))).toHaveLength(0);
229 });