mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
(feat) stock limit if stock <= stock threshold
This commit is contained in:
parent
1b7c4862c5
commit
b9397388c5
@ -46,17 +46,18 @@ export const ProductItem: React.FC<ProductItemProps> = ({ product, onEdit, onDel
|
||||
/**
|
||||
* Returns CSS class from stock status
|
||||
*/
|
||||
const statusColor = (product: Product) => {
|
||||
if (product.stock.external < 1 && product.stock.internal < 1) {
|
||||
const statusColor = (product: Product, stockType: string) => {
|
||||
if (product.stock[stockType] < (product.quantity_min || 1)) {
|
||||
return 'out-of-stock';
|
||||
}
|
||||
if (product.low_stock_threshold && (product.stock.external < product.low_stock_threshold || product.stock.internal < product.low_stock_threshold)) {
|
||||
if (product.low_stock_threshold && product.stock[stockType] <= product.low_stock_threshold) {
|
||||
return 'low';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`product-item ${statusColor(product)}`}>
|
||||
<div className='product-item'>
|
||||
<div className='itemInfo'>
|
||||
<img src={thumbnail()?.thumb_attachment_url || noImage} alt='' className='itemInfo-thumbnail' />
|
||||
<p className="itemInfo-name">{product.name}</p>
|
||||
@ -68,11 +69,11 @@ export const ProductItem: React.FC<ProductItemProps> = ({ product, onEdit, onDel
|
||||
: t('app.admin.store.product_item.hidden')
|
||||
}
|
||||
</FabStateLabel>
|
||||
<div className={`stock ${product.stock.internal < product.low_stock_threshold ? 'low' : ''}`}>
|
||||
<div className={`stock ${statusColor(product, 'internal')}`}>
|
||||
<span>{t('app.admin.store.product_item.stock.internal')}</span>
|
||||
<p>{product.stock.internal}</p>
|
||||
</div>
|
||||
<div className={`stock ${product.stock.external < product.low_stock_threshold ? 'low' : ''}`}>
|
||||
<div className={`stock ${statusColor(product, 'external')}`}>
|
||||
<span>{t('app.admin.store.product_item.stock.external')}</span>
|
||||
<p>{product.stock.external}</p>
|
||||
</div>
|
||||
|
@ -57,7 +57,7 @@ export const StoreProductItem: React.FC<StoreProductItemProps> = ({ product, car
|
||||
if (product.stock.external < (product.quantity_min || 1)) {
|
||||
return 'out-of-stock';
|
||||
}
|
||||
if (product.low_stock_threshold && product.stock.external < product.low_stock_threshold) {
|
||||
if (product.low_stock_threshold && product.stock.external <= product.low_stock_threshold) {
|
||||
return 'low';
|
||||
}
|
||||
return '';
|
||||
|
@ -71,7 +71,7 @@ export const StoreProduct: React.FC<StoreProductProps> = ({ productSlug, current
|
||||
if (product.stock.external < (product.quantity_min || 1)) {
|
||||
return 'out-of-stock';
|
||||
}
|
||||
if (product.low_stock_threshold && product.stock.external < product.low_stock_threshold) {
|
||||
if (product.low_stock_threshold && product.stock.external <= product.low_stock_threshold) {
|
||||
return 'low';
|
||||
}
|
||||
return '';
|
||||
|
@ -44,7 +44,7 @@ export default class ProductLib {
|
||||
if (product.stock.external < (product.quantity_min || 1)) {
|
||||
return 'app.public.stock_status.out_of_stock';
|
||||
}
|
||||
if (product.low_stock_threshold && product.stock.external < product.low_stock_threshold) {
|
||||
if (product.low_stock_threshold && product.stock.external <= product.low_stock_threshold) {
|
||||
return 'app.public.stock_status.limited_stock';
|
||||
}
|
||||
return 'app.public.stock_status.available';
|
||||
|
@ -63,6 +63,7 @@
|
||||
color: var(--gray-hard-darkest);
|
||||
span { @include text-xs; }
|
||||
&.low { color: var(--alert-light); }
|
||||
&.out-of-stock { color: var(--alert); }
|
||||
}
|
||||
.price {
|
||||
justify-self: flex-end;
|
||||
@ -95,4 +96,4 @@
|
||||
.actions { grid-area: auto; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,8 +192,8 @@ class ProductService
|
||||
def notify_on_low_stock(product)
|
||||
return product unless product.low_stock_threshold
|
||||
|
||||
if (product.stock['internal'] < product.low_stock_threshold) ||
|
||||
(product.stock['external'] < product.low_stock_threshold)
|
||||
if (product.stock['internal'] <= product.low_stock_threshold) ||
|
||||
(product.stock['external'] <= product.low_stock_threshold)
|
||||
NotificationCenter.call type: 'notify_admin_low_stock_threshold',
|
||||
receiver: User.admins_and_managers,
|
||||
attached_object: product
|
||||
|
Loading…
Reference in New Issue
Block a user