feat: integer cents money handling, order page fixes, and vendor filter persistence
Money Handling Architecture: - Store all monetary values as integer cents (€105.91 = 10591) - Add app/utils/money.py with Money class and conversion helpers - Add static/shared/js/money.js for frontend formatting - Update all database models to use _cents columns (Product, Order, etc.) - Update CSV processor to convert prices to cents on import - Add Alembic migration for Float to Integer conversion - Create .architecture-rules/money.yaml with 7 validation rules - Add docs/architecture/money-handling.md documentation Order Details Page Fixes: - Fix customer name showing 'undefined undefined' - use flat field names - Fix vendor info empty - add vendor_name/vendor_code to OrderDetailResponse - Fix shipping address using wrong nested object structure - Enrich order detail API response with vendor info Vendor Filter Persistence Fixes: - Fix orders.js: restoreSavedVendor now sets selectedVendor and filters - Fix orders.js: init() only loads orders if no saved vendor to restore - Fix marketplace-letzshop.js: restoreSavedVendor calls selectVendor() - Fix marketplace-letzshop.js: clearVendorSelection clears TomSelect dropdown - Align vendor selector placeholder text between pages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -79,10 +79,16 @@ function adminMarketplaceLetzshop() {
|
||||
api_key: '',
|
||||
auto_sync_enabled: false,
|
||||
sync_interval_minutes: 15,
|
||||
test_mode_enabled: false,
|
||||
letzshop_csv_url_fr: '',
|
||||
letzshop_csv_url_en: '',
|
||||
letzshop_csv_url_de: ''
|
||||
letzshop_csv_url_de: '',
|
||||
default_carrier: '',
|
||||
carrier_greco_label_url: 'https://dispatchweb.fr/Tracky/Home/',
|
||||
carrier_colissimo_label_url: '',
|
||||
carrier_xpresslogistics_label_url: ''
|
||||
},
|
||||
savingCarrierSettings: false,
|
||||
|
||||
// Orders
|
||||
orders: [],
|
||||
@@ -137,9 +143,75 @@ function adminMarketplaceLetzshop() {
|
||||
this.initTomSelect();
|
||||
});
|
||||
|
||||
// Check localStorage for last selected vendor
|
||||
const savedVendorId = localStorage.getItem('letzshop_selected_vendor_id');
|
||||
if (savedVendorId) {
|
||||
marketplaceLetzshopLog.info('Restoring saved vendor:', savedVendorId);
|
||||
// Load saved vendor after TomSelect is ready
|
||||
setTimeout(async () => {
|
||||
await this.restoreSavedVendor(parseInt(savedVendorId));
|
||||
}, 200);
|
||||
} else {
|
||||
// Load cross-vendor data when no vendor selected
|
||||
await this.loadCrossVendorData();
|
||||
}
|
||||
|
||||
marketplaceLetzshopLog.info('Initialization complete');
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore previously selected vendor from localStorage
|
||||
*/
|
||||
async restoreSavedVendor(vendorId) {
|
||||
try {
|
||||
// Load vendor details first
|
||||
const vendor = await apiClient.get(`/admin/vendors/${vendorId}`);
|
||||
|
||||
// Add to TomSelect and select (silent to avoid double-triggering)
|
||||
if (this.tomSelectInstance) {
|
||||
this.tomSelectInstance.addOption({
|
||||
id: vendor.id,
|
||||
name: vendor.name,
|
||||
vendor_code: vendor.vendor_code
|
||||
});
|
||||
this.tomSelectInstance.setValue(vendor.id, true);
|
||||
}
|
||||
|
||||
// Manually call selectVendor since we used silent mode above
|
||||
// This sets selectedVendor and loads all vendor-specific data
|
||||
await this.selectVendor(vendor.id);
|
||||
|
||||
marketplaceLetzshopLog.info('Restored saved vendor:', vendor.name);
|
||||
} catch (error) {
|
||||
marketplaceLetzshopLog.error('Failed to restore saved vendor:', error);
|
||||
// Clear invalid saved vendor
|
||||
localStorage.removeItem('letzshop_selected_vendor_id');
|
||||
// Load cross-vendor data instead
|
||||
await this.loadCrossVendorData();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Load cross-vendor aggregate data
|
||||
*/
|
||||
async loadCrossVendorData() {
|
||||
marketplaceLetzshopLog.info('Loading cross-vendor data');
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadOrders(),
|
||||
this.loadExceptions(),
|
||||
this.loadExceptionStats(),
|
||||
this.loadJobs()
|
||||
]);
|
||||
} catch (error) {
|
||||
marketplaceLetzshopLog.error('Failed to load cross-vendor data:', error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize Tom Select for vendor autocomplete
|
||||
*/
|
||||
@@ -217,6 +289,9 @@ function adminMarketplaceLetzshop() {
|
||||
const vendor = await apiClient.get(`/admin/vendors/${vendorId}`);
|
||||
this.selectedVendor = vendor;
|
||||
|
||||
// Save to localStorage for persistence
|
||||
localStorage.setItem('letzshop_selected_vendor_id', vendorId.toString());
|
||||
|
||||
// Pre-fill settings form with CSV URLs
|
||||
this.settingsForm.letzshop_csv_url_fr = vendor.letzshop_csv_url_fr || '';
|
||||
this.settingsForm.letzshop_csv_url_en = vendor.letzshop_csv_url_en || '';
|
||||
@@ -245,27 +320,39 @@ function adminMarketplaceLetzshop() {
|
||||
/**
|
||||
* Clear vendor selection
|
||||
*/
|
||||
clearVendorSelection() {
|
||||
async clearVendorSelection() {
|
||||
// Clear TomSelect dropdown
|
||||
if (this.tomSelectInstance) {
|
||||
this.tomSelectInstance.clear();
|
||||
}
|
||||
|
||||
this.selectedVendor = null;
|
||||
this.letzshopStatus = { is_configured: false };
|
||||
this.credentials = null;
|
||||
this.orders = [];
|
||||
this.ordersFilter = '';
|
||||
this.ordersSearch = '';
|
||||
this.ordersHasDeclinedItems = false;
|
||||
this.exceptions = [];
|
||||
this.exceptionsFilter = '';
|
||||
this.exceptionsSearch = '';
|
||||
this.exceptionStats = { pending: 0, resolved: 0, ignored: 0, total: 0, orders_with_exceptions: 0 };
|
||||
this.jobs = [];
|
||||
this.settingsForm = {
|
||||
api_key: '',
|
||||
auto_sync_enabled: false,
|
||||
sync_interval_minutes: 15,
|
||||
test_mode_enabled: false,
|
||||
letzshop_csv_url_fr: '',
|
||||
letzshop_csv_url_en: '',
|
||||
letzshop_csv_url_de: ''
|
||||
letzshop_csv_url_de: '',
|
||||
default_carrier: '',
|
||||
carrier_greco_label_url: 'https://dispatchweb.fr/Tracky/Home/',
|
||||
carrier_colissimo_label_url: '',
|
||||
carrier_xpresslogistics_label_url: ''
|
||||
};
|
||||
|
||||
// Clear localStorage
|
||||
localStorage.removeItem('letzshop_selected_vendor_id');
|
||||
|
||||
// Load cross-vendor data
|
||||
await this.loadCrossVendorData();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -285,6 +372,11 @@ function adminMarketplaceLetzshop() {
|
||||
};
|
||||
this.settingsForm.auto_sync_enabled = response.auto_sync_enabled;
|
||||
this.settingsForm.sync_interval_minutes = response.sync_interval_minutes || 15;
|
||||
this.settingsForm.test_mode_enabled = response.test_mode_enabled || false;
|
||||
this.settingsForm.default_carrier = response.default_carrier || '';
|
||||
this.settingsForm.carrier_greco_label_url = response.carrier_greco_label_url || 'https://dispatchweb.fr/Tracky/Home/';
|
||||
this.settingsForm.carrier_colissimo_label_url = response.carrier_colissimo_label_url || '';
|
||||
this.settingsForm.carrier_xpresslogistics_label_url = response.carrier_xpresslogistics_label_url || '';
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
// Not configured
|
||||
@@ -403,15 +495,9 @@ function adminMarketplaceLetzshop() {
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Load orders for selected vendor
|
||||
* Load orders for selected vendor (or all vendors if none selected)
|
||||
*/
|
||||
async loadOrders() {
|
||||
if (!this.selectedVendor || !this.letzshopStatus.is_configured) {
|
||||
this.orders = [];
|
||||
this.totalOrders = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadingOrders = true;
|
||||
this.error = '';
|
||||
|
||||
@@ -433,7 +519,13 @@ function adminMarketplaceLetzshop() {
|
||||
params.append('search', this.ordersSearch);
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`/admin/letzshop/vendors/${this.selectedVendor.id}/orders?${params}`);
|
||||
// Use cross-vendor endpoint (with optional vendor_id filter)
|
||||
let url = '/admin/letzshop/orders';
|
||||
if (this.selectedVendor) {
|
||||
params.append('vendor_id', this.selectedVendor.id.toString());
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`${url}?${params}`);
|
||||
this.orders = response.orders || [];
|
||||
this.totalOrders = response.total || 0;
|
||||
|
||||
@@ -845,7 +937,8 @@ function adminMarketplaceLetzshop() {
|
||||
try {
|
||||
const payload = {
|
||||
auto_sync_enabled: this.settingsForm.auto_sync_enabled,
|
||||
sync_interval_minutes: parseInt(this.settingsForm.sync_interval_minutes)
|
||||
sync_interval_minutes: parseInt(this.settingsForm.sync_interval_minutes),
|
||||
test_mode_enabled: this.settingsForm.test_mode_enabled
|
||||
};
|
||||
|
||||
// Only include API key if it was provided (not just placeholder)
|
||||
@@ -950,20 +1043,41 @@ function adminMarketplaceLetzshop() {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Save carrier settings
|
||||
*/
|
||||
async saveCarrierSettings() {
|
||||
if (!this.selectedVendor || !this.credentials) return;
|
||||
|
||||
this.savingCarrierSettings = true;
|
||||
this.error = '';
|
||||
this.successMessage = '';
|
||||
|
||||
try {
|
||||
await apiClient.patch(`/admin/letzshop/vendors/${this.selectedVendor.id}/credentials`, {
|
||||
default_carrier: this.settingsForm.default_carrier || null,
|
||||
carrier_greco_label_url: this.settingsForm.carrier_greco_label_url || null,
|
||||
carrier_colissimo_label_url: this.settingsForm.carrier_colissimo_label_url || null,
|
||||
carrier_xpresslogistics_label_url: this.settingsForm.carrier_xpresslogistics_label_url || null
|
||||
});
|
||||
|
||||
this.successMessage = 'Carrier settings saved successfully';
|
||||
} catch (error) {
|
||||
marketplaceLetzshopLog.error('Failed to save carrier settings:', error);
|
||||
this.error = error.message || 'Failed to save carrier settings';
|
||||
} finally {
|
||||
this.savingCarrierSettings = false;
|
||||
}
|
||||
},
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// EXCEPTIONS
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Load exceptions for selected vendor
|
||||
* Load exceptions for selected vendor (or all vendors if none selected)
|
||||
*/
|
||||
async loadExceptions() {
|
||||
if (!this.selectedVendor) {
|
||||
this.exceptions = [];
|
||||
this.totalExceptions = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadingExceptions = true;
|
||||
|
||||
try {
|
||||
@@ -980,7 +1094,12 @@ function adminMarketplaceLetzshop() {
|
||||
params.append('search', this.exceptionsSearch);
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`/admin/order-exceptions?vendor_id=${this.selectedVendor.id}&${params}`);
|
||||
// Add vendor filter if a vendor is selected
|
||||
if (this.selectedVendor) {
|
||||
params.append('vendor_id', this.selectedVendor.id.toString());
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`/admin/order-exceptions?${params}`);
|
||||
this.exceptions = response.exceptions || [];
|
||||
this.totalExceptions = response.total || 0;
|
||||
} catch (error) {
|
||||
@@ -992,19 +1111,20 @@ function adminMarketplaceLetzshop() {
|
||||
},
|
||||
|
||||
/**
|
||||
* Load exception statistics for selected vendor
|
||||
* Load exception statistics for selected vendor (or all vendors if none selected)
|
||||
*/
|
||||
async loadExceptionStats() {
|
||||
if (!this.selectedVendor) {
|
||||
this.exceptionStats = { pending: 0, resolved: 0, ignored: 0, total: 0, orders_with_exceptions: 0 };
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(`/admin/order-exceptions/stats?vendor_id=${this.selectedVendor.id}`);
|
||||
const params = new URLSearchParams();
|
||||
if (this.selectedVendor) {
|
||||
params.append('vendor_id', this.selectedVendor.id.toString());
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`/admin/order-exceptions/stats?${params}`);
|
||||
this.exceptionStats = response;
|
||||
} catch (error) {
|
||||
marketplaceLetzshopLog.error('Failed to load exception stats:', error);
|
||||
this.exceptionStats = { pending: 0, resolved: 0, ignored: 0, total: 0, orders_with_exceptions: 0 };
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1119,10 +1239,13 @@ function adminMarketplaceLetzshop() {
|
||||
|
||||
/**
|
||||
* Load jobs for selected vendor
|
||||
* Note: Jobs are vendor-specific, so we need a vendor selected to show them
|
||||
*/
|
||||
async loadJobs() {
|
||||
// Jobs require a vendor to be selected (they are vendor-specific)
|
||||
if (!this.selectedVendor) {
|
||||
this.jobs = [];
|
||||
this.jobsPagination.total = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user