Skip to content
Snippets Groups Projects
Unverified Commit ece66476 authored by meskio's avatar meskio :tent:
Browse files

Don't assume product extists

parent 7a65dfb9
No related branches found
No related tags found
No related merge requests found
...@@ -6,9 +6,10 @@ import { date2string, time2string, daysAfterNow } from "../util"; ...@@ -6,9 +6,10 @@ import { date2string, time2string, daysAfterNow } from "../util";
function order2picks(order) { function order2picks(order) {
return order.products.map((p) => { return order.products.map((p) => {
const name = p.product !== null ? p.product.name : p.code;
return { return {
code: p.code, code: p.code,
name: p.product.name, name: name,
price: p.price, price: p.price,
}; };
}); });
......
...@@ -16,10 +16,17 @@ import { printDate } from "../util"; ...@@ -16,10 +16,17 @@ import { printDate } from "../util";
import AuthContext from "../AuthContext"; import AuthContext from "../AuthContext";
import { printMoney, url } from "../util"; import { printMoney, url } from "../util";
function getName(order_product) {
if (order_product.product !== null) {
return order_product.product.name;
}
return order_product.code;
}
function ShowOrderTransaction(props) { function ShowOrderTransaction(props) {
const list = props.transaction.order_purchase.map((o) => ( const list = props.transaction.order_purchase.map((o) => (
<li key={o.order_product.code}> <li key={o.order_product.code}>
{o.order_product.product.name} ({o.order_product.code}): {o.amount} {getName(o.order_product)} ({o.order_product.code}): {o.amount}
</li> </li>
)); ));
return ( return (
...@@ -48,7 +55,7 @@ function ShowOrderResults(props) { ...@@ -48,7 +55,7 @@ function ShowOrderResults(props) {
t.member.num.toString() + "-" + purchase.order_product_id.toString(); t.member.num.toString() + "-" + purchase.order_product_id.toString();
return ( return (
<li key={key}> <li key={key}>
{products[i].product.name} {purchase.amount} {getName(products[i])} {purchase.amount}
</li> </li>
); );
} }
...@@ -64,7 +71,7 @@ function ShowOrderResults(props) { ...@@ -64,7 +71,7 @@ function ShowOrderResults(props) {
const product_list = products.map((p) => ( const product_list = products.map((p) => (
<li key={p.code}> <li key={p.code}>
{p.product.name}: {p.total} {getName(p)}: {p.total}
</li> </li>
)); ));
return ( return (
......
...@@ -7,7 +7,7 @@ function ShowPurchase(props) { ...@@ -7,7 +7,7 @@ function ShowPurchase(props) {
return ( return (
<tr key={p.code}> <tr key={p.code}>
<td>{p.code}</td> <td>{p.code}</td>
<td>{p.product.name}</td> <td>{p.product !== null ? p.product.name : p.code}</td>
<td>{printMoney(p.price) + ""}</td> <td>{printMoney(p.price) + ""}</td>
<td>{p.amount}</td> <td>{p.amount}</td>
</tr> </tr>
......
...@@ -8,7 +8,10 @@ function transactionOverlay(transaction) { ...@@ -8,7 +8,10 @@ function transactionOverlay(transaction) {
switch (transaction.type) { switch (transaction.type) {
case "purchase": case "purchase":
title = "compra"; title = "compra";
content = transaction.purchase.map((p) => p.product.name).join(",") + "."; content =
transaction.purchase
.map((p) => (p.product !== null ? p.product.name : p.code))
.join(",") + ".";
break; break;
case "topup": case "topup":
if (transaction.total < 0) { if (transaction.total < 0) {
...@@ -21,9 +24,13 @@ function transactionOverlay(transaction) { ...@@ -21,9 +24,13 @@ function transactionOverlay(transaction) {
case "order": case "order":
title = "pedido de " + transaction.order.name; title = "pedido de " + transaction.order.name;
content = transaction.order_purchase.map((p) => { content = transaction.order_purchase.map((p) => {
const name =
p.order_product.product !== null
? p.order_product.product.name
: p.order_product.code;
return ( return (
<div key={"O" + transaction.ID + "-" + p.order_product.ID}> <div key={"O" + transaction.ID + "-" + p.order_product.ID}>
{p.order_product.product.name + ": " + p.amount} {name + ": " + p.amount}
<br /> <br />
</div> </div>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment