Skip to content

Commit

Permalink
Update supplier item number
Browse files Browse the repository at this point in the history
  • Loading branch information
PleatherStarfish committed Aug 4, 2024
1 parent 852d6f8 commit 8014cd5
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.5 on 2024-08-04 12:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('components', '0004_component_current_rating_component_forward_current_and_more'),
]

operations = [
migrations.AddField(
model_name='component',
name='supplier_has_no_item_no',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='component',
name='supplier_item_no',
field=models.CharField(max_length=100, null=True, unique=True),
),
]
9 changes: 8 additions & 1 deletion backend/components/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class Component(BaseModel):
supplier = models.ForeignKey(
ComponentSupplier, blank=True, null=True, on_delete=models.PROTECT
)
supplier_item_no = models.CharField(max_length=100, blank=False, unique=True)
supplier_item_no = models.CharField(
max_length=100, unique=True, null=True
)
supplier_has_no_item_no = models.BooleanField(default=False)
type = models.ForeignKey(Types, on_delete=models.PROTECT)
ohms = models.DecimalField(
blank=True,
Expand Down Expand Up @@ -163,6 +166,10 @@ def __str__(self):
return f"{self.description} -- {self.type.name} -- ({self.supplier.name} {self.supplier_item_no})"

def clean(self):
if not self.supplier_has_no_item_no and not self.supplier_item_no:
raise ValidationError(
"Supplier item number is required if 'supplier has no item number' is False."
)
if self.type.name == "Resistors":
if not self.ohms or not self.ohms_unit:
raise ValidationError(
Expand Down
2 changes: 1 addition & 1 deletion backend/static/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/components/VersionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const SupplierItemNo = ({ componentPks }) => {

return (
<a href={component?.link} className="text-blue-500 hover:text-blue-700">
{component?.supplier_item_no}
{component?.supplier_item_no ? component?.supplier_item_no : "[ none ]"}
</a>
);
};
Expand Down
44 changes: 36 additions & 8 deletions frontend/src/components/bom_list/nestedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const NestedTable = ({ data }) => {
selector: (row) => {
console.log(row)
return <a href={row.link} className="text-blue-500 hover:text-blue-700">
{row.supplier_item_no}
{row?.supplier_item_no ? row?.supplier_item_no : "[ none ]"}
</a>
},
sortable: true,
Expand Down Expand Up @@ -143,17 +143,45 @@ const NestedTable = ({ data }) => {
wrap: true,
omit: type !== "Resistor",
},
{
name: <div>Forward Current</div>,
selector: (row) => row.forward_current,
sortable: true,
wrap: true,
omit: row => row.type.name !== "Diodes",
},
{
name: <div>Forward Voltage</div>,
selector: (row) => row.forward_voltage,
sortable: true,
wrap: true,
omit: row => row.type.name !== "Diodes",
},
{
name: <div>Forward Surge Current</div>,
selector: (row) => row.forward_surge_current,
sortable: true,
wrap: true,
omit: row => row.type.name !== "Diodes",
},
{
name: <div>Forward Current Avg Rectified</div>,
selector: (row) => row.forward_current_avg_rectified,
sortable: true,
wrap: true,
omit: row => row.type.name !== "Diodes",
},
{
name: <div>Price</div>,
selector: (row) => {
return (
<span>
{row.component?.price_currency &&
{row.price_currency &&
`${getCurrencySymbol(
row.component.price_currency
row.price_currency
)}${roundToCurrency(
row.component.price,
row.component.price_currency
row.price,
row.price_currency
)}`}
</span>
);
Expand Down Expand Up @@ -236,9 +264,9 @@ const NestedTable = ({ data }) => {
<AddComponentModal
open={inventoryModalOpen === row.id}
setOpen={setInventoryModalOpen}
title={`Add ${row.supplier?.short_name} ${row.supplier_item_no} to Inventory?`}
title={row.supplier_item_no ? `Add ${row.supplier?.short_name} ${row.supplier_item_no} to Inventory?` : `Add ${row.description} to Inventory?`}
type={Types.INVENTORY}
componentName={`${row.supplier?.short_name} ${row.supplier_item_no}`}
componentName={row.supplier_item_no ? `${row.supplier?.short_name} ${row.supplier_item_no}` : row.description}
text={
<>
<span>
Expand Down Expand Up @@ -294,7 +322,7 @@ const NestedTable = ({ data }) => {
open={shoppingModalOpen === row.id}
setOpen={setShoppingModalOpen}
title={`Add ${row.description} to Shopping List?`}
componentName={`${row.supplier?.short_name} ${row.supplier_item_no}`}
componentName={row.supplier_item_no ? `${row.supplier?.short_name} ${row.supplier_item_no}` : row.description}
type={Types.SHOPPING}
hookArgs={{
component_pk: row.id,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const Inventory = () => {
.map((row) =>
[
row.component.description.replace(/,/g, ""),
row.component.supplier_item_no.replace(/,/g, ""),
(row.component.supplier_item_no ?? "").replace(/,/g, ""),
row.component.farads,
row.component.price,
row.quantity,
Expand Down Expand Up @@ -274,7 +274,7 @@ const Inventory = () => {
href={row.component.link}
className="text-blue-500 hover:text-blue-700"
>
{row.component.supplier_item_no}
{row.component?.supplier_item_no ? row.component?.supplier_item_no : "[ none ]"}
</a>
);
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/shopping_list/addOneModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const AddOneModal = ({
onSubmit={handleAddToInventory}
>
<div>
{`Are you sure you want to add ${component?.supplier?.short_name} ${component?.supplier_item_no} to your inventory? This will remove this item from your shopping list.`}
{component?.supplier_item_no ? `Are you sure you want to add ${component?.supplier?.short_name} ${component?.supplier_item_no} to your inventory? This will remove this item from your shopping list.` : `Are you sure you want to add ${component?.description} to your inventory? This will remove this item from your shopping list.`}
</div>
<InventoryModalContent
isLoadingQuantity={isLoadingQuantity}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/shopping_list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const ShoppingList = () => {
let copyString = '';
userShoppingListData.aggregatedComponents.forEach((item) => {
if (item?.component.supplier.name === "Mouser Electronics") {
copyString += `${item?.component.supplier_item_no}|${item?.quantity}\n`;
copyString += `${item?.component?.supplier_item_no}|${item?.quantity}\n`;
}
});

Expand Down Expand Up @@ -216,8 +216,8 @@ const ShoppingList = () => {
<div className="w-full p-4 rounded bg-stone-200">
<ul>
{mouserItems.map((item) => (
<li key={item?.component.supplier_item_no}>
{`${item?.component.supplier_item_no}|${item?.quantity}\n`}
<li key={item?.component?.supplier_item_no}>
{`${item?.component?.supplier_item_no}|${item?.quantity}\n`}
</li>
))}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const InventoryModalContent = ({
<div>Error: {isErrorQuantity?.message || isErrorLocation?.message}</div>
) : (
<div className="p-4 mt-4 mb-2 bg-gray-100 rounded-md">
{showComponentHeading && <h2>{`${component?.[0].supplier?.short_name} ${component?.[0].supplier_item_no}`}</h2>}
{showComponentHeading && <h2>{component?.[0]?.supplier_item_no ? `${component?.[0].supplier?.short_name} ${component?.[0]?.supplier_item_no}` : component?.[0]?.description}</h2>}
<p className="my-2 text-xs text-slate-500">
Specify the location where you will store this item in your inventory. Separate locations with commas.
</p>
Expand All @@ -35,7 +35,7 @@ const InventoryModalContent = ({
<div className="mt-4">
<Accordion
backgroundColor="bg-blue-100"
title={`Your inventory locations for ${component?.[0].supplier?.short_name} ${component?.[0].supplier_item_no}`}
title={component?.[0]?.supplier_item_no ? `Your inventory locations for ${component?.[0].supplier?.short_name} ${component?.[0]?.supplier_item_no}` : `Your inventory locations for ${component?.[0].description}`}
>
<div className="p-4 bg-blue-100 rounded-md">
<p className="mb-4 text-xs text-slate-500">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/shopping_list/listSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const ListSlice = ({
"text-blue-500 hover:text-blue-700": index !== 0,
})}
>
{row.component.supplier_item_no}
{row.component?.supplier_item_no ? row.component?.supplier_item_no : "[ none ]"}
</a>
),
sortable: false,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const Components = () => {
selector: (row) => {
return (
<a href={row.link} className="text-blue-500 hover:text-blue-700">
{row.supplier_item_no}
{row?.supplier_item_no ? row?.supplier_item_no : "[ none ]"}
</a>
);
},
Expand Down Expand Up @@ -216,8 +216,8 @@ const Components = () => {
<AddComponentModal
open={inventoryModalOpen === row.id}
setOpen={setInventoryModalOpen}
componentName={`${row.supplier?.short_name} ${row.supplier_item_no}`}
title={`Add ${row.supplier?.short_name} ${row.supplier_item_no} to Inventory?`}
componentName={row.supplier_item_no ? `${row.supplier?.short_name} ${row.supplier_item_no}` : row.description}
title={row.supplier_item_no ? `Add ${row.supplier?.short_name} ${row.supplier_item_no} to Inventory?` : `Add ${row.description} to Inventory?`}
// text={`Add ${row.description} (${row.supplier?.short_name} ${row.supplier_item_no}) to your inventory?`}
type={Types.INVENTORY}
quantityRequired={1}
Expand Down

0 comments on commit 8014cd5

Please sign in to comment.