On 2024-04-10, Lawrence D'Oliveiro <
ldo@nz.invalid> wrote:
On Tue, 9 Apr 2024 15:22:25 +0200, David Brown wrote:
>
You could try doing what almost every other Python programmer does - use
smaller functions and drop the silly line continuations.
>
Fine. Try that with the example I gave.
Maybe you have a Python-coding niece or nephew in the fifth grade who can
reformat it for you?
Meanwhile:
Pass 1:
def fill_in_depreciations(tax_year) :
"""
(re)inserts depreciation entries for the specified tax year,
based on currently-entered assets.
"""
sql.cursor.execute("delete from payments where kind = %s and tax_year = %s",
["D", tax_year])
for entry in get_each_record(table_name = "assets, asset_depreciations",
fields = [
"assets.description as description",
"assets.initial_value as initial_value",
"assets.when_purchased as when_purchased",
"assets.depreciation_rate as rate",
"assets.depreciation_method as method",
"asset_depreciations.depreciation_amount as amount",
],
condition = "assets.asset_id = asset_depreciations.asset_id and"
" asset_depreciations.tax_year = %s",
values = [tax_year]):
sql.cursor.execute("insert into payments set when_made = %(when_made)s,"
" description = %(description)s, other_party_name = \"\","
" amount = %(amount)d, kind = \"D\", tax_year = %(tax_year)d"
% { "when_made" : end_for_tax_year(tax_year) - 1,
"description" : sql_string("%s: %s $%s at %d%% from %s" %
(entry["description"],
entry["method"],
format_amount(entry["initial_value"]),
entry["rate"],
format_date(entry["when_purchased"]))),
"amount" : - entry["amount"],
"tax_year" : tax_year })
Pass 2: fits into 80 cols and everything:
def fill_in_depreciations(tax_year) :
"""
(re)inserts depreciation entries for the specified tax year,
based on currently-entered assets."
"""
table = "assets, asset_depreciations"
fields = ["assets.description as description",
"assets.initial_value as initial_value",
"assets.when_purchased as when_purchased",
"assets.depreciation_rate as rate",
"assets.depreciation_method as method",
"asset_depreciations.depreciation_amount as amount"]
condition = ("assets.asset_id = asset_depreciations.asset_id and"
" asset_depreciations.tax_year = %s")
insert = ("insert into payments set when_made = %(when_made)s,"
" description = %(description)s, other_party_name = \"\","
" amount = %(amount)d, kind = \"D\", tax_year = %(tax_year)d")
sql.cursor.execute("delete from payments where kind = %s and tax_year = %s",
["D", tax_year])
for entry in get_each_record(table_name = table_name, fields = fields,
condition = condition, values = [tax_year]):
desc = sql_string("%s: %s $%s at %d%% from %s" %
(entry["description"],
entry["method"],
format_amount(entry["initial_value"]),
entry["rate"],
format_date(entry["when_purchased"])))
sql.cursor.execute(insert %
{"when_made" : end_for_tax_year(tax_year) - 1,
"description" : desc,
"amount" : - entry["amount"],
"tax_year" : tax_year})
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca