浏览代码

Inventory: no false weight mismatch on a group of weighed spools

- The collapsed group row compared the first spool's scale reading
  with the weight of the whole group, so every weighed group showed
  a mismatch, and Sync re-synced only the first spool.
- The group row now carries no scale reading; each spool in the
  expanded group keeps its own weight check.
maziggy 1 周之前
父节点
当前提交
ffa407381e

+ 1 - 0
CHANGELOG.md

@@ -31,6 +31,7 @@ All notable changes to Bambuddy will be documented in this file.
 - **Choose which printer an "Any model" job takes (#2915, requested by @bryanmahin, contributed by @Keybored02 in #3547)** — Several printers of a model can take an "Any model" job, and the one with the fewest print hours always got it. **Settings > Workflow > Printer Order for Any-Model Jobs** now chooses: the fewest print hours (the default, as before), the most (use up the machines near replacement first), the printer idle the longest (by its last finished print; one that never printed goes first), or the printers' own priority, a number in **Edit Printer** (lowest first, none last). The order only ranks printers that can take the job: a busy, offline or filament-short printer is still passed over, and preferred colours still come first. Powering a printer on with an Auto Power On plug follows the same order.
 
 ### Fixed
+- **A group of weighed spools no longer shows a false weight mismatch** — With **Group** on, the collapsed row of a group compared the first spool's scale reading with the weight of the whole group, so a group of two or more weighed spools always showed a mismatch, and its **Sync** button re-synced only the first spool. The group row now shows no weight check; each spool in the expanded group keeps its own.
 - **"Any model" queue jobs only go to a printer whose nozzle fits (#3536, reported and fixed by @Eifel-Joe in #3554)** — A job queued for any printer of a model went to the first free one without looking at its nozzle, and the nozzle check before the start then failed it, even when another printer of the model had the right nozzle. With two A1s (0.4 mm and 0.6 mm), a file sliced for 0.6 mm could fail on the 0.4 mm one. Now a printer whose nozzles, including the nozzle rack on an H2C, don't fit the file is passed over. If no printer of the model fits, the job waits with "No A1 has a 0.6mm nozzle: ..." instead of failing, and starts by itself once a matching nozzle is fitted. A file or printer without a known nozzle size counts as fitting, as before. Waking a printer with its smart plug, moving a job held for low filament and auto-drying use the same check. A job for one specific printer is unchanged.
 - **Spool labels print Polish, Czech, Cyrillic and Greek letters (#3553, reported by @wsciekly83)** — Label PDFs used the PDF base font Helvetica, which only has Western European characters, so letters like ą, ę, ł, ś or ż and any Cyrillic or Greek text came out as empty boxes, although the inventory showed them correctly. Labels now embed Liberation Sans, which has the same letter widths, so the layout is unchanged. Chinese and Japanese characters are not covered yet
 - **The spool CSV import reads files saved by Excel with European regional settings (#3523, reported and fixed by @jayhemnani9910 in #3529)** — Excel in a comma-decimal locale (German, French, Dutch, Italian, ...) saves CSV with `;` between the fields and `,` as the decimal mark. The import only read commas, so the whole header became one unknown column and nothing was imported ("Required column 'material' is missing"). The separator is now taken from the header line, and in a `;` file a decimal comma in `cost_per_kg` and `weight_used` is read as a decimal point, so `24,99` imports as 24.99. Comma-separated files are read as before. Wiki updated.

+ 44 - 1
frontend/src/__tests__/pages/InventoryPageGroupRestore.test.tsx

@@ -2,7 +2,7 @@
  * Restore on an archived spool inside an expanded group row of the table.
  * The group row passed a no-op to its members, so the button did nothing.
  */
-import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
 import { screen, waitFor, fireEvent } from '@testing-library/react';
 import { render } from '../utils';
 import InventoryPageRouter from '../../pages/InventoryPage';
@@ -145,3 +145,46 @@ describe('InventoryPage — restore inside a group row', () => {
     expect([2, 3]).toContain(restored[0]);
   });
 });
+
+describe('InventoryPage — weight check on a group row', () => {
+  beforeEach(() => {
+    // Group on, and the (hidden by default) Weight Check column shown.
+    vi.mocked(localStorage.getItem).mockImplementation((key: string) => {
+      if (key === 'bambuddy-inventory-group') return 'true';
+      if (key === 'bambuddy-inventory-columns') {
+        return JSON.stringify([{ id: 'weight_check', label: 'Weight Check', visible: true }]);
+      }
+      return null;
+    });
+    // Two identical unopened spools, each weighed at exactly its own weight
+    // (1000 g filament + 250 g core).
+    const weighed = { ...archivedSpool, archived_at: null, weight_used: 0, last_scale_weight: 1250 };
+    server.use(
+      http.get('/api/v1/settings/', () => HttpResponse.json(baseSettings)),
+      http.get('/api/v1/inventory/spools', () =>
+        HttpResponse.json([
+          { ...weighed, id: 2 },
+          { ...weighed, id: 3 },
+        ]),
+      ),
+      http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
+      http.get('/api/v1/spoolman/settings', () => HttpResponse.json({ spoolman_enabled: 'false' })),
+    );
+  });
+
+  afterEach(() => {
+    vi.mocked(localStorage.getItem).mockReset();
+  });
+
+  it('shows no mismatch or Sync on the group row; each spool keeps its own check', async () => {
+    render(<InventoryPageRouter />);
+
+    const header = await screen.findByText('#2, #3');
+    // The first spool's 1250 g against the group's 2500 g read as a mismatch.
+    expect(screen.queryByTitle(/mismatch!/)).not.toBeInTheDocument();
+    expect(screen.queryByTitle('Sync: trust scale weight and reset tracking')).not.toBeInTheDocument();
+
+    fireEvent.click(header.closest('tr')!);
+    expect(await screen.findAllByTitle(/within tolerance/)).toHaveLength(2);
+  });
+});

+ 11 - 0
frontend/src/__tests__/pages/InventoryPageGrouping.test.ts

@@ -299,6 +299,17 @@ describe('computeDisplayItems', () => {
 });
 
 describe('aggregateGroupSpool (#1368)', () => {
+  it('carries no scale reading, so the header shows no weight check', () => {
+    // The first member's reading against the group's summed weight was always
+    // a mismatch, and Sync then re-synced only that member.
+    const agg = aggregateGroupSpool([
+      makeSpool({ id: 1, last_scale_weight: 1250, last_weighed_at: '2026-11-01T10:00:00Z' }),
+      makeSpool({ id: 2, last_scale_weight: 1250, last_weighed_at: '2026-11-01T10:05:00Z' }),
+    ]);
+    expect(agg.last_scale_weight).toBeNull();
+    expect(agg.last_weighed_at).toBeNull();
+  });
+
   it('sums label_weight, weight_used and core_weight across members', () => {
     const agg = aggregateGroupSpool([
       makeSpool({ id: 1, label_weight: 1000, weight_used: 200, core_weight: 250 }),

+ 5 - 0
frontend/src/utils/inventoryGrouping.ts

@@ -5,6 +5,9 @@ import type { InventorySpool } from '../api/client';
 // members so the header shows group totals (#1368), while identity fields are
 // carried from the first member — all members share them, they are the group
 // key. The expanded per-spool rows keep using the real per-member spools.
+// A scale reading belongs to one spool, so the header has none: compared with
+// the summed weight, the first member's reading made every weighed group show
+// a mismatch, and its Sync button re-synced only that first spool.
 export function aggregateGroupSpool(spools: InventorySpool[]): InventorySpool {
   const base = spools[0];
   let labelWeight = 0;
@@ -20,5 +23,7 @@ export function aggregateGroupSpool(spools: InventorySpool[]): InventorySpool {
     label_weight: labelWeight,
     weight_used: weightUsed,
     core_weight: coreWeight,
+    last_scale_weight: null,
+    last_weighed_at: null,
   };
 }