forked from brmlab/brmbar-github
Use account loading stored procedure for Account construction.
This commit is contained in:
parent
38a4a3def1
commit
89fb60bab5
1 changed files with 12 additions and 14 deletions
|
|
@ -20,24 +20,22 @@ class Account:
|
|||
@classmethod
|
||||
def load_by_barcode(cls, db, barcode):
|
||||
logger.debug("load_by_barcode: '%s'", barcode)
|
||||
res = db.execute_and_fetch(
|
||||
"SELECT account FROM barcodes WHERE barcode = %s", [barcode]
|
||||
)
|
||||
if res is None:
|
||||
return None
|
||||
id = res[0]
|
||||
return cls.load(db, id=id)
|
||||
account_id, account_name, account_acctype, currency_id, currency_name = db_execute_and_fetch(
|
||||
"SELECT account_id, account_name, account_acctype, currency_id, currency_name
|
||||
FROM public.account_class_initialization_data('by_barcode', NULL, %s)",
|
||||
[barcode])
|
||||
currency = Currency(db, currency_id, currency_name)
|
||||
return cls(db, account_id, account_name, currency, account_acctype)
|
||||
|
||||
@classmethod
|
||||
def load(cls, db, id=None):
|
||||
"""Constructor for existing account"""
|
||||
if id is None:
|
||||
raise NameError("Account.load(): Specify id")
|
||||
name, currid, acctype = db.execute_and_fetch(
|
||||
"SELECT name, currency, acctype FROM accounts WHERE id = %s", [id]
|
||||
)
|
||||
currency = Currency.load(db, id=currid)
|
||||
return cls(db, name=name, id=id, currency=currency, acctype=acctype)
|
||||
account_id, account_name, account_acctype, currency_id, currency_name = db_execute_and_fetch(
|
||||
"SELECT account_id, account_name, account_acctype, currency_id, currency_name
|
||||
FROM public.account_class_initialization_data('by_id', %s, NULL)",
|
||||
[id])
|
||||
currency = Currency(db, currency_id, currency_name)
|
||||
return cls(db, account_id, account_name, currency, account_acctype)
|
||||
|
||||
@classmethod
|
||||
def create(cls, db, name, currency, acctype):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue