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

@@ -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([