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
|
@classmethod
|
||||||
def load_by_barcode(cls, db, barcode):
|
def load_by_barcode(cls, db, barcode):
|
||||||
logger.debug("load_by_barcode: '%s'", barcode)
|
logger.debug("load_by_barcode: '%s'", barcode)
|
||||||
res = db.execute_and_fetch(
|
account_id, account_name, account_acctype, currency_id, currency_name = db_execute_and_fetch(
|
||||||
"SELECT account FROM barcodes WHERE barcode = %s", [barcode]
|
"SELECT account_id, account_name, account_acctype, currency_id, currency_name
|
||||||
)
|
FROM public.account_class_initialization_data('by_barcode', NULL, %s)",
|
||||||
if res is None:
|
[barcode])
|
||||||
return None
|
currency = Currency(db, currency_id, currency_name)
|
||||||
id = res[0]
|
return cls(db, account_id, account_name, currency, account_acctype)
|
||||||
return cls.load(db, id=id)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, db, id=None):
|
def load(cls, db, id=None):
|
||||||
"""Constructor for existing account"""
|
"""Constructor for existing account"""
|
||||||
if id is None:
|
account_id, account_name, account_acctype, currency_id, currency_name = db_execute_and_fetch(
|
||||||
raise NameError("Account.load(): Specify id")
|
"SELECT account_id, account_name, account_acctype, currency_id, currency_name
|
||||||
name, currid, acctype = db.execute_and_fetch(
|
FROM public.account_class_initialization_data('by_id', %s, NULL)",
|
||||||
"SELECT name, currency, acctype FROM accounts WHERE id = %s", [id]
|
[id])
|
||||||
)
|
currency = Currency(db, currency_id, currency_name)
|
||||||
currency = Currency.load(db, id=currid)
|
return cls(db, account_id, account_name, currency, account_acctype)
|
||||||
return cls(db, name=name, id=id, currency=currency, acctype=acctype)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, db, name, currency, acctype):
|
def create(cls, db, name, currency, acctype):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue