fix last bugs

This commit is contained in:
2025-09-16 10:47:18 +03:00
parent a43277cb7b
commit cf27903e10
13 changed files with 345 additions and 145 deletions

View File

@@ -330,11 +330,17 @@ class OrdersEditPage:
self.unloading_query = addresses
self.unloading.controls = self.create_unloading_list(addresses, self.on_delete_unloading_address_btn_click)
self.currency = ft.Dropdown(
self.currency_received = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value=self.order['currency'],
value=self.order['currency_received'],
)
self.currency_paid = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value=self.order['currency_paid'],
)
def get_currency(self):
@@ -924,7 +930,8 @@ class OrdersEditPage:
'paid_price': self.paid_price.value,
'loading_addresses': loading_addresses,
'unloading_addresses': unloading_addresses,
'currency': self.currency.value
'currency_received': self.currency_received.value,
'currency_paid': self.currency_paid.value
}
#print(saved_data)
if self.order_number.value == None or len(self.order_number.value)==0:
@@ -1189,12 +1196,21 @@ class OrdersEditPage:
ft.Row(
[
ft.Text("Price", size=18, weight=ft.FontWeight.BOLD),
self.currency
],
alignment=ft.MainAxisAlignment.START
),
ft.Row(
[
self.received_price,
self.paid_price
self.currency_received
]
),
ft.Row(
[
self.paid_price,
self.currency_paid
]
)
],
expand=2.5
)

View File

@@ -261,7 +261,13 @@ class OrdersInPage:
self.filename = ft.Text()
self.currency = ft.Dropdown(
self.currency_received = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value="EURO",
)
self.currency_expenses = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
@@ -842,7 +848,8 @@ class OrdersInPage:
'unloading_addresses': unloading_addresses,
'file':self.filename.value,
'expenses': self.expenses.value,
'currency': self.currency.value
'currency_received': self.currency_received.value,
'currency_expenses': self.currency_expenses.value
}
#print(saved_data)
if self.order_number.value == None or len(self.order_number.value)==0:
@@ -1055,12 +1062,21 @@ class OrdersInPage:
ft.Row(
[
ft.Text("Price / Expenses", size=18, weight=ft.FontWeight.BOLD),
self.currency
],
alignment=ft.MainAxisAlignment.START
),
ft.Row(
[
self.received_price,
self.expenses
self.currency_received,
]
),
ft.Row(
[
self.expenses,
self.currency_expenses
]
)
],
expand=2.5
)

View File

@@ -236,7 +236,13 @@ class OrdersOutPage:
replacement_string=""
),
)
self.currency = ft.Dropdown(
self.currency_received = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value="EURO",
)
self.currency_paid = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
@@ -778,7 +784,8 @@ class OrdersOutPage:
'paid_price': self.paid_price.value,
'loading_addresses': loading_addresses,
'unloading_addresses': unloading_addresses,
'currency':self.currency.value
'currency_received':self.currency_received.value,
'currency_paid': self.currency_paid.value
}
#print(saved_data)
if self.order_number.value == None or len(str(self.order_number.value))==0:
@@ -1054,13 +1061,22 @@ class OrdersOutPage:
ft.Row(
[
ft.Text("Price", size=18, weight=ft.FontWeight.BOLD),
self.currency
],
expand = True,
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
),
ft.Row(
[
self.received_price,
self.paid_price
self.currency_received
]
),
ft.Row(
[
self.paid_price,
self.currency_paid
]
)
],
expand=2.5,
alignment=ft.MainAxisAlignment.END

View File

@@ -1,4 +1,5 @@
ISO = {"EURO": "EUR", "USD": "USD", "CHF": "CHF", "GBP": "GBP"}
ALL_OPTION = "--ALL--"
def fetch_rates_for_base(base_ui: str) -> dict:
"""
@@ -45,7 +46,7 @@ class ReportOrderInPage:
ft.DataColumn(label=ft.Text("Expenses")),
ft.DataColumn(label=ft.Text("Received")),
ft.DataColumn(label=ft.Text("Profit")),
ft.DataColumn(label=ft.Text("Currency")),
#ft.DataColumn(label=ft.Text("Currency")),
],
rows=[],
border=ft.border.all(1, ft.Colors.GREY_300),
@@ -58,12 +59,13 @@ class ReportOrderInPage:
self.clients_filter = ft.Dropdown(
options=[
ft.dropdown.Option(text = client['name'], key=client['name']) for client in self.all_clients
ft.dropdown.Option(text=ALL_OPTION, key=ALL_OPTION),
*[ft.dropdown.Option(text=client['name'], key=client['name']) for client in self.all_clients]
],
width=250,
label="Clients",
hint_text= "Select client",
on_change= self.filter_by_client
hint_text="Select client",
on_change=self.filter_by_client
)
self.clients_filter_placeholder = ft.Container(content=self.clients_filter)
@@ -220,16 +222,19 @@ class ReportOrderInPage:
return amt / rate
# Rebuild table in base currency
self.rows_copy = list(self.rows)
total = 0.0
self.data_table.rows.clear()
# Keep current filters by working on the visible subset (self.rows_copy)
source_rows = list(self.rows_copy)
for r in self.rows_copy:
for r in source_rows:
# r structure: [order_number, client_name, transporter_name, order_date, paid, received, profit, currency]
original_currency = r[6]
paid_base = to_base(r[3], original_currency)
received_base = to_base(r[4], original_currency)
paid_number = r[3].split(" ")[0]
paid_currency = r[3].split(" ")[1]
received_number = r[4].split(" ")[0]
received_currency = r[4].split(" ")[1]
paid_base = to_base(paid_number, paid_currency)
received_base = to_base(received_number, received_currency)
profit_base = round(float(received_base) - float(paid_base), 2)
# Update a display row (do not mutate self.rows source amounts)
@@ -238,10 +243,10 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[0])),
ft.DataCell(ft.Text(r[1])),
ft.DataCell(ft.Text(r[2])),
ft.DataCell(ft.Text(f"{paid_base:.2f}")),
ft.DataCell(ft.Text(f"{received_base:.2f}")),
ft.DataCell(ft.Text(f"{profit_base:.2f}")),
ft.DataCell(ft.Text(base)),
ft.DataCell(ft.Text(f"{paid_base:.2f} {base}")),
ft.DataCell(ft.Text(f"{received_base:.2f} {base}")),
ft.DataCell(ft.Text(f"{profit_base:.2f} {base}")),
#ft.DataCell(ft.Text(base)),
],
)
self.data_table.rows.append(row)
@@ -288,7 +293,7 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
@@ -304,20 +309,24 @@ class ReportOrderInPage:
print(all_orders)
total = 0
for order in all_orders:
if order['currency'] not in self.currency_list:
self.currency_list.append(order['currency'])
if len(self.currency_list) > 1:
self.convert_currency_placeholder.content=self.convert_currency
if order['currency_received'] not in self.currency_list:
self.currency_list.append(order['currency_received'])
if order['currency_expenses'] not in self.currency_list:
self.currency_list.append(order['currency_expenses'])
order_number = order['order_number']
client_name = self.get_client(order['client_id'])['name']
order_date = order['created_at'].split("T")[0]
paid = order['expenses']
received = order['received_price']
currency = order['currency']
paid = f"{order['expenses']} {order['currency_expenses']}"
received = f"{order['received_price']} {order['currency_received']}"
currency = order['currency_received'] if order['currency_expenses'] == order['currency_received'] else ''
if len(currency)>1:
try:
profit = round(float(received) - float(paid), 2)
profit = f"{round(float(order['received_price']) - float(order['expenses']), 2)} {currency}"
except:
profit = 0.00
profit = ''
else:
profit = ''
row = ft.DataRow(
cells=[
@@ -327,13 +336,16 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(paid)),
ft.DataCell(ft.Text(received)),
ft.DataCell(ft.Text(profit)),
ft.DataCell(ft.Text(currency)),
#ft.DataCell(ft.Text(currency)),
],
)
row_data = [order_number, client_name, order_date, paid, received, profit, currency]
self.rows.append(row_data)
self.data_table.rows.append(row)
total += profit
try:
total += float(profit.split(" ")[0])
except Exception:
pass
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.rows_copy = self.rows
@@ -368,11 +380,14 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
total += r[5]
try:
total += float(r[5].split(" ")[0])
except Exception:
pass
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.total.update()
@@ -389,7 +404,7 @@ class ReportOrderInPage:
buffer = []
data = datetime.strptime(self.start_date.value, '%Y-%m-%d')
for r in self.rows_copy:
obj_date = datetime.strptime(r[3], '%Y-%m-%d')
obj_date = datetime.strptime(r[2], '%Y-%m-%d')
if data <= obj_date:
row = ft.DataRow(
cells=[
@@ -399,12 +414,15 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[5]
try:
total += float(r[5].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
@@ -418,7 +436,7 @@ class ReportOrderInPage:
buffer = []
data = datetime.strptime(self.end_date.value, '%Y-%m-%d')
for r in self.rows_copy:
obj_date = datetime.strptime(r[3], '%Y-%m-%d')
obj_date = datetime.strptime(r[2], '%Y-%m-%d')
if data >= obj_date:
row = ft.DataRow(
cells=[
@@ -428,12 +446,15 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[5]
try:
total += float(r[5].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
@@ -442,10 +463,33 @@ class ReportOrderInPage:
def filter_by_client(self, e):
total = 0
self.data_table.rows.clear()
# If ALL or None is selected, show all rows
if self.clients_filter.value in (None, ALL_OPTION):
self.rows_copy = list(self.rows)
for r in self.rows_copy:
row = ft.DataRow(
cells=[
ft.DataCell(ft.Text(r[0])),
ft.DataCell(ft.Text(r[1])),
ft.DataCell(ft.Text(r[2])),
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
try:
total += float(r[5].split(" ")[0])
except Exception:
pass
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.total.update()
return
# Otherwise filter by selected client
buffer = []
for r in self.rows_copy:
#print(r[1])
#print(self.clients_filter.value)
if r[1] == self.clients_filter.value:
row = ft.DataRow(
cells=[
@@ -455,12 +499,15 @@ class ReportOrderInPage:
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[6])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[5]
try:
total += float(r[5].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""

View File

@@ -1,4 +1,5 @@
ISO = {"EURO": "EUR", "USD": "USD", "CHF": "CHF", "GBP": "GBP"}
ALL_OPTION = "--ALL--"
def fetch_rates_for_base(base_ui: str) -> dict:
"""
@@ -46,7 +47,7 @@ class ReportOrderOutPage:
ft.DataColumn(label=ft.Text("Paid")),
ft.DataColumn(label=ft.Text("Received")),
ft.DataColumn(label=ft.Text("Profit")),
ft.DataColumn(label=ft.Text("Currency")),
#ft.DataColumn(label=ft.Text("Currency")),
],
rows=[],
border=ft.border.all(1, ft.Colors.GREY_300),
@@ -59,23 +60,25 @@ class ReportOrderOutPage:
self.clients_filter = ft.Dropdown(
options=[
ft.dropdown.Option(text = client['name'], key=client['name']) for client in self.all_clients
ft.dropdown.Option(text=ALL_OPTION, key=ALL_OPTION),
*[ft.dropdown.Option(text=client['name'], key=client['name']) for client in self.all_clients]
],
width=250,
label="Clients",
hint_text= "Select client",
on_change= self.filter_by_client
hint_text="Select client",
on_change=self.filter_by_client
)
self.clients_filter_placeholder = ft.Container(content=self.clients_filter)
self.transporters_filter = ft.Dropdown(
options=[
ft.dropdown.Option(text = transporter['name'], key=transporter['name']) for transporter in self.all_transporters
ft.dropdown.Option(text=ALL_OPTION, key=ALL_OPTION),
*[ft.dropdown.Option(text=transporter['name'], key=transporter['name']) for transporter in self.all_transporters]
],
width=250,
label="Transporters",
hint_text= "Select transporter",
on_change= self.filter_by_transporter
hint_text="Select transporter",
on_change=self.filter_by_transporter
)
self.transporters_filter_placeholder = ft.Container(content=self.transporters_filter)
@@ -232,16 +235,20 @@ class ReportOrderOutPage:
return amt / rate
# Rebuild table in base currency
self.rows_copy = list(self.rows)
#self.rows_copy = list(self.rows)
total = 0.0
self.data_table.rows.clear()
source_rows = list(self.rows_copy)
for r in self.rows_copy:
#for r in self.rows_copy:
for r in source_rows:
# r structure: [order_number, client_name, transporter_name, order_date, paid, received, profit, currency]
original_currency = r[7]
paid_base = to_base(r[4], original_currency)
received_base = to_base(r[5], original_currency)
paid_number = r[4].split(" ")[0]
paid_currency = r[4].split(" ")[1]
received_number = r[5].split(" ")[0]
received_currency = r[5].split(" ")[1]
paid_base = to_base(paid_number, paid_currency)
received_base = to_base(received_number, received_currency)
profit_base = round(float(received_base) - float(paid_base), 2)
# Update a display row (do not mutate self.rows source amounts)
@@ -251,10 +258,10 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[1])),
ft.DataCell(ft.Text(r[2])),
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(f"{paid_base:.2f}")),
ft.DataCell(ft.Text(f"{received_base:.2f}")),
ft.DataCell(ft.Text(f"{profit_base:.2f}")),
ft.DataCell(ft.Text(base)),
ft.DataCell(ft.Text(f"{paid_base:.2f} {base}")),
ft.DataCell(ft.Text(f"{received_base:.2f} {base}")),
ft.DataCell(ft.Text(f"{profit_base:.2f} {base}")),
#ft.DataCell(ft.Text(base)),
],
)
self.data_table.rows.append(row)
@@ -312,7 +319,7 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
@@ -327,25 +334,27 @@ class ReportOrderOutPage:
all_orders = self.get_orders()
total = 0
for order in all_orders:
if order['currency'] not in self.currency_list:
self.currency_list.append(order['currency'])
if len(self.currency_list) > 1:
self.convert_currency_placeholder.content=self.convert_currency
# Skip non-active orders from reports
#print(order.get('status'))
if order['currency_received'] not in self.currency_list:
self.currency_list.append(order['currency_received'])
if order['currency_paid'] not in self.currency_list:
self.currency_list.append(order['currency_paid'])
if order.get('status') != 'active':
continue
order_number = order['order_number']
client_name = self.get_client(order['client_id'])['name']
transporter_name = self.get_transporter(order['transporter_id'])['name']
order_date = order['created_at'].split("T")[0]
paid = order['paid_price']
received = order['received_price']
currency = order['currency']
paid = f"{order['paid_price']} {order['currency_paid']}"
received = f"{order['received_price']} {order['currency_received']}"
currency = order['currency_received'] if order['currency_paid'] == order['currency_received'] else ''
if len(currency)>1:
try:
profit = round(float(received) - float(paid), 2)
profit = f"{round(float(order['received_price']) - float(order['paid_price']), 2)} {currency}"
except:
profit = 0.00
profit = ''
else:
profit = ''
row = ft.DataRow(
cells=[
@@ -356,13 +365,16 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(paid)),
ft.DataCell(ft.Text(received)),
ft.DataCell(ft.Text(profit)),
ft.DataCell(ft.Text(currency)),
#ft.DataCell(ft.Text(currency)),
],
)
row_data = [order_number, client_name, transporter_name, order_date, paid, received, profit, currency]
self.rows.append(row_data)
self.data_table.rows.append(row)
total += profit
try:
total += float(profit.split(" ")[0])
except Exception:
pass
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.rows_copy = self.rows
@@ -415,11 +427,14 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
total += r[6]
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.total.update()
@@ -447,12 +462,15 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[6]
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
@@ -477,12 +495,15 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[6]
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
@@ -491,10 +512,33 @@ class ReportOrderOutPage:
def filter_by_client(self, e):
total = 0
self.data_table.rows.clear()
# If ALL or None is selected, show all rows
if self.clients_filter.value in (None, ALL_OPTION):
self.rows_copy = list(self.rows)
for r in self.rows_copy:
row = ft.DataRow(
cells=[
ft.DataCell(ft.Text(r[0])),
ft.DataCell(ft.Text(r[1])),
ft.DataCell(ft.Text(r[2])),
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.total.update()
return
buffer = []
for r in self.rows_copy:
#print(r[1])
#print(self.clients_filter.value)
if r[1] == self.clients_filter.value:
row = ft.DataRow(
cells=[
@@ -505,12 +549,15 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[6]
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
@@ -519,10 +566,33 @@ class ReportOrderOutPage:
def filter_by_transporter(self, e):
total = 0
self.data_table.rows.clear()
# If ALL or None is selected, show all rows
if self.transporters_filter.value in (None, ALL_OPTION):
self.rows_copy = list(self.rows)
for r in self.rows_copy:
row = ft.DataRow(
cells=[
ft.DataCell(ft.Text(r[0])),
ft.DataCell(ft.Text(r[1])),
ft.DataCell(ft.Text(r[2])),
ft.DataCell(ft.Text(r[3])),
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""
self.total.update()
return
buffer = []
for r in self.rows_copy:
#print(r[2])
#print(self.transporters_filter.value)
if r[2] == self.transporters_filter.value:
row = ft.DataRow(
cells=[
@@ -533,12 +603,15 @@ class ReportOrderOutPage:
ft.DataCell(ft.Text(r[4])),
ft.DataCell(ft.Text(r[5])),
ft.DataCell(ft.Text(r[6])),
ft.DataCell(ft.Text(r[7])),
#ft.DataCell(ft.Text(r[7])),
],
)
self.data_table.rows.append(row)
buffer.append(r)
total += r[6]
try:
total += float(r[6].split(" ")[0])
except Exception:
pass
self.rows_copy = buffer
self.data_table.update()
self.total.value = f"Total: {total}" if len(self.currency_list)==1 else ""

View File

@@ -298,11 +298,17 @@ class ViewOrdersIn:
self.filename = ft.Text(value=self.order['file'])
self.currency = ft.Dropdown(
self.currency_received = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value=self.order['currency'],
value=self.order['currency_received'],
)
self.currency_expenses = ft.Dropdown(
editable=True,
label="Currency",
options=self.get_currency(),
value=self.order['currency_expenses'],
)
def get_currency(self):
@@ -851,7 +857,8 @@ class ViewOrdersIn:
'unloading_addresses': unloading_addresses,
'file':self.filename.value,
'expenses': self.expenses.value,
'currency': self.currency.value
'currency_received': self.currency_received.value,
'currency_expenses': self.currency_expenses.value
}
#print(saved_data)
if self.order_number.value == None or len(self.order_number.value)==0:
@@ -1065,12 +1072,21 @@ class ViewOrdersIn:
ft.Row(
[
ft.Text("Price / Expenses", size=18, weight=ft.FontWeight.BOLD),
self.currency
],
alignment=ft.MainAxisAlignment.START
),
ft.Row(
[
self.received_price,
self.currency_received
]
),
ft.Row(
[
self.expenses,
self.currency_expenses
]
)
],
expand=2.5
)

View File

@@ -21,7 +21,8 @@ class OrdersIn:
"created_at": row[10],
"file":row[11],
"expenses": row[12],
"currency": row[13]
"currency_received": row[13],
"currency_expenses": row[14]
}
def order_point_to_dict(self, row):
@@ -44,8 +45,9 @@ class OrdersIn:
f"""
INSERT INTO orders_in
(user_id, client_id, products_description, received_price, order_number,
ldb_quantity, kg_quantity, track_reg_number, trailer_reg_number, created_at, file_name, expenses, currency)
VALUES ({self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}){returning}
ldb_quantity, kg_quantity, track_reg_number, trailer_reg_number, created_at,
file_name, expenses, currency_received, currency_expenses)
VALUES ({self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}){returning}
""",
(
data["user_id"],
@@ -60,7 +62,8 @@ class OrdersIn:
created_at,
data["file"],
data["expenses"],
data['currency']
data['currency_received'],
data['currency_expenses'],
),
)
new_id = cur.fetchone()[0] if is_postgres() else getattr(cur, "lastrowid", None)
@@ -77,7 +80,8 @@ class OrdersIn:
user_id = {self.ph}, client_id = {self.ph}, products_description = {self.ph},
received_price = {self.ph}, order_number = {self.ph},
ldb_quantity = {self.ph}, kg_quantity = {self.ph}, track_reg_number = {self.ph},
trailer_reg_number = {self.ph}, file_name = {self.ph}, expenses = {self.ph}, currency = {self.ph}
trailer_reg_number = {self.ph}, file_name = {self.ph}, expenses = {self.ph},
currency_received = {self.ph}, currency_expenses = {self.ph}
WHERE id = {self.ph}
""",
(
@@ -92,7 +96,8 @@ class OrdersIn:
data["trailer_reg_number"],
data['file'],
data['expenses'],
data['currency'],
data['currency_received'],
data['currency_expenses'],
data["id"],
),
)

View File

@@ -23,7 +23,8 @@ class OrdersOut:
"created_at": row[12],
"status": row[13],
"order_in_number": row[14],
"currency":row[15]
"currency_received":row[15],
"currency_paid": row[16]
}
def order_point_to_dict(self, row):
@@ -46,8 +47,8 @@ class OrdersOut:
f"""
INSERT INTO orders_out
(user_id, client_id, transporter_id, products_description, received_price, paid_price, order_number,
ldb_quantity, kg_quantity, track_reg_number, trailer_reg_number, created_at, order_in_number, currency)
VALUES ({self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}){returning}
ldb_quantity, kg_quantity, track_reg_number, trailer_reg_number, created_at, order_in_number, currency_received, currency_paid)
VALUES ({self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}){returning}
""",
(
data["user_id"],
@@ -63,7 +64,8 @@ class OrdersOut:
data["trailer_reg_number"],
created_at,
data['order_in_number'],
data['currency']
data['currency_received'],
data['currency_paid'],
),
)
new_id = cursor.fetchone()[0] if is_postgres() else getattr(cursor, "lastrowid", None)
@@ -79,7 +81,8 @@ class OrdersOut:
UPDATE orders_out SET client_id = {self.ph}, transporter_id = {self.ph}, products_description = {self.ph},
received_price = {self.ph}, paid_price = {self.ph}, order_number = {self.ph},
ldb_quantity = {self.ph}, kg_quantity = {self.ph}, track_reg_number = {self.ph},
trailer_reg_number = {self.ph}, order_in_number = {self.ph}, currency = {self.ph}
trailer_reg_number = {self.ph}, order_in_number = {self.ph}, currency_received = {self.ph},
currency_paid = {self.ph}
WHERE id = {self.ph}
""",
(
@@ -94,7 +97,8 @@ class OrdersOut:
data["track_reg_number"],
data["trailer_reg_number"],
data['order_in_number'],
data['currency'],
data['currency_received'],
data['currency_paid'],
data["id"],
),
)

View File

@@ -51,7 +51,8 @@ def create_order_route():
'trailer_reg_number': incoming_data["trailer_reg_number"],
'products_description': incoming_data["products_description"],
'order_in_number': incoming_data["order_in_number"],
'currency': incoming_data["currency"]
'currency_received': incoming_data["currency_received"],
'currency_paid': incoming_data["currency_paid"]
}
order_id = orders.create_order(order_data)
@@ -113,7 +114,9 @@ def update_order_route(order_id):
"trailer_reg_number": data.get("trailer_reg_number", order["trailer_reg_number"]),
"products_description": data.get("products_description", order["products_description"]),
"order_in_number": data.get("order_in_number", order["order_in_number"]),
"currency":data.get("currency", order["currency"]),
"currency_received":data.get("currency_received", order["currency_received"]),
"currency_paid":data.get("currency_paid", order["currency_paid"]),
"user_id":user_id,
})
orders.delete_points_by_order_id(order_id)

View File

@@ -34,7 +34,8 @@ def create_order_in_route():
'products_description': incoming_data["products_description"],
'file': incoming_data['file'],
'expenses': incoming_data['expenses'],
'currency': incoming_data['currency']
'currency_received': incoming_data['currency_received'],
'currency_expenses': incoming_data['currency_expenses']
}
#print(order_data)
order_id = orders.create_order(order_data)
@@ -94,7 +95,8 @@ def update_order_route(order_id):
"products_description": data.get("products_description", order["products_description"]),
"file": data.get("file", order["file"]),
"expenses": data.get("expenses", order["expenses"]),
"currency": data.get("currency", order["currency"]),
"currency_received": data.get("currency_received", order["currency_received"]),
"currency_expenses": data.get("currency_expenses", order["currency_expenses"]),
"user_id":user_id,
})

View File

@@ -1,24 +1,24 @@
-- Reset schema: drop tables first (children → parents), then recreate.
-- BEGIN TRANSACTION;
-- PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
PRAGMA foreign_keys=OFF;
-- -- Drop child tables first to avoid FK constraints
-- DROP TABLE IF EXISTS order_in_points;
-- DROP TABLE IF EXISTS order_out_points;
-- DROP TABLE IF EXISTS orders_in;
-- DROP TABLE IF EXISTS orders_out;
-- DROP TABLE IF EXISTS email;
-- DROP TABLE IF EXISTS subscriptions;
-- DROP TABLE IF EXISTS company_user_access;
-- DROP TABLE IF EXISTS destinations;
-- DROP TABLE IF EXISTS transporters;
-- DROP TABLE IF EXISTS clients;
-- DROP TABLE IF EXISTS currency;
-- DROP TABLE IF EXISTS users;
-- Drop child tables first to avoid FK constraints
DROP TABLE IF EXISTS order_in_points;
DROP TABLE IF EXISTS order_out_points;
DROP TABLE IF EXISTS orders_in;
DROP TABLE IF EXISTS orders_out;
DROP TABLE IF EXISTS email;
DROP TABLE IF EXISTS subscriptions;
DROP TABLE IF EXISTS company_user_access;
DROP TABLE IF EXISTS destinations;
DROP TABLE IF EXISTS transporters;
DROP TABLE IF EXISTS clients;
DROP TABLE IF EXISTS currency;
DROP TABLE IF EXISTS users;
-- PRAGMA foreign_keys=ON;
-- COMMIT;
PRAGMA foreign_keys=ON;
COMMIT;
-- Users table
@@ -103,7 +103,8 @@ CREATE TABLE IF NOT EXISTS orders_out (
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
order_status TEXT NOT NULL DEFAULT 'active' CHECK (order_status IN ('active', 'inactive', 'cancelled')),
order_in_number TEXT,
currency TEXT,
currency_received TEXT,
currency_paid TEXT,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(client_id) REFERENCES clients(id) ON DELETE CASCADE,
FOREIGN KEY(transporter_id) REFERENCES transporters(id) ON DELETE CASCADE
@@ -124,7 +125,8 @@ CREATE TABLE IF NOT EXISTS orders_in (
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
file_name TEXT,
expenses DOUBLE PRECISION,
currency TEXT,
currency_received TEXT,
currency_expenses TEXT,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(client_id) REFERENCES clients(id) ON DELETE CASCADE
);

View File

@@ -129,7 +129,7 @@ def generate_order_pdf(order, user_data, transporter_data, logo_path, save_to_di
["Product Description", Paragraph(str(order["products_description"]), styles["Normal"])],
["LDM", Paragraph(str(order["ldb_quantity"]), styles["Normal"])],
["KG", Paragraph(str(order["kg_quantity"]), styles["Normal"])],
["Price", Paragraph(str(order["paid_price"]), styles["Normal"])],
["Price", Paragraph(str(order["paid_price"])+ " " +order["currency_paid"], styles["Normal"])],
]
summary_table = Table(summary_data, colWidths=[150, 350])
summary_table.setStyle(TableStyle([