Update price class to use sku as primary key of item

This commit is contained in:
Dita Aji Pratama 2025-02-28 20:44:20 +07:00
parent 0121f3fcd0
commit 05373a86fa
5 changed files with 15 additions and 15 deletions

View File

@ -12,10 +12,10 @@ post {
body:json { body:json {
{ {
"item":2, "sku":"TEST-001",
"type":"sell", "type":"sell",
"currency":"IDR", "currency":"IDR",
"value":3600000, "value":36000,
"periods":"2025-01-01 18:32:35" "periods":"2025-01-01 18:32:35"
} }
} }

View File

@ -11,5 +11,5 @@ post {
} }
body:json { body:json {
{"id":5} {"id":1}
} }

View File

@ -12,11 +12,11 @@ post {
body:json { body:json {
{ {
"id":5, "id":1,
"item":2, "sku":"TEST-001",
"type":"sell", "type":"buy",
"currency":"IDR", "currency":"IDR",
"value":999999, "value":20000,
"periods":"2025-01-01 18:32:35" "periods":"2025-01-01 18:32:35"
} }
} }

View File

@ -12,6 +12,6 @@ post {
body:json { body:json {
{ {
"id":5 "id":1
} }
} }

View File

@ -14,7 +14,7 @@ class price:
response = {} response = {}
self.cursor.execute("BEGIN;") self.cursor.execute("BEGIN;")
try: try:
self.cursor.execute("SELECT `id`, `item`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` ORDER BY periods DESC, id DESC;") self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` ORDER BY periods DESC, id DESC;")
ls = self.cursor.fetchall() ls = self.cursor.fetchall()
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success" response["status" ] = "success"
@ -39,7 +39,7 @@ class price:
id = params["id"] id = params["id"]
self.cursor.execute("BEGIN;") self.cursor.execute("BEGIN;")
try: try:
self.cursor.execute("SELECT `id`, `item`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` WHERE id= %s ORDER BY periods DESC, id DESC;", (id,)) self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` WHERE id= %s ORDER BY periods DESC, id DESC;", (id,))
data = self.cursor.fetchone() data = self.cursor.fetchone()
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success" response["status" ] = "success"
@ -61,7 +61,7 @@ class price:
APIADDR = "/api/invlab/price/add" APIADDR = "/api/invlab/price/add"
response = {} response = {}
loggorilla.prcss(APIADDR, "Define parameters") loggorilla.prcss(APIADDR, "Define parameters")
item = params["item" ] sku = params["sku" ]
type = params["type" ] type = params["type" ]
currency = params["currency" ] currency = params["currency" ]
value = params["value" ] value = params["value" ]
@ -69,7 +69,7 @@ class price:
self.cursor.execute("BEGIN;") self.cursor.execute("BEGIN;")
try: try:
loggorilla.prcss(APIADDR, "Inserting") loggorilla.prcss(APIADDR, "Inserting")
self.cursor.execute("INSERT INTO `item_price` VALUES (DEFAULT, %s, %s, %s, %s, %s) ;", (item, type, currency, value, periods) ) self.cursor.execute("INSERT INTO `item_price` VALUES (DEFAULT, %s, %s, %s, %s, %s) ;", (sku, type, currency, value, periods) )
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success" response["status" ] = "success"
response["desc" ] = "data added" response["desc" ] = "data added"
@ -78,7 +78,7 @@ class price:
loggorilla.error(APIADDR, str(e) ) loggorilla.error(APIADDR, str(e) )
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "failed" response["status" ] = "failed"
response["desc" ] = "Internal Server Error. Please contact us if you still have an error." response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
finally: finally:
self.cursor.execute("COMMIT;") self.cursor.execute("COMMIT;")
self.cursor.close() self.cursor.close()
@ -90,7 +90,7 @@ class price:
response = {} response = {}
loggorilla.prcss(APIADDR, "Define parameters") loggorilla.prcss(APIADDR, "Define parameters")
key = params["id" ] key = params["id" ]
item = params["item" ] sku = params["sku" ]
type = params["type" ] type = params["type" ]
currency = params["currency" ] currency = params["currency" ]
value = params["value" ] value = params["value" ]
@ -98,7 +98,7 @@ class price:
self.cursor.execute("BEGIN;") self.cursor.execute("BEGIN;")
try: try:
loggorilla.prcss(APIADDR, "Updating") loggorilla.prcss(APIADDR, "Updating")
self.cursor.execute("UPDATE `item_price` SET `item` = %s,`type` = %s,`currency` = %s,`value` = %s,`periods` = %s WHERE `id` = %s ;", (item, type, currency, value, periods, key) ) self.cursor.execute("UPDATE `item_price` SET `sku` = %s,`type` = %s,`currency` = %s,`value` = %s,`periods` = %s WHERE `id` = %s ;", (sku, type, currency, value, periods, key) )
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success" response["status" ] = "success"
response["desc" ] = "data change" response["desc" ] = "data change"