fix: отрицательная накидка и сохранность накидок в notes
Отрицательная «Накидка, %» отбрасывалась в четырёх местах (ввод, сохранение, восстановление, отображение) — теперь любое ненулевое значение сохраняется, отрицательное работает как скидка. Коэффициент (аплифт + накидка/100) ограничен снизу нулём и в UI, и в CSV-экспорте. Принимается «−» (U+2212). Накидки пропадали после синхронизации: клиент до v3.41 собирает notes заново из трёх старых полей и при сохранении стирает sale_row_markups на сервере, а следующий pull перезаписывает локальную копию. Клиент теперь переносит незнакомые ключи notes/pricing_ui как есть, чтобы будущие поля не терялись. ADL исправлен (неверное утверждение «старые клиенты игнорируют ключ»). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4501193423
commit
6b9652e3ac
5 files changed
+66
-16
No files matched your search
@@ -623,6 +623,12 @@ const PricingMarkup = {
|
||||
// reads it live rather than relying on per-render input state.
|
||||
let saleRowMarkups = {};
|
||||
|
||||
// Notes keys this client doesn't understand (top-level and inside pricing_ui), kept from
|
||||
// the last restorePricingStateFromNotes() and written back verbatim on save — otherwise
|
||||
// an older client re-saving a config silently drops fields added by a newer one.
|
||||
let loadedNotesExtra = {};
|
||||
let loadedPricingUIExtra = {};
|
||||
|
||||
// Amber marker for world-fallback cells — must stay outside gray/green/red/blue
|
||||
// families since applyCustomPrice() strips those on vendor-price cells via regex.
|
||||
// Shared by renderPricingTab() (initial paint) and recomputeSalePrices() (re-paint on
|
||||
@@ -2589,14 +2595,17 @@ function buildPricingState() {
|
||||
const saleUplift = parseDecimalInput(document.getElementById('pricing-uplift-sale')?.value || '');
|
||||
const saleCustom = parseDecimalInput(document.getElementById('pricing-custom-price-sale')?.value || '');
|
||||
|
||||
// Only non-zero entries are kept, so an untouched config serializes exactly like
|
||||
// before this feature (additive key — old clients simply ignore it).
|
||||
// Only non-zero entries are kept (negative = discount), so an untouched config
|
||||
// serializes exactly like before this feature.
|
||||
const rowMarkups = {};
|
||||
Object.entries(saleRowMarkups).forEach(([key, pct]) => {
|
||||
if (pct > 0) rowMarkups[key] = pct;
|
||||
if (Number.isFinite(pct) && pct !== 0) rowMarkups[key] = pct;
|
||||
});
|
||||
|
||||
return {
|
||||
// Keys this client doesn't know (added by a newer version) are carried through
|
||||
// untouched, so saving here never wipes them — see restorePricingStateFromNotes.
|
||||
...loadedPricingUIExtra,
|
||||
buy_custom_price: buyCustom > 0 ? buyCustom : null,
|
||||
sale_uplift: saleUplift > 0 ? saleUplift : null,
|
||||
sale_custom_price: saleCustom > 0 ? saleCustom : null,
|
||||
@@ -2606,6 +2615,7 @@ function buildPricingState() {
|
||||
|
||||
function serializeConfigNotes() {
|
||||
return JSON.stringify({
|
||||
...loadedNotesExtra,
|
||||
pricing_ui: buildPricingState()
|
||||
});
|
||||
}
|
||||
@@ -2619,8 +2629,12 @@ function restorePricingStateFromNotes(notesRaw) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pricing = parsed?.pricing_ui;
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return;
|
||||
const { pricing_ui: pricing, ...notesExtra } = parsed;
|
||||
loadedNotesExtra = notesExtra;
|
||||
if (!pricing || typeof pricing !== 'object') return;
|
||||
const { buy_custom_price, sale_uplift, sale_custom_price, sale_row_markups, ...pricingExtra } = pricing;
|
||||
loadedPricingUIExtra = pricingExtra;
|
||||
|
||||
const buyInput = document.getElementById('pricing-custom-price-buy');
|
||||
if (buyInput) {
|
||||
@@ -2648,7 +2662,7 @@ function restorePricingStateFromNotes(notesRaw) {
|
||||
saleRowMarkups = {};
|
||||
if (pricing.sale_row_markups && typeof pricing.sale_row_markups === 'object') {
|
||||
Object.entries(pricing.sale_row_markups).forEach(([key, pct]) => {
|
||||
if (typeof pct === 'number' && Number.isFinite(pct) && pct > 0) {
|
||||
if (typeof pct === 'number' && Number.isFinite(pct) && pct !== 0) {
|
||||
saleRowMarkups[key] = pct;
|
||||
}
|
||||
});
|
||||
@@ -4813,7 +4827,8 @@ function _saleRowKey(vendorPN, lot) {
|
||||
// proportional share of the global "Ручная цена" when set) times (global uplift + this
|
||||
// row's own Накидка%).
|
||||
function _saleRowPrice(base, markupPct, saleUplift) {
|
||||
const factor = saleUplift + ((markupPct || 0) / 100);
|
||||
// Negative Накидка is a discount; floored at 0 so a large one can't make a price negative.
|
||||
const factor = Math.max(0, saleUplift + ((markupPct || 0) / 100));
|
||||
return base * factor;
|
||||
}
|
||||
|
||||
@@ -4871,7 +4886,7 @@ function recomputeSalePrices() {
|
||||
function onSaleRowMarkupInput(inputEl) {
|
||||
const key = inputEl.dataset.rowKey;
|
||||
const value = parseDecimalInput(inputEl.value || '');
|
||||
if (value > 0) {
|
||||
if (value !== 0) {
|
||||
saleRowMarkups[key] = value;
|
||||
} else {
|
||||
delete saleRowMarkups[key];
|
||||
@@ -4928,7 +4943,7 @@ function formatPercent(v) {
|
||||
|
||||
function parseDecimalInput(raw) {
|
||||
if (raw == null) return 0;
|
||||
const cleaned = String(raw).trim().replace(/\s/g, '').replace(',', '.');
|
||||
const cleaned = String(raw).trim().replace(/\s/g, '').replace(',', '.').replace(/\u2212/g, '-');
|
||||
const n = parseFloat(cleaned);
|
||||
return Number.isFinite(n) ? n : 0;
|
||||
}
|
||||
@@ -4940,7 +4955,7 @@ function formatUpliftInput(value) {
|
||||
|
||||
// One or two decimals, comma separator, no trailing zeros — for the per-row Накидка input.
|
||||
function formatMarkupInput(value) {
|
||||
if (!Number.isFinite(value) || value <= 0) return '';
|
||||
if (!Number.isFinite(value) || value === 0) return '';
|
||||
return String(Math.round(value * 100) / 100).replace('.', ',');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user