From a636897eeeca6eebbc5d7cd5f765b0288c9b4937 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Tue, 10 Dec 2024 17:22:19 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=94=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BC=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=B0=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/__init__.py | 6 +++-- App/Requests/requests_model.py | 28 ++---------------------- App/Requests/templates/sellers_ship.html | 8 +++---- App/Requests/templates/zagotovki.html | 8 +++---- 4 files changed, 12 insertions(+), 38 deletions(-) diff --git a/App/Requests/__init__.py b/App/Requests/__init__.py index 6c6e471..9eb706a 100644 --- a/App/Requests/__init__.py +++ b/App/Requests/__init__.py @@ -24,7 +24,8 @@ def requests(): @check_auth def sklad_zapros(): if request.method == "GET": - return render_template("zagotovki.html") + materials = materials_names() + return render_template("zagotovki.html", materials=materials) else: zagotovki = sklad(request) if zagotovki.status: @@ -39,7 +40,8 @@ def sklad_zapros(): @check_auth def sellers_ship(): if request.method == "GET": - return render_template("sellers_ship.html") + sellers = sellers_names() + return render_template("sellers_ship.html", sellers=sellers) else: zagotovki = materials_per_seller(request) if zagotovki.status: diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index 5f38c03..9ef9f07 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -15,31 +15,19 @@ class InfoRespronse: status: bool -def sellers_names() -> InfoRespronse: +def sellers_names() -> list: db_config = current_app.config["db_config"] _sql = sql_provider.get("sellers_names.sql", {}) result = select_list(db_config, _sql) - if result is None: - return InfoRespronse( - (), - error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором", - status=False, - ) return InfoRespronse(result, error_message="", status=True) -def materials_names() -> InfoRespronse: +def materials_names() -> list: db_config = current_app.config["db_config"] _sql = sql_provider.get("materials_names.sql", {}) result = select_list(db_config, _sql) - if result is None: - return InfoRespronse( - (), - error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором", - status=False, - ) return InfoRespronse(result, error_message="", status=True) @@ -49,12 +37,6 @@ def sklad(request) -> InfoRespronse: _sql = sql_provider.get("sklad_material.sql", material) result = select_list(db_config, _sql) - if result is None: - return InfoRespronse( - (), - error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором", - status=False, - ) return InfoRespronse(result, error_message="", status=True) @@ -64,10 +46,4 @@ def materials_per_seller(request) -> InfoRespronse: seller = dict(request.form) _sql = sql_provider.get("ship_seller.sql", seller) result = select_list(db_config, _sql) - if result is None: - return InfoRespronse( - (), - error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором", - status=False, - ) return InfoRespronse(result, error_message="", status=True) diff --git a/App/Requests/templates/sellers_ship.html b/App/Requests/templates/sellers_ship.html index 844a8f6..d28af81 100644 --- a/App/Requests/templates/sellers_ship.html +++ b/App/Requests/templates/sellers_ship.html @@ -33,11 +33,9 @@
diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index c36de7d..ccd1492 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -34,11 +34,9 @@
From 5bf6f4e30b87512012760f26b582a7939d6b916c Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Tue, 10 Dec 2024 17:22:37 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=BE=D0=B5=20=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=BC=D1=83=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 App/Requests/README.md diff --git a/App/Requests/README.md b/App/Requests/README.md new file mode 100644 index 0000000..2c8cf55 --- /dev/null +++ b/App/Requests/README.md @@ -0,0 +1 @@ +# Переделать первый запрос (поставки конкретной заготовки формата "кем - когда - количество") \ No newline at end of file From 8ec0cf6b589aa77e20c6856e461ea628649cad92 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Tue, 10 Dec 2024 18:09:15 +0300 Subject: [PATCH 3/8] SQL fix --- .pre-commit-config.yaml | 7 ++++++- App/Requests/sql/materials_names.sql | 6 +++++- App/Requests/sql/sklad_material.sql | 15 +++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5f2aa90..30225de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,4 +8,9 @@ repos: - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - - id: isort \ No newline at end of file + - id: isort + - repo: https://github.com/sqlfluff/sqlfluff + rev: 3.3.0 + hooks: + - id: sqlfluff-fix + args: [ --dialect=mariadb ] \ No newline at end of file diff --git a/App/Requests/sql/materials_names.sql b/App/Requests/sql/materials_names.sql index e5873a7..fe16f5b 100644 --- a/App/Requests/sql/materials_names.sql +++ b/App/Requests/sql/materials_names.sql @@ -1 +1,5 @@ -SELECT DISTINCT material FROM workpiece; \ No newline at end of file +SELECT + work_id, + name, + material +FROM workpiece; diff --git a/App/Requests/sql/sklad_material.sql b/App/Requests/sql/sklad_material.sql index 10de13c..645d5c8 100644 --- a/App/Requests/sql/sklad_material.sql +++ b/App/Requests/sql/sklad_material.sql @@ -1,4 +1,11 @@ -SELECT weight AS 'Вес', price AS 'Цена (в рублях)', -count AS 'Количество', last_update AS 'Дата последнего обновления' -FROM workpiece -WHERE material = '$material' \ No newline at end of file +SELECT + w.waybill_date AS 'Дата поставки', + s.name AS 'Поставщик', + wl.amount AS 'Количество' +FROM waybill w + +JOIN (SELECT waybill_id, work_id, amount FROM waybill_lines) wl USING(waybill_id) +JOIN (SELECT user_id, sel_id FROM external_users) eu USING(user_id) +JOIN (SELECT sel_id, name FROM sellers) s USING(sel_id) +WHERE work_id = '$id' +GROUP BY waybill_date, name; \ No newline at end of file From fe2b1fd014554605943934fae6358d7b2956f097 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Tue, 10 Dec 2024 18:19:30 +0300 Subject: [PATCH 4/8] Fixed requests --- App/Requests/__init__.py | 3 +-- App/Requests/requests_model.py | 8 ++++---- App/Requests/templates/zagotovki.html | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/App/Requests/__init__.py b/App/Requests/__init__.py index 9eb706a..3bf9da7 100644 --- a/App/Requests/__init__.py +++ b/App/Requests/__init__.py @@ -29,8 +29,7 @@ def sklad_zapros(): else: zagotovki = sklad(request) if zagotovki.status: - material = dict(request.form) - header = f'Заготовки на складе из материала "{material["material"]}"' + header = "Поставки выбранной заготовки" return render_template("output.html", items=zagotovki.result, header=header) else: return render_template("error.html", error_message=zagotovki.error_message) diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index 9ef9f07..bccd958 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -20,7 +20,7 @@ def sellers_names() -> list: _sql = sql_provider.get("sellers_names.sql", {}) result = select_list(db_config, _sql) - return InfoRespronse(result, error_message="", status=True) + return result def materials_names() -> list: @@ -28,14 +28,14 @@ def materials_names() -> list: _sql = sql_provider.get("materials_names.sql", {}) result = select_list(db_config, _sql) - return InfoRespronse(result, error_message="", status=True) + return result def sklad(request) -> InfoRespronse: db_config = current_app.config["db_config"] - material = dict(request.form) + id = dict(request.form) - _sql = sql_provider.get("sklad_material.sql", material) + _sql = sql_provider.get("sklad_material.sql", id) result = select_list(db_config, _sql) return InfoRespronse(result, error_message="", status=True) diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index ccd1492..f99600c 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -33,9 +33,9 @@
- {% for item in materials %} - + {% endfor %} From 6c435f6bb70a38e8fe8e7b197e76e14a46fe9c17 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Wed, 11 Dec 2024 15:19:27 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B3=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=20=D0=A0=D0=9F=D0=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/requests_model.py | 4 ++-- App/Requests/sql/ship_seller.sql | 1 + App/Requests/sql/sklad_material.sql | 5 +++-- App/Requests/templates/zagotovki.html | 10 +++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index bccd958..ce7c71c 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -33,9 +33,9 @@ def materials_names() -> list: def sklad(request) -> InfoRespronse: db_config = current_app.config["db_config"] - id = dict(request.form) + workpiece = dict(request.form) - _sql = sql_provider.get("sklad_material.sql", id) + _sql = sql_provider.get("sklad_material.sql", workpiece) result = select_list(db_config, _sql) return InfoRespronse(result, error_message="", status=True) diff --git a/App/Requests/sql/ship_seller.sql b/App/Requests/sql/ship_seller.sql index 11edb10..db16924 100644 --- a/App/Requests/sql/ship_seller.sql +++ b/App/Requests/sql/ship_seller.sql @@ -2,6 +2,7 @@ SELECT w.waybill_date AS 'Дата поставки', SUM(w.total) AS 'Общая сумма (в рублях)', SUM(wl.amount) as 'Общее количество заготовок' FROM waybill w + JOIN (SELECT waybill_id, SUM(amount) AS amount FROM waybill_lines wl GROUP BY waybill_id)wl USING (waybill_id) JOIN (SELECT user_id, sel_id FROM external_users) eu USING(user_id) JOIN (SELECT sel_id, name FROM sellers) s USING(sel_id) diff --git a/App/Requests/sql/sklad_material.sql b/App/Requests/sql/sklad_material.sql index 645d5c8..14f8729 100644 --- a/App/Requests/sql/sklad_material.sql +++ b/App/Requests/sql/sklad_material.sql @@ -1,5 +1,6 @@ SELECT - w.waybill_date AS 'Дата поставки', + DATE_FORMAT(w.waybill_date, '%Y-%m-%d') AS 'Дата поставки', + TIME_FORMAT(w.waybill_date, '%H:%i') AS 'Время поставки', s.name AS 'Поставщик', wl.amount AS 'Количество' FROM waybill w @@ -7,5 +8,5 @@ FROM waybill w JOIN (SELECT waybill_id, work_id, amount FROM waybill_lines) wl USING(waybill_id) JOIN (SELECT user_id, sel_id FROM external_users) eu USING(user_id) JOIN (SELECT sel_id, name FROM sellers) s USING(sel_id) -WHERE work_id = '$id' +WHERE work_id = '$workpiece' GROUP BY waybill_date, name; \ No newline at end of file diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index f99600c..b6034d4 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -2,7 +2,7 @@ - Количество заготовок на складе + Поставки заготовок на склад
-

Количество заготовок на складе

+

Поставки заготовок на склад

@@ -32,10 +32,10 @@
- - {% for item in materials %} - + {% endfor %} From 5505d4bb2a448c4e54475adc0530c5a8026f3feb Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Wed, 11 Dec 2024 23:42:22 +0300 Subject: [PATCH 6/8] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B3=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=20=D0=A0=D0=9F=D0=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Report/sql/sellers_report.sql | 7 ++++--- App/Report/sql/workpiece_report.sql | 8 ++++---- App/Requests/README.md | 1 - App/Requests/sql/ship_seller.sql | 3 ++- App/Requests/templates/zagotovki.html | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 App/Requests/README.md diff --git a/App/Report/sql/sellers_report.sql b/App/Report/sql/sellers_report.sql index b02253a..49855a7 100644 --- a/App/Report/sql/sellers_report.sql +++ b/App/Report/sql/sellers_report.sql @@ -1,8 +1,9 @@ SELECT s.name AS Поставщик, - SUM(reports.count) AS 'Количество поставок', - SUM(reports.sum) AS Сумма + reports.sum AS 'Сумма в рублях', + reports.count AS 'Количество поставок' FROM reports JOIN sellers s ON reports.item_id = s.sel_id WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year') -GROUP BY s.name; \ No newline at end of file +GROUP BY s.name +ORDER BY s.name; \ No newline at end of file diff --git a/App/Report/sql/workpiece_report.sql b/App/Report/sql/workpiece_report.sql index e35c331..6abe547 100644 --- a/App/Report/sql/workpiece_report.sql +++ b/App/Report/sql/workpiece_report.sql @@ -1,8 +1,8 @@ SELECT w.name AS Наименование, - w.material AS Материал, - sum(sum) AS Сумма, - sum(reports.count) AS Количество + reports.sum AS 'Сумма в рублях', + reports.count AS 'Количество поставленных заготовок' from reports JOIN workpiece w ON reports.item_id = w.work_id WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year') -GROUP BY w.material, w.name; \ No newline at end of file +GROUP BY w.material, w.name +ORDER BY w.name; \ No newline at end of file diff --git a/App/Requests/README.md b/App/Requests/README.md deleted file mode 100644 index 2c8cf55..0000000 --- a/App/Requests/README.md +++ /dev/null @@ -1 +0,0 @@ -# Переделать первый запрос (поставки конкретной заготовки формата "кем - когда - количество") \ No newline at end of file diff --git a/App/Requests/sql/ship_seller.sql b/App/Requests/sql/ship_seller.sql index db16924..f97bfb8 100644 --- a/App/Requests/sql/ship_seller.sql +++ b/App/Requests/sql/ship_seller.sql @@ -1,4 +1,5 @@ -SELECT w.waybill_date AS 'Дата поставки', +SELECT DATE_FORMAT(w.waybill_date, '%Y-%m-%d') AS 'Дата поставки', + TIME_FORMAT(w.waybill_date, '%H:%i') AS 'Время поставки', SUM(w.total) AS 'Общая сумма (в рублях)', SUM(wl.amount) as 'Общее количество заготовок' FROM waybill w diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index b6034d4..56f1c6f 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -35,7 +35,7 @@ From 42de5a02e465bdfb2a4a1bbc5f9297e6fe16461c Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 12 Dec 2024 10:18:28 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/__init__.py | 8 ++++---- App/Requests/requests_model.py | 6 +++--- .../sql/{sklad_material.sql => sklad_workpiece.sql} | 0 .../sql/{materials_names.sql => workpiece_names.sql} | 0 App/Requests/templates/zagotovki.html | 2 +- App/Requests/zapros_menu.json | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) rename App/Requests/sql/{sklad_material.sql => sklad_workpiece.sql} (100%) rename App/Requests/sql/{materials_names.sql => workpiece_names.sql} (100%) diff --git a/App/Requests/__init__.py b/App/Requests/__init__.py index 3bf9da7..bcc3027 100644 --- a/App/Requests/__init__.py +++ b/App/Requests/__init__.py @@ -4,8 +4,8 @@ from os import path from checker import check_auth from flask import Blueprint, render_template, request, url_for -from .requests_model import (materials_names, materials_per_seller, - sellers_names, sklad) +from .requests_model import (materials_per_seller, sellers_names, sklad, + workpiece_names) with open(path.join(path.dirname(__file__), "zapros_menu.json"), encoding="utf-8") as f: requests_list = json.load(f) @@ -24,8 +24,8 @@ def requests(): @check_auth def sklad_zapros(): if request.method == "GET": - materials = materials_names() - return render_template("zagotovki.html", materials=materials) + workpiece = workpiece_names() + return render_template("zagotovki.html", workpiece=workpiece) else: zagotovki = sklad(request) if zagotovki.status: diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index ce7c71c..c70f707 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -23,10 +23,10 @@ def sellers_names() -> list: return result -def materials_names() -> list: +def workpiece_names() -> list: db_config = current_app.config["db_config"] - _sql = sql_provider.get("materials_names.sql", {}) + _sql = sql_provider.get("workpiece_names.sql", {}) result = select_list(db_config, _sql) return result @@ -35,7 +35,7 @@ def sklad(request) -> InfoRespronse: db_config = current_app.config["db_config"] workpiece = dict(request.form) - _sql = sql_provider.get("sklad_material.sql", workpiece) + _sql = sql_provider.get("sklad_workpiece.sql", workpiece) result = select_list(db_config, _sql) return InfoRespronse(result, error_message="", status=True) diff --git a/App/Requests/sql/sklad_material.sql b/App/Requests/sql/sklad_workpiece.sql similarity index 100% rename from App/Requests/sql/sklad_material.sql rename to App/Requests/sql/sklad_workpiece.sql diff --git a/App/Requests/sql/materials_names.sql b/App/Requests/sql/workpiece_names.sql similarity index 100% rename from App/Requests/sql/materials_names.sql rename to App/Requests/sql/workpiece_names.sql diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index 56f1c6f..4d0bdbe 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -34,7 +34,7 @@ diff --git a/App/Requests/zapros_menu.json b/App/Requests/zapros_menu.json index 45c1b4b..ed56bd7 100644 --- a/App/Requests/zapros_menu.json +++ b/App/Requests/zapros_menu.json @@ -1,4 +1,4 @@ [ - {"name": "Количество заготовок на складе", "url": "requests_bp.sklad_zapros"}, - {"name": "Поставки поставщиками", "url": "requests_bp.sellers_ship"} + {"name": "Поставки заготовок", "url": "requests_bp.sklad_zapros"}, + {"name": "Работа поставщиков", "url": "requests_bp.sellers_ship"} ] \ No newline at end of file From 773ff54dceb2fec53ab97d2d053b59c34c5e59ea Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 12 Dec 2024 11:21:07 +0300 Subject: [PATCH 8/8] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/sql/workpiece_names.sql | 2 +- App/Requests/templates/zagotovki.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/App/Requests/sql/workpiece_names.sql b/App/Requests/sql/workpiece_names.sql index fe16f5b..4251f0f 100644 --- a/App/Requests/sql/workpiece_names.sql +++ b/App/Requests/sql/workpiece_names.sql @@ -1,5 +1,5 @@ SELECT work_id, name, - material + price FROM workpiece; diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index 4d0bdbe..bac2fae 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -35,7 +35,7 @@