Skip to content

Commit

Permalink
Testing dbupdate code. #1659
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdspencer77 committed Feb 24, 2025
1 parent 57d1b24 commit 164439e
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 46 deletions.
63 changes: 59 additions & 4 deletions src/asm3/dbupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,19 @@ def fclob(name: str, nullable: bool = True) -> str:

sql += table("lkcoattype", (
fid(), fstr("CoatType") ), False)

sql += table("lkproducttype", (
fid(),
fstr("ProductTypeName"),
fstr("Description"),
fint("IsRetired") ), False)

sql += table("lktaxrate", (
fid(),
fstr("TaxRateName"),
fstr("Description"),
ffloat("TaxRate"),
fint("IsRetired") ), False)

sql += table("lksex", (
fid(), fstr("Sex") ), False)
Expand Down Expand Up @@ -1410,6 +1423,7 @@ def fclob(name: str, nullable: bool = True) -> str:
fint("IsRetailer", True),
fint("IsVet", True),
fint("IsGiftAid", True),
fint("IsSupplier", True),
fstr("ExtraIDs", True),
flongstr("AdditionalFlags", True),
flongstr("HomeCheckAreas", True),
Expand Down Expand Up @@ -1474,6 +1488,7 @@ def fclob(name: str, nullable: bool = True) -> str:
sql += index("owner_IsVolunteer", "owner", "IsVolunteer")
sql += index("owner_ExtraIDs", "owner", "ExtraIDs")
sql += index("owner_IsSponsor", "owner", "IsSponsor")
sql += index("owner_IsSupplier", "owner", "IsSupplier")

sql += table("ownercitation", (
fid(),
Expand Down Expand Up @@ -1629,6 +1644,32 @@ def fclob(name: str, nullable: bool = True) -> str:
fint("NextID") ), False)
sql += index("primarykey_TableName", "primarykey", "TableName")

sql += table("product", (
fid(),
fstr("ProductName"),
fstr("Description"),
fint("ProductType"),
fint("SupplierID"),
fint("UnitType"),
fstr("CustomUnit"),
fint("PurchaseTypeUnit"),
fstr("CustomPurchaseUnit"),
fint("CostPrice"),
fint("RetailPrice"),
fint("UnitRatio"),
fint("TaxRate"),
fstr("Barcode"),
fstr("PLU"),
fstr("RecentBatchNo"),
fstr("RecentExpiry"),
fint("RecordVersion"),
fstr("CreatedBy"),
fdate("CreatedDate"),
fstr("LastChangedBy"),
fdate("LastChangedDate"),
fint("IsRetired") ), False)
sql += index("product_SupplierID", "product", "SupplierID")

sql += table("publishlog", (
fid(),
fdate("PublishDateTime"),
Expand Down Expand Up @@ -1675,13 +1716,15 @@ def fclob(name: str, nullable: bool = True) -> str:
fstr("BatchNumber", True),
fint("Cost", True),
fint("UnitPrice", True),
fint("ProductID", True),
fdate("CreatedDate")
), False)
sql += index("stocklevel_Name", "stocklevel", "Name")
sql += index("stocklevel_UnitName", "stocklevel", "UnitName")
sql += index("stocklevel_StockLocationID", "stocklevel", "StockLocationID")
sql += index("stocklevel_Expiry", "stocklevel", "Expiry")
sql += index("stocklevel_BatchNumber", "stocklevel", "BatchNumber")
sql += index("stocklevel_ProductID", "stocklevel", "ProductID")

sql += table("stocklocation", (
fid(),
Expand Down Expand Up @@ -1770,7 +1813,10 @@ def fclob(name: str, nullable: bool = True) -> str:
fint("SiteID", True),
fint("DisableLogin", True),
fstr("LocationFilter", True),
fint("DefaultStockLocationID"),
fint("DefaultStockUsageTypeID"),
fint("RecordVersion", True)), False)

sql += index("users_UserName", "users", "UserName")

sql += table("userrole", (
Expand Down Expand Up @@ -1827,6 +1873,10 @@ def role(tid: int, name: str, perms: str) -> str:
return "INSERT INTO role (ID, Rolename, SecurityMap) VALUES (%s, '%s', '%s')|=\n" % (tid, dbo.escape(name), perms)
def species(tid: int, name: str, petfinder: str) -> str:
return "INSERT INTO species (ID, SpeciesName, SpeciesDescription, PetFinderSpecies, IsRetired) VALUES (%s, '%s', '', '%s', 0)|=\n" % ( tid, dbo.escape(name), petfinder )

def taxrate(tid: int, name: str, taxrate: float) -> str:
return "INSERT INTO lktaxrate (ID, TaxRateName, Description, TaxRate, IsRetired) VALUES (%s, '%s', '', %f, 0)" % ( tid, name, "", taxrate, 0 )

def user(tid: int, username: str, realname: str, password: str, superuser: bool) -> str:
return "INSERT INTO users (ID, UserName, RealName, EmailAddress, Password, SuperUser, OwnerID, SecurityMap, IPRestriction, Signature, LocaleOverride, ThemeOverride, SiteID, DisableLogin, LocationFilter, RecordVersion) VALUES (%s,'%s','%s', '', 'plain:%s', %s, 0,'', '', '', '', '', 0, 0, '', 0)|=\n" % (tid, username, realname, password, superuser and 1 or 0)

Expand Down Expand Up @@ -2621,6 +2671,7 @@ def user(tid: int, username: str, realname: str, password: str, superuser: bool)
sql += medicalprofile(3, _("Deflea", l), _("{0} Pipette", l).format(1))
sql += medicalprofile(4, _("Wormer", l), _("{0} Tablet", l).format(1))
sql += lookup2("pickuplocation", "LocationName", 1, _("Shelter", l))
sql += lookup2("lkproducttype", "ProductTypeName", 1, _("General", l))
sql += lookup2("reservationstatus", "StatusName", 1, _("More Info Needed", l))
sql += lookup2("reservationstatus", "StatusName", 2, _("Pending Vet Check", l))
sql += lookup2("reservationstatus", "StatusName", 3, _("Pending Apartment Verification", l))
Expand Down Expand Up @@ -2666,6 +2717,8 @@ def user(tid: int, username: str, realname: str, password: str, superuser: bool)
sql += lookup2("stockusagetype", "UsageTypeName", 5, _("Sold", l))
sql += lookup2("stockusagetype", "UsageTypeName", 6, _("Stocktake", l))
sql += lookup2("stockusagetype", "UsageTypeName", 7, _("Wasted", l))
sql += lookup2("stockusagetype", "UsageTypeName", 8, _("Movement", l))
sql += taxrate(1, _("Tax Free", l), 0.0)
sql += lookup2("testresult", "ResultName", 1, _("Unknown", l))
sql += lookup2("testresult", "ResultName", 2, _("Negative", l))
sql += lookup2("testresult", "ResultName", 3, _("Positive", l))
Expand Down Expand Up @@ -6421,7 +6474,7 @@ def update_34907(dbo: Database) -> None:

def update_35000(dbo: Database) -> None:
l = dbo.locale
# Add extra column to person
# Add extra column to owner table
add_column(dbo, "owner", "IsSupplier", dbo.type_integer)
add_index(dbo, "owner_IsSupplier", "owner", "IsSupplier")
dbo.execute_dbupdate("UPDATE owner SET IsSupplier=0")
Expand All @@ -6441,7 +6494,6 @@ def update_35000(dbo: Database) -> None:
dbo.ddl_add_table_column("RetailPrice", dbo.type_integer, False),
dbo.ddl_add_table_column("UnitRatio", dbo.type_integer, False),
dbo.ddl_add_table_column("TaxRate", dbo.type_integer, False),
dbo.ddl_add_table_column("IsRetired", dbo.type_integer, False),
dbo.ddl_add_table_column("Barcode", dbo.type_shorttext, False),
dbo.ddl_add_table_column("PLU", dbo.type_shorttext, False),
dbo.ddl_add_table_column("RecentBatchNo", dbo.type_shorttext, False),
Expand All @@ -6450,10 +6502,11 @@ def update_35000(dbo: Database) -> None:
dbo.ddl_add_table_column("CreatedBy", dbo.type_shorttext, False),
dbo.ddl_add_table_column("CreatedDate", dbo.type_datetime, False),
dbo.ddl_add_table_column("LastChangedBy", dbo.type_shorttext, False),
dbo.ddl_add_table_column("LastChangedDate", dbo.type_datetime, False)
dbo.ddl_add_table_column("LastChangedDate", dbo.type_datetime, False),
dbo.ddl_add_table_column("IsRetired", dbo.type_integer, False)
])
dbo.execute_dbupdate( dbo.ddl_add_table("product", fields) )
#add_index(dbo, "ownerrole_OwnerIDRoleID", "ownerrole", "OwnerID,RoleID", unique=True)
add_index(dbo, "product_SupplierID", "product", "SupplierID")

# Add the lkproducttype table
fields = ",".join([
Expand Down Expand Up @@ -6497,4 +6550,6 @@ def update_35000(dbo: Database) -> None:

# Adding ProductID columns to stocklevel table
add_column(dbo, "stocklevel", "ProductID", dbo.type_integer)
add_index(dbo, "stocklevel_ProductID", "stocklevel", "ProductID")


9 changes: 9 additions & 0 deletions src/asm3/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,15 @@
"Albino or Red-Eyed White"
)

UNITTYPES = (
{"ID": 1, "UNIT": "kg"},
{"ID": 2, "UNIT": "g"},
{"ID": 3, "UNIT": "lb"},
{"ID": 4, "UNIT": "oz"},
{"ID": 5, "UNIT": "l"},
{"ID": 6, "UNIT": "ml"}
)

def add_message(dbo: Database, createdby: str, email: int, message: str, forname: str = "*",
priority: int = 0, expires: datetime = None, added: datetime = None) -> int:
if added is None: added = dbo.today()
Expand Down
27 changes: 22 additions & 5 deletions src/asm3/stock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import asm3.utils
import asm3.lookups
from asm3.i18n import _, now, python2display
from asm3.typehints import datetime, Database, List, PostedData, ResultRow, Results

Expand All @@ -12,18 +13,34 @@ def get_products(dbo: Database, includeretired=False) -> Results:
"""
Returns all products
"""
unitsql = ""
for unitdict in asm3.lookups.UNITTYPES:
unitsql = unitsql + "WHEN product.UnitType = %s THEN '%s' " % (str(unitdict["ID"]), unitdict["UNIT"])
sql = "SELECT product.*, " \
"(SELECT SUM(Balance) FROM stocklevel WHERE ProductID = product.ID) AS Balance, " \
"CASE " \
"WHEN product.UnitType = 0 THEN '%s' " \
"WHEN product.UnitType = -1 THEN product.CustomUnit " \
"%s" \
"ELSE product.CustomUnit " \
"END AS Unit " \
"FROM product " \
"WHERE IsRetired = %s " \
"ORDER BY ProductName" % (_("unit"), unitsql, int(includeretired))

pass

return dbo.query("SELECT product.*, " \
"(SELECT SUM(Balance) FROM stocklevel WHERE ProductID = product.ID) AS Balance, " \
"CASE " \
"WHEN product.UnitType = 1 THEN 'kg' " \
"WHEN product.UnitType = 2 THEN 'g' " \
"WHEN product.UnitType = 3 THEN 'l' " \
"WHEN product.UnitType = 4 THEN 'ml' " \
"WHEN product.UnitType = 0 THEN '%s' " \
"WHEN product.UnitType = -1 THEN product.CustomUnit " \
"%s" \
"ELSE product.CustomUnit " \
"END AS Unit " \
"FROM product " \
"WHERE IsRetired = %s " \
"ORDER BY ProductName" % (int(includeretired),))
"ORDER BY ProductName" % (_("unit"), unitsql, int(includeretired),))

def get_stock_movements(dbo: Database, productid: int = 0) -> Results:
"""
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6698,6 +6698,7 @@ def controller(self, o):
"stocklocations": asm3.lookups.get_stock_locations(dbo),
"stockusagetypes": asm3.lookups.get_stock_usage_types(dbo),
"sortexp": o.post.integer("sortexp") == 1, # Don't know what this does - Adam
"units": asm3.lookups.UNITTYPES,
"rows": products
}

Expand Down
4 changes: 2 additions & 2 deletions src/static/js/change_user_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ $(function() {
$(".enable2fa, .disable2fa").hide();
$("#button-enable2fa").toggle(u.ENABLETOTP == 0);
$("#button-disable2fa").toggle(u.ENABLETOTP == 1);
$("#defaultlocationid").select("value", u.DEFAULTSTOCKLOCATIONID)
$("#defaultstockusagetypeid").select("value", u.DEFAULTSTOCKUSAGETYPEID)
$("#defaultlocationid").select("value", u.DEFAULTSTOCKLOCATIONID);
$("#defaultstockusagetypeid").select("value", u.DEFAULTSTOCKUSAGETYPEID);
let userql = config.str(asm.user + "_QuicklinksID");
if (userql == "") { userql = config.str("QuicklinksID"); }
let ql = userql.split(",");
Expand Down
2 changes: 1 addition & 1 deletion src/static/js/lookups.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $(function() {
{ hideif: function() { return !controller.hasvat; },
json_field: "ISVAT", post_field: "vat", label: _("Sales Tax"), type: "select",
options: '<option value="0">' + _("No") + '</option><option value="1">' + _("Yes") + '</option>' },
{ hideif: function() { return !controller.hastaxrate },
{ hideif: function() { return !controller.hastaxrate; },
json_field: "TAXRATE", post_field: "taxrate", label: _("Tax Rate"), type: "number",
callout: _("Rate of tax to be applied") },
{ hideif: function() { return controller.descfield == ""; },
Expand Down
Loading

0 comments on commit 164439e

Please sign in to comment.