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 {
{
"item":2,
"sku":"TEST-001",
"type":"sell",
"currency":"IDR",
"value":3600000,
"value":36000,
"periods":"2025-01-01 18:32:35"
}
}

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ class price:
response = {}
self.cursor.execute("BEGIN;")
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()
loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success"
@ -39,7 +39,7 @@ class price:
id = params["id"]
self.cursor.execute("BEGIN;")
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()
loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success"
@ -61,7 +61,7 @@ class price:
APIADDR = "/api/invlab/price/add"
response = {}
loggorilla.prcss(APIADDR, "Define parameters")
item = params["item" ]
sku = params["sku" ]
type = params["type" ]
currency = params["currency" ]
value = params["value" ]
@ -69,7 +69,7 @@ class price:
self.cursor.execute("BEGIN;")
try:
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")
response["status" ] = "success"
response["desc" ] = "data added"
@ -78,7 +78,7 @@ class price:
loggorilla.error(APIADDR, str(e) )
loggorilla.prcss(APIADDR, "Giving response")
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:
self.cursor.execute("COMMIT;")
self.cursor.close()
@ -90,7 +90,7 @@ class price:
response = {}
loggorilla.prcss(APIADDR, "Define parameters")
key = params["id" ]
item = params["item" ]
sku = params["sku" ]
type = params["type" ]
currency = params["currency" ]
value = params["value" ]
@ -98,7 +98,7 @@ class price:
self.cursor.execute("BEGIN;")
try:
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")
response["status" ] = "success"
response["desc" ] = "data change"