Skip to content

Commit

Permalink
Bond russian tax report handling was improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed May 24, 2024
1 parent 98adcc0 commit 8728dd3
Show file tree
Hide file tree
Showing 4 changed files with 585 additions and 576 deletions.
8 changes: 4 additions & 4 deletions jal/data_export/dlsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ def append_dividend(self, dividend):
self._tax_form['sections']['@DeclForeign'][next_label] = income

def append_stock_trade(self, trade):
if trade['qty'] < 0: # short position - swap close/open dates/rates
if trade['c_qty'] < 0: # short position - swap close/open dates/rates
trade['cs_date'] = trade['os_date']
trade['cs_rate'] = trade['os_rate']
if self._broker_as_income:
income_source = self.broker_name
else:
income_source = f"Доход от сделки с {trade['symbol']} ({trade['isin']})"
income_source = f"Доход от сделки с {trade['c_symbol']} ({trade['c_isin']})"
income_iso_country = self.broker_iso_country
if self._year == 2020:
income = (13, '1530', '(01)Доходы от реализации ЦБ (обращ-ся на орг. рынке ЦБ)',
Expand Down Expand Up @@ -325,13 +325,13 @@ def append_bond_interest(self, interest):
self._tax_form['sections']['@DeclForeign'][next_label] = income

def append_derivative_trade(self, trade):
if trade['qty'] < 0: # short position - swap close/open dates/rates
if trade['c_qty'] < 0: # short position - swap close/open dates/rates
trade['cs_date'] = trade['os_date']
trade['cs_rate'] = trade['os_rate']
if self._broker_as_income:
income_source = self.broker_name
else:
income_source = f"Доход от сделки с {trade['symbol']}"
income_source = f"Доход от сделки с {trade['c_symbol']}"
income_iso_country = self.broker_iso_country
if self._year == 2020:
income = (13, '1532',
Expand Down
9 changes: 6 additions & 3 deletions jal/data_export/tax_reports/russia.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ def prepare_bonds(self):
spending_rub = round(trade.close_amount(self._currency_id, no_settlement=ns), 2) + round(trade.fee(self._currency_id), 2) - round(trade.close_operation().accrued_interest(self._currency_id), 2)
line = {
'report_template': "bond_trade",
'symbol': trade.asset().symbol(self.account_currency.id()),
'isin': trade.asset().isin(),
'qty': trade.qty(),
'c_symbol': trade.asset().symbol(self.account_currency.id()),
'c_isin': trade.asset().isin(), # May be not used in template (for derivatives as example)
'c_qty': trade.qty(),
'o_symbol': trade.open_operation().asset().symbol(),
'o_isin': trade.open_operation().asset().isin(),
'o_qty': trade.open_qty(),
'principal': trade.asset().principal(),
'country_iso': country.iso_code(),
'o_type': "Покупка" if trade.qty() >= Decimal('0') else "Продажа",
Expand Down
225 changes: 114 additions & 111 deletions tests/test_data/taxes_bond_rus.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,122 @@
{
"Акции":[
"Акции":[

],
"Дивиденды":[
],
"Дивиденды":[

],
"Комиссии":[
],
"Комиссии":[

],
"Криптовалюты":[
],
"Криптовалюты":[

],
"Облигации":[
{
"c_amount":2062.5,
"c_amount_rub":149994.28,
"c_date":1632515100,
"c_fee":0.0,
"c_fee_rub":0.0,
"c_int":0.0,
"c_int_rub":0.0,
"c_number":"17849517124",
"c_price":103.125,
"c_rate":72.7245,
"c_type":"Продажа",
"country_iso":"840",
"cs_date":1632515100,
"cs_rate":72.7245,
"income":2062.5,
"income_rub":149994.28,
"isin":"US912CALAN84",
"o_amount":1274.18,
"o_amount_rub":93618.72,
"o_date":1622131065,
"o_fee":2.0,
"o_fee_rub":146.95,
"o_int":25.69,
"o_int_rub":1887.54,
"o_number":"2882737839",
"o_price":63.709,
"o_rate":73.4737,
"o_type":"Покупка",
"os_date":1622246400,
"os_rate":73.4737,
"principal":1000.0,
"profit":760.63,
"profit_rub":54341.07,
"qty":2.0,
"report_template":"bond_trade",
"spending_rub":95653.21,
"symbol":"X 6 1/4 03/15/26 - PARTIAL CALL RED DATE 9/26"
},
{
"country_iso":"840",
"empty":"",
"income_rub":4508.46,
"interest":62.0,
"interest_rub":4508.46,
"isin":"US912909AN84",
"number":"",
"o_date":1631664000,
"profit":62.0,
"profit_rub":4508.46,
"rate":72.7171,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26",
"type":"Купон"
},
{
"country_iso":"840",
"empty":"",
"income_rub":36.36,
"interest":0.5,
"interest_rub":36.36,
"isin":"US912909AN84",
"number":"TEST_ID",
"o_date":1631664000,
"profit":0.5,
"profit_rub":36.36,
"rate":72.7171,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26",
"type":"Купон"
},
{
"country_iso":"840",
"empty":"",
"income_rub":278.89,
"interest":3.82,
"interest_rub":278.89,
"isin":"US912CALAN84",
"number":"",
"o_date":1632700800,
"profit":3.82,
"profit_rub":278.89,
"rate":73.0081,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26 - PARTIAL CALL RED DATE 9/26",
"type":"Купон"
},
{
"income_rub":154817.99,
"profit":826.95,
"profit_rub":59164.78,
"report_template":"totals",
"spending_rub":95653.21
}
],
"ПФИ":[
],
"Облигации":[
{
"c_amount":2062.5,
"c_amount_rub":149994.28,
"c_date":1632515100,
"c_fee":0.0,
"c_fee_rub":0.0,
"c_int":0.0,
"c_int_rub":0.0,
"c_isin":"US912CALAN84",
"c_number":"17849517124",
"c_price":103.125,
"c_qty":2.0,
"c_rate":72.7245,
"c_symbol":"X 6 1/4 03/15/26 - PARTIAL CALL RED DATE 9/26",
"c_type":"Продажа",
"country_iso":"840",
"cs_date":1632515100,
"cs_rate":72.7245,
"income":2062.5,
"income_rub":149994.28,
"o_amount":1274.18,
"o_amount_rub":93618.72,
"o_date":1622131065,
"o_fee":2.0,
"o_fee_rub":146.95,
"o_int":25.69,
"o_int_rub":1887.54,
"o_isin":"US912909AN84",
"o_number":"2882737839",
"o_price":63.709,
"o_qty":2.0,
"o_rate":73.4737,
"o_symbol":"X 6 1/4 03/15/26",
"o_type":"Покупка",
"os_date":1622246400,
"os_rate":73.4737,
"principal":1000.0,
"profit":760.63,
"profit_rub":54341.07,
"report_template":"bond_trade",
"spending_rub":95653.21
},
{
"country_iso":"840",
"empty":"",
"income_rub":4508.46,
"interest":62.0,
"interest_rub":4508.46,
"isin":"US912909AN84",
"number":"",
"o_date":1631664000,
"profit":62.0,
"profit_rub":4508.46,
"rate":72.7171,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26",
"type":"Купон"
},
{
"country_iso":"840",
"empty":"",
"income_rub":36.36,
"interest":0.5,
"interest_rub":36.36,
"isin":"US912909AN84",
"number":"TEST_ID",
"o_date":1631664000,
"profit":0.5,
"profit_rub":36.36,
"rate":72.7171,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26",
"type":"Купон"
},
{
"country_iso":"840",
"empty":"",
"income_rub":278.89,
"interest":3.82,
"interest_rub":278.89,
"isin":"US912CALAN84",
"number":"",
"o_date":1632700800,
"profit":3.82,
"profit_rub":278.89,
"rate":73.0081,
"report_template":"bond_interest",
"spending_rub":0.0,
"symbol":"X 6 1/4 03/15/26 - PARTIAL CALL RED DATE 9/26",
"type":"Купон"
},
{
"income_rub":154817.99,
"profit":826.95,
"profit_rub":59164.78,
"report_template":"totals",
"spending_rub":95653.21
}
],
"ПФИ":[

],
"Проценты":[
],
"Проценты":[

]
]
}
Loading

0 comments on commit 8728dd3

Please sign in to comment.