Auto-derive total cannabinoids from THC + CBD when adding inventory
Build and push image / build (push) Successful in 50s
Build and push image / build (push) Successful in 50s
Total cannabinoids % now defaults to THC + CBD and stays in sync as either field changes. Once the user manually edits the total field it stops auto-updating, since some labels list an explicit total that differs from the sum. When autofilling from a previous instance the field is treated as manual (preserving the stored value). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -375,7 +375,7 @@ function InstanceDetailsStep({
|
||||
price: initialPrice,
|
||||
thc: last?.thc ?? (cfg?.showCannabinoidPct !== false ? 22 : 0),
|
||||
cbd: last?.cbd ?? (cfg?.showCannabinoidPct !== false ? 0.4 : 0),
|
||||
totalCannabinoids: last?.totalCannabinoids ?? (cfg?.showCannabinoidPct !== false ? 26 : 0),
|
||||
totalCannabinoids: last?.totalCannabinoids ?? (cfg?.showCannabinoidPct !== false ? 22.4 : 0),
|
||||
purchaseDate: getToday(getStoredTimezone()),
|
||||
});
|
||||
const [newShopName, setNewShopName] = useState("");
|
||||
@@ -383,10 +383,17 @@ function InstanceDetailsStep({
|
||||
const [newBinName, setNewBinName] = useState("");
|
||||
const [newBinCapacity, setNewBinCapacity] = useState(10);
|
||||
const [containerWeight, setContainerWeight] = useState("");
|
||||
const [totalCannaManual, setTotalCannaManual] = useState(!!last);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const update = <K extends keyof typeof form>(k: K, v: (typeof form)[K]) =>
|
||||
setForm((f) => ({ ...f, [k]: v }));
|
||||
setForm((f) => {
|
||||
const next = { ...f, [k]: v };
|
||||
if ((k === "thc" || k === "cbd") && !totalCannaManual) {
|
||||
next.totalCannabinoids = +(next.thc + next.cbd).toFixed(1);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
|
||||
const cpg = !isDiscrete && form.weight > 0 ? form.price / form.weight : 0;
|
||||
const assetIdValid = ASSET_ID_RE.test(assetId);
|
||||
@@ -677,7 +684,10 @@ function InstanceDetailsStep({
|
||||
type="number"
|
||||
step="0.1"
|
||||
value={form.totalCannabinoids}
|
||||
onChange={(e) => update("totalCannabinoids", +e.target.value)}
|
||||
onChange={(e) => {
|
||||
setTotalCannaManual(true);
|
||||
update("totalCannabinoids", +e.target.value);
|
||||
}}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user