diff --git a/asset.py b/asset.py index 9505d2f..f805724 100644 --- a/asset.py +++ b/asset.py @@ -45,4 +45,3 @@ class AssetRate(metaclass=PoolMeta): super(AssetRate, cls).delete(records) # end - diff --git a/assetsetting.py b/assetsetting.py index 11f86b6..b5981dd 100644 --- a/assetsetting.py +++ b/assetsetting.py @@ -12,13 +12,16 @@ class AssetSetting(ModelSingleton, ModelSQL, ModelView): 'Asset setting' __name__ = 'cashbook.assetconf' - fee_category = fields.Many2One(string='Fee category', + fee_category = fields.Many2One( + string='Fee category', model_name='cashbook.category', ondelete='RESTRICT', help='Category for fees when trading assets.') - dividend_category = fields.Many2One(string='Dividend category', + dividend_category = fields.Many2One( + string='Dividend category', model_name='cashbook.category', ondelete='RESTRICT', help='Category for dividend paid out.') - gainloss_book = fields.Many2One(string='Profit/Loss Cashbook', + gainloss_book = fields.Many2One( + string='Profit/Loss Cashbook', model_name='cashbook.book', ondelete='RESTRICT', help='Profit and loss on sale of assets are recorded in the cash book.') diff --git a/book.py b/book.py index 9e0c830..99461cf 100644 --- a/book.py +++ b/book.py @@ -22,22 +22,27 @@ from .asset import CACHEKEY_ASSETRATE # enable/disable caching of cachekey for 'currency.rate' -if config.get('cashbook', 'cache_currency', default='yes').lower() in ['yes', '1', 'true']: +if config.get( + 'cashbook', 'cache_currency', + default='yes').lower() in ['yes', '1', 'true']: ENA_CURRKEY = True -else : +else: ENA_CURRKEY = False # enable/disable caching of cachekey for 'currency.rate' -if config.get('cashbook', 'cache_asset', default='yes').lower() in ['yes', '1', 'true']: +if config.get( + 'cashbook', 'cache_asset', + default='yes').lower() in ['yes', '1', 'true']: ENA_ASSETKEY = True -else : +else: ENA_ASSETKEY = False class Book(SymbolMixin, metaclass=PoolMeta): __name__ = 'cashbook.book' - asset = fields.Many2One(string='Asset', select=True, + asset = fields.Many2One( + string='Asset', select=True, model_name='investment.asset', ondelete='RESTRICT', states={ 'required': Eval('feature', '') == 'asset', @@ -47,8 +52,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): Len(Eval('lines')) > 0, ), }, depends=DEPENDS2+['feature', 'lines']) - quantity_digits = fields.Integer(string='Digits', - help='Quantity Digits', + quantity_digits = fields.Integer( + string='Digits', help='Quantity Digits', domain=[ ('quantity_digits', '>=', 0), ('quantity_digits', '<=', 6), @@ -61,10 +66,12 @@ class Book(SymbolMixin, metaclass=PoolMeta): Len(Eval('lines')) > 0, ), }, depends=DEPENDS2+['feature', 'lines']) - asset_uomcat = fields.Function(fields.Many2One(string='UOM Category', - readonly=True, model_name='product.uom.category', + asset_uomcat = fields.Function(fields.Many2One( + string='UOM Category', readonly=True, + model_name='product.uom.category', states={'invisible': True}), 'on_change_with_asset_uomcat') - quantity_uom = fields.Many2One(string='UOM', select=True, + quantity_uom = fields.Many2One( + string='UOM', select=True, model_name='product.uom', ondelete='RESTRICT', domain=[ ('category.id', '=', Eval('asset_uomcat', -1)), @@ -77,34 +84,38 @@ class Book(SymbolMixin, metaclass=PoolMeta): Len(Eval('lines')) > 0, ), }, depends=DEPENDS2+['feature', 'lines', 'asset_uomcat']) - symbol = fields.Function(fields.Char(string='Symbol', readonly=True), - 'on_change_with_symbol') - asset_symbol = fields.Function(fields.Many2One(string='Symbol', - readonly=True, model_name='cashbook.book'), + symbol = fields.Function(fields.Char( + string='Symbol', readonly=True), 'on_change_with_symbol') + asset_symbol = fields.Function(fields.Many2One( + string='Symbol', readonly=True, model_name='cashbook.book'), 'on_change_with_asset_symbol') - quantity = fields.Function(fields.Numeric(string='Quantity', - help='Quantity of assets until to date', readonly=True, - digits=(16, Eval('quantity_digits', 4)), + quantity = fields.Function(fields.Numeric( + string='Quantity', help='Quantity of assets until to date', + readonly=True, digits=(16, Eval('quantity_digits', 4)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['quantity_digits', 'feature']), 'get_asset_quantity') - quantity_all = fields.Function(fields.Numeric(string='Total Quantity', - help='Total quantity of all assets', readonly=True, - digits=(16, Eval('quantity_digits', 4)), + quantity_all = fields.Function(fields.Numeric( + string='Total Quantity', help='Total quantity of all assets', + readonly=True, digits=(16, Eval('quantity_digits', 4)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['quantity_digits', 'feature']), 'get_asset_quantity') - current_value = fields.Function(fields.Numeric(string='Value', - help='Valuation of the investment based on the current stock market price.', + current_value = fields.Function(fields.Numeric( + string='Value', + help='Valuation of the investment based on the current ' + + 'stock market price.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('show_performance', False) == False, }, depends=['currency_digits', 'show_performance']), 'get_asset_quantity') - current_value_ref = fields.Function(fields.Numeric(string='Value (Ref.)', - help='Valuation of the investment based on the current stock exchange price, converted into the company currency.', + current_value_ref = fields.Function(fields.Numeric( + string='Value (Ref.)', + help='Valuation of the investment based on the current stock' + + ' exchange price, converted into the company currency.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Or( @@ -115,27 +126,35 @@ class Book(SymbolMixin, metaclass=PoolMeta): 'get_asset_quantity') # performance - diff_amount = fields.Function(fields.Numeric(string='Difference', + diff_amount = fields.Function(fields.Numeric( + string='Difference', help='Difference between acquisition value and current value', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('show_performance', False) == False, - }, depends=['currency_digits', 'show_performance']), 'get_asset_quantity') - diff_percent = fields.Function(fields.Numeric(string='Percent', + }, depends=['currency_digits', 'show_performance']), + 'get_asset_quantity') + diff_percent = fields.Function(fields.Numeric( + string='Percent', help='percentage performance since acquisition', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('show_performance', False) == False, - }, depends=['currency_digits', 'show_performance']), 'get_asset_quantity') - show_performance = fields.Function(fields.Boolean(string='Performance', - readonly=True), 'on_change_with_show_performance') - current_rate = fields.Function(fields.Numeric(string='Rate', - help='Rate per unit of investment based on current stock exchange price.', + }, depends=['currency_digits', 'show_performance']), + 'get_asset_quantity') + show_performance = fields.Function(fields.Boolean( + string='Performance', readonly=True), + 'on_change_with_show_performance') + current_rate = fields.Function(fields.Numeric( + string='Rate', + help='Rate per unit of investment based on current stock ' + + 'exchange price.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_asset_quantity') - purchase_amount = fields.Function(fields.Numeric(string='Purchase Amount', + purchase_amount = fields.Function(fields.Numeric( + string='Purchase Amount', help='Total purchase amount, from shares and fees.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ @@ -144,43 +163,47 @@ class Book(SymbolMixin, metaclass=PoolMeta): 'get_asset_quantity') # yield - yield_dividend_total = fields.Function(fields.Numeric(string='Dividend', - help='Total dividends received', + yield_dividend_total = fields.Function(fields.Numeric( + string='Dividend', help='Total dividends received', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_dividend_12m = fields.Function(fields.Numeric(string='Dividend 1y', + yield_dividend_12m = fields.Function(fields.Numeric( + string='Dividend 1y', help='Dividends received in the last twelve months', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_fee_total = fields.Function(fields.Numeric(string='Trade Fee', - help='Total trade fees payed', + yield_fee_total = fields.Function(fields.Numeric( + string='Trade Fee', help='Total trade fees payed', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_fee_12m = fields.Function(fields.Numeric(string='Trade Fee 1y', + yield_fee_12m = fields.Function(fields.Numeric( + string='Trade Fee 1y', help='Trade fees payed in the last twelve month', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_sales = fields.Function(fields.Numeric(string='Sales', - help='Total profit or loss on sale of shares.', + yield_sales = fields.Function(fields.Numeric( + string='Sales', help='Total profit or loss on sale of shares.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_sales_12m = fields.Function(fields.Numeric(string='Sales 1y', + yield_sales_12m = fields.Function(fields.Numeric( + string='Sales 1y', help='Total profit or loss on sale of shares in the last twelve month.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['currency_digits', 'feature']), 'get_yield_data') - yield_balance = fields.Function(fields.Numeric(string='Total Yield', + yield_balance = fields.Function(fields.Numeric( + string='Total Yield', help='Total income: price gain + dividends + sales gains - fees', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ @@ -194,9 +217,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): ('/tree', 'visual', If(Eval('show_performance', False) == True, If(Eval('diff_percent', 0) < 0, 'danger', - If(Eval('diff_percent', 0) > 0, 'success', '') - ), '') - ), + If(Eval('diff_percent', 0) > 0, + 'success', '')), '')), ] def get_rec_name(self, name): @@ -205,7 +227,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): recname = super(Book, self).get_rec_name(name) if self.feature == 'asset': recname += ' | %(quantity)s %(uom_symbol)s' % { - 'quantity': Report.format_number(self.quantity or 0.0, None, + 'quantity': Report.format_number( + self.quantity or 0.0, None, digits=self.quantity_digits), 'uom_symbol': getattr(self.quantity_uom, 'symbol', '-'), } @@ -229,7 +252,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): """ calculate yield total fee is already contained in 'diff_amount' """ - sum_lst = [self.diff_amount, self.yield_dividend_total, self.yield_sales] + sum_lst = [ + self.diff_amount, self.yield_dividend_total, self.yield_sales] sum2 = sum([x for x in sum_lst if x is not None]) return sum2 @@ -252,14 +276,18 @@ class Book(SymbolMixin, metaclass=PoolMeta): if date_to: where &= tab_line.date <= date_to - query = tab_book.join(tab_line, - condition=tab_line.cashbook==tab_book.id, - ).join(tab_cur, - condition=tab_cur.id==tab_book.currency, - ).join(tab_line_yield, - condition=tab_line_yield.id==tab_line.id, - ).join(tab_line_gainloss, - condition=tab_line_gainloss.id==tab_line.id, + query = tab_book.join( + tab_line, + condition=tab_line.cashbook == tab_book.id, + ).join( + tab_cur, + condition=tab_cur.id == tab_book.currency, + ).join( + tab_line_yield, + condition=tab_line_yield.id == tab_line.id, + ).join( + tab_line_gainloss, + condition=tab_line_gainloss.id == tab_line.id, ).select( tab_book.id, Sum(tab_line_yield.fee).as_('fee'), @@ -276,16 +304,16 @@ class Book(SymbolMixin, metaclass=PoolMeta): """ collect yield data """ pool = Pool() - CashBook = pool.get('cashbook.book') IrDate = pool.get('ir.date') MemCache = pool.get('cashbook.memcache') cursor = Transaction().connection.cursor() context = Transaction().context result = { - x:{y.id: Decimal('0.0') for y in cashbooks} - for x in ['yield_fee_total', 'yield_dividend_total', - 'yield_sales', 'yield_fee_12m', 'yield_dividend_12m', - 'yield_sales_12m']} + x: {y.id: Decimal('0.0') for y in cashbooks} + for x in [ + 'yield_fee_total', 'yield_dividend_total', + 'yield_sales', 'yield_fee_12m', 'yield_dividend_12m', + 'yield_sales_12m']} def quantize_val(value, digits): """ quantize... @@ -297,21 +325,23 @@ class Book(SymbolMixin, metaclass=PoolMeta): query_date = context.get('date', IrDate.today()) cache_keys = { x.id: MemCache.get_key_by_record( - name = 'get_yield_data', - record = x, - query = [{ + name='get_yield_data', + record=x, + query=[{ 'model': 'cashbook.line', 'query': [('cashbook.parent', 'child_of', [x.id])], }, { 'model': 'currency.currency.rate', 'query': [('currency.id', '=', x.currency.id)], - 'cachekey' if ENA_CURRKEY else 'disabled': CACHEKEY_CURRENCY % x.currency.id, + 'cachekey' if ENA_CURRKEY else 'disabled': + CACHEKEY_CURRENCY % x.currency.id, }, { 'model': 'investment.rate', 'query': [('asset.id', '=', x.asset.id)], - 'cachekey' if ENA_ASSETKEY else 'disabled': CACHEKEY_ASSETRATE % x.asset.id, + 'cachekey' if ENA_ASSETKEY else 'disabled': + CACHEKEY_ASSETRATE % x.asset.id, } if x.asset is not None else {}], - addkeys = [query_date.isoformat()]) + addkeys=[query_date.isoformat()]) for x in cashbooks } @@ -332,26 +362,32 @@ class Book(SymbolMixin, metaclass=PoolMeta): # results for 12 months (tab_book2, query_12m) = cls.get_yield_data_sql( - date_to = query_date, - date_from = query_date - timedelta(days=365), + date_to=query_date, + date_from=query_date - timedelta(days=365), ) query_12m.where &= tab_book2.id.in_([x.id for x in todo_cashbook]) cursor.execute(*query_12m) records_12m = cursor.fetchall() for record in records_total: - result['yield_fee_total'][record[0]] = quantize_val(record[1], record[4]) - result['yield_dividend_total'][record[0]] = quantize_val(record[2], record[4]) - result['yield_sales'][record[0]] = quantize_val(record[3], record[4]) + result['yield_fee_total'][record[0]] = quantize_val( + record[1], record[4]) + result['yield_dividend_total'][record[0]] = quantize_val( + record[2], record[4]) + result['yield_sales'][record[0]] = quantize_val( + record[3], record[4]) for record in records_12m: - result['yield_fee_12m'][record[0]] = quantize_val(record[1], record[4]) - result['yield_dividend_12m'][record[0]] = quantize_val(record[2], record[4]) - result['yield_sales_12m'][record[0]] = quantize_val(record[3], record[4]) + result['yield_fee_12m'][record[0]] = quantize_val( + record[1], record[4]) + result['yield_dividend_12m'][record[0]] = quantize_val( + record[2], record[4]) + result['yield_sales_12m'][record[0]] = quantize_val( + record[3], record[4]) # store to cache MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook) - return {x:result[x] for x in names} + return {x: result[x] for x in names} @classmethod def get_asset_quantity_sql(cls): @@ -374,40 +410,50 @@ class Book(SymbolMixin, metaclass=PoolMeta): context = Transaction().context query_date = context.get('qdate', CurrentDate()) - query = tab_book.join(tab_line, - condition=(tab_book.id==tab_line.cashbook), - ).join(tab_type, - condition=tab_book.btype==tab_type.id, - ).join(tab_cur, - condition=tab_book.currency==tab_cur.id, - ).join(tab_asset, - condition=tab_book.asset==tab_asset.id, - ).join(query_yield, - condition=query_yield.id==tab_line.id, - ).join(tab_balance, - condition=tab_book.id==tab_balance.cashbook, - type_ = 'LEFT OUTER', - ).join(tab_rate, - condition=tab_book.asset==tab_rate.id, - type_ = 'LEFT OUTER', + query = tab_book.join( + tab_line, + condition=(tab_book.id == tab_line.cashbook), + ).join( + tab_type, + condition=tab_book.btype == tab_type.id, + ).join( + tab_cur, + condition=tab_book.currency == tab_cur.id, + ).join( + tab_asset, + condition=tab_book.asset == tab_asset.id, + ).join( + query_yield, + condition=query_yield.id == tab_line.id, + ).join( + tab_balance, + condition=tab_book.id == tab_balance.cashbook, + type_='LEFT OUTER', + ).join( + tab_rate, + condition=tab_book.asset == tab_rate.id, + type_='LEFT OUTER', ).select( tab_book.id, # 0 Coalesce(Sum(Case( (tab_line.date <= query_date, tab_line.quantity_credit - tab_line.quantity_debit), - else_ = Decimal('0.0'), + else_=Decimal('0.0'), )), Decimal('0.0')).as_('quantity'), # 1 - Sum(tab_line.quantity_credit - tab_line.quantity_debit).as_('quantity_all'), # 2 + Sum( + tab_line.quantity_credit - + tab_line.quantity_debit).as_('quantity_all'), # 2 Coalesce(tab_rate.rate, Decimal('0.0')).as_('rate'), # 3 - tab_book.currency, # 4 + tab_book.currency, # 4 tab_cur.digits.as_('currency_digits'), # 5 tab_asset.uom, # 6 tab_book.quantity_uom, # 7 - tab_asset.currency.as_('asset_currency'), #8 + tab_asset.currency.as_('asset_currency'), # 8 ( Sum(query_yield.fee) + tab_balance.balance - ).as_('purchase_amount'), #9 - group_by=[tab_book.id, tab_rate.rate, + ).as_('purchase_amount'), # 9 + group_by=[ + tab_book.id, tab_rate.rate, tab_book.currency, tab_cur.digits, tab_asset.uom, tab_book.quantity_uom, tab_asset.currency, tab_balance.balance], @@ -434,28 +480,31 @@ class Book(SymbolMixin, metaclass=PoolMeta): company_currency = CBook.default_currency() result = { - x:{y.id: None for y in cashbooks} - for x in ['quantity', 'quantity_all', 'current_value', - 'current_value_ref', 'diff_amount', 'diff_percent', - 'current_rate', 'purchase_amount', 'purchase_amount_ref', - 'digits'] + x: {y.id: None for y in cashbooks} + for x in [ + 'quantity', 'quantity_all', 'current_value', + 'current_value_ref', 'diff_amount', 'diff_percent', + 'current_rate', 'purchase_amount', 'purchase_amount_ref', + 'digits'] } cache_keys = { x.id: MemCache.get_key_by_record( - name = 'get_asset_quantity', - record = x, - query = [{ - 'model': 'cashbook.line', - 'query': [('cashbook.parent', 'child_of', [x.id])], + name='get_asset_quantity', + record=x, + query=[{ + 'model': 'cashbook.line', + 'query': [('cashbook.parent', 'child_of', [x.id])], }, { - 'model': 'currency.currency.rate', - 'query': [('currency.id', '=', x.currency.id)], - 'cachekey' if ENA_CURRKEY else 'disabled': CACHEKEY_CURRENCY % x.currency.id, + 'model': 'currency.currency.rate', + 'query': [('currency.id', '=', x.currency.id)], + 'cachekey' if ENA_CURRKEY else 'disabled': + CACHEKEY_CURRENCY % x.currency.id, }, { - 'model': 'investment.rate', - 'query': [('asset.id', '=', x.asset.id)], - 'cachekey' if ENA_ASSETKEY else 'disabled': CACHEKEY_ASSETRATE % x.asset.id, + 'model': 'investment.rate', + 'query': [('asset.id', '=', x.asset.id)], + 'cachekey' if ENA_ASSETKEY else 'disabled': + CACHEKEY_ASSETRATE % x.asset.id, } if x.asset is not None else {}], addkeys=[ str(company_currency), @@ -476,9 +525,11 @@ class Book(SymbolMixin, metaclass=PoolMeta): # uom-factor if rdata[6] == rdata[7]: uom_factor = Decimal('1.0') - else : + else: uom_factor = Decimal( - Uom.compute_qty(Uom(rdata[6]), 1.0, Uom(rdata[7]), round=False) + Uom.compute_qty( + Uom(rdata[6]), 1.0, + Uom(rdata[7]), round=False) ) current_value = Currency.compute( @@ -493,23 +544,26 @@ class Book(SymbolMixin, metaclass=PoolMeta): 'current_value_ref': Currency.compute( rdata[8], rdata[3] * rdata[1] / uom_factor, - company_currency if company_currency is not None else rdata[8], + company_currency + if company_currency is not None else rdata[8], ), 'diff_amount': current_value - rdata[9], 'diff_percent': ( - Decimal('100.0') * current_value / \ + Decimal('100.0') * current_value / rdata[9] - Decimal('100.0') - ).quantize(Decimal(str(1/10**rdata[5]))) \ - if rdata[9] != Decimal('0.0') else None, + ).quantize(Decimal(str(1/10**rdata[5]))) + if rdata[9] != Decimal('0.0') else None, 'current_rate': ( current_value / rdata[1] - ).quantize(Decimal(str(1/10**rdata[5]))) \ - if rdata[1] != Decimal('0.0') else None, - 'purchase_amount': record[9].quantize(Decimal(str(1/10**rdata[5]))), + ).quantize(Decimal(str(1/10**rdata[5]))) + if rdata[1] != Decimal('0.0') else None, + 'purchase_amount': record[9].quantize( + Decimal(str(1/10**rdata[5]))), 'purchase_amount_ref': Currency.compute( rdata[4], record[9], - company_currency if company_currency is not None else rdata[4], + company_currency + if company_currency is not None else rdata[4], ), }) @@ -529,7 +583,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): result[name][book_id] = values[name] # add aggregated values of cashbooks without type - aggr_names = ['current_value', 'current_value_ref', + aggr_names = [ + 'current_value', 'current_value_ref', 'diff_amount', 'diff_percent'] queried_names = list(set(aggr_names).intersection(set(names))) @@ -539,27 +594,30 @@ class Book(SymbolMixin, metaclass=PoolMeta): (tab_quantity, tab_book) = cls.get_asset_quantity_sql() tab_subids = sub_ids_hierarchical('cashbook.book') - query = tab_book.join(tab_subids, - condition=tab_book.id==tab_subids.parent, - ).join(tab_quantity, - condition=tab_quantity.id==AnyInArray(tab_subids.subids), + query = tab_book.join( + tab_subids, + condition=tab_book.id == tab_subids.parent, + ).join( + tab_quantity, + condition=tab_quantity.id == AnyInArray(tab_subids.subids), ).select( tab_book.id, - Sum(tab_quantity.quantity), # 1 - Sum(tab_quantity.quantity_all), # 2 - tab_quantity.rate, # 3 - tab_quantity.currency, # 4 - tab_quantity.currency_digits, # 5 - tab_quantity.uom, # 6 - tab_quantity.quantity_uom, # 7 - tab_quantity.asset_currency, # 8 - Sum(tab_quantity.purchase_amount), # 9 - tab_book.currency.as_('currency_book'), # 10 + Sum(tab_quantity.quantity), # 1 + Sum(tab_quantity.quantity_all), # 2 + tab_quantity.rate, # 3 + tab_quantity.currency, # 4 + tab_quantity.currency_digits, # 5 + tab_quantity.uom, # 6 + tab_quantity.quantity_uom, # 7 + tab_quantity.asset_currency, # 8 + Sum(tab_quantity.purchase_amount), # 9 + tab_book.currency.as_('currency_book'), # 10 where=tab_book.id.in_(ids_nonebtypes), - group_by=[tab_book.id, tab_quantity.rate, + group_by=[ + tab_book.id, tab_quantity.rate, tab_quantity.currency, tab_quantity.currency_digits, tab_quantity.uom, tab_quantity.quantity_uom, - tab_quantity.asset_currency,tab_book.currency], + tab_quantity.asset_currency, tab_book.currency], ) cursor.execute(*query) records = cursor.fetchall() @@ -567,7 +625,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): for record in records: (book_id, values) = values_from_record(record) - for name in ['current_value', 'diff_amount', + for name in [ + 'current_value', 'diff_amount', 'current_value_ref', 'purchase_amount_ref']: if result[name][book_id] is None: result[name][book_id] = Decimal('0.0') @@ -575,14 +634,17 @@ class Book(SymbolMixin, metaclass=PoolMeta): value = Decimal('0.0') if name == 'current_value': value = Currency.compute( - company_currency if company_currency is not None else record[4], + company_currency + if company_currency is not None else record[4], values['current_value_ref'], record[10], ) elif name == 'diff_amount': value = Currency.compute( - company_currency if company_currency is not None else record[4], - values['current_value_ref'] - values['purchase_amount_ref'], + company_currency + if company_currency is not None else record[4], + values['current_value_ref'] - + values['purchase_amount_ref'], record[10], ) elif name in ['current_value_ref', 'purchase_amount_ref']: @@ -596,7 +658,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): p_amount = result['purchase_amount_ref'][id_book] digits = result['digits'][id_book] - if (p_amount == Decimal('0.0')) or (p_amount is None) or (c_val is None): + if (p_amount == Decimal('0.0')) or \ + (p_amount is None) or (c_val is None): continue result['diff_percent'][id_book] = ( @@ -606,7 +669,7 @@ class Book(SymbolMixin, metaclass=PoolMeta): # store to cache MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook) - return {x:result[x] for x in names} + return {x: result[x] for x in names} @fields.depends('id') def on_change_with_show_performance(self, name=None): @@ -616,9 +679,8 @@ class Book(SymbolMixin, metaclass=PoolMeta): Book2 = Pool().get('cashbook.book') if Book2.search_count([ - ('btype.feature', '=', 'asset'), - ('parent', 'child_of', [self.id]), - ]) > 0: + ('btype.feature', '=', 'asset'), + ('parent', 'child_of', [self.id])]) > 0: return True return False diff --git a/line.py b/line.py index fc86536..c46d16c 100644 --- a/line.py +++ b/line.py @@ -85,7 +85,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta): quantity_balance = fields.Function(fields.Numeric( string='Quantity', digits=(16, Eval('quantity_digits', 4)), readonly=True, - help='Number of shares in the cashbook up to the current row if the default sort applies.', + help='Number of shares in the cashbook up to the current ' + + 'row if the default sort applies.', states={ 'invisible': Eval('feature', '') != 'asset', }, depends=['quantity_digits', 'feature']), @@ -97,7 +98,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta): # performance current_value = fields.Function(fields.Numeric( string='Value', - help='Valuation of the investment based on the current stock market price.', + help='Valuation of the investment based on the current ' + + 'stock market price.', readonly=True, digits=(16, Eval('currency_digits', 2)), states={ 'invisible': Eval('feature', '') != 'asset', @@ -154,60 +156,69 @@ class Line(SecondUomMixin, metaclass=PoolMeta): SplitLine = pool.get('cashbook.split') tab_line = cls.__table__() tab_mvsp_counterpart = cls.__table__() - tab_mvsp_local = cls.__table__() tab_mvmv_counterpart = cls.__table__() tab_spmv_counterpart = cls.__table__() tab_mv_spline = SplitLine.__table__() cfg1 = AssetSetting.get_singleton() - gainloss_book = getattr(getattr(cfg1, 'gainloss_book', None), 'id', None) + gainloss_book = getattr(getattr( + cfg1, 'gainloss_book', None), 'id', None) tab_assetline = cls.search([ ('cashbook.btype.feature', '=', 'asset'), ], query=True) - query = tab_line.join(tab_assetline, - condition=(tab_assetline.id==tab_line.id), + query = tab_line.join( + tab_assetline, + condition=(tab_assetline.id == tab_line.id), - ).join(tab_mvsp_counterpart, - # [MV-SP] transfer booking, select counterpart [1] - a split-booking + ).join( + tab_mvsp_counterpart, + # [MV-SP] transfer booking, + # select counterpart [1] - a split-booking condition=tab_line.bookingtype.in_(['mvin', 'mvout']) & \ - ((tab_line.reference == tab_mvsp_counterpart.id) | \ - (tab_line.id == tab_mvsp_counterpart.reference)) & \ - (tab_mvsp_counterpart.bookingtype.in_(['spin', 'spout'])), - type_ = 'LEFT OUTER', - ).join(tab_mv_spline, - # [MV-SP] line is linked to split-booking-line of counterpart [1] + ((tab_line.reference == tab_mvsp_counterpart.id) | + (tab_line.id == tab_mvsp_counterpart.reference)) & + (tab_mvsp_counterpart.bookingtype.in_(['spin', 'spout'])), + type_='LEFT OUTER', + ).join( + tab_mv_spline, + # [MV-SP] line is linked to split-booking-line + # of counterpart [1] condition=(tab_mv_spline.line == tab_mvsp_counterpart.id) & \ - (tab_mv_spline.splittype == 'tr') & \ - (tab_mv_spline.booktransf != None) & \ - (tab_mv_spline.booktransf == gainloss_book), - type_ = 'LEFT OUTER', + (tab_mv_spline.splittype == 'tr') & \ + (tab_mv_spline.booktransf != None) & \ + (tab_mv_spline.booktransf == gainloss_book), + type_='LEFT OUTER', - ).join(tab_spmv_counterpart, - # [SP-MV] split booking, select counterpart [1] - a transfer-booking + ).join( + tab_spmv_counterpart, + # [SP-MV] split booking, select counterpart [1] + # - a transfer-booking condition=tab_line.bookingtype.in_(['spin', 'spout']) & \ - ((tab_line.reference == tab_spmv_counterpart.id) | \ - (tab_line.id == tab_spmv_counterpart.reference)) & \ - tab_spmv_counterpart.bookingtype.in_(['mvin', 'mvout']) & \ - (tab_spmv_counterpart.cashbook == gainloss_book), - type_ = 'LEFT OUTER', + ((tab_line.reference == tab_spmv_counterpart.id) | \ + (tab_line.id == tab_spmv_counterpart.reference)) & \ + tab_spmv_counterpart.bookingtype.in_(['mvin', 'mvout']) & \ + (tab_spmv_counterpart.cashbook == gainloss_book), + type_='LEFT OUTER', - ).join(tab_mvmv_counterpart, + ).join( + tab_mvmv_counterpart, # [MV-MV] transfer booking condition=tab_line.bookingtype.in_(['mvin', 'mvout']) & \ - ((tab_mvmv_counterpart.reference == tab_line.id) | \ - (tab_mvmv_counterpart.id == tab_line.reference)) & \ - tab_mvmv_counterpart.bookingtype.in_(['mvin', 'mvout']) & \ - (tab_mvmv_counterpart.cashbook == gainloss_book), - type_ = 'LEFT OUTER', + ((tab_mvmv_counterpart.reference == tab_line.id) | \ + (tab_mvmv_counterpart.id == tab_line.reference)) & \ + tab_mvmv_counterpart.bookingtype.in_(['mvin', 'mvout']) & \ + (tab_mvmv_counterpart.cashbook == gainloss_book), + type_='LEFT OUTER', ).select( tab_line.id, (Coalesce( tab_mvmv_counterpart.credit - tab_mvmv_counterpart.debit, Case( (tab_line.bookingtype == 'mvin', tab_mv_spline.amount), - (tab_line.bookingtype == 'mvout', tab_mv_spline.amount * Decimal('-1.0')), + (tab_line.bookingtype == 'mvout', + tab_mv_spline.amount * Decimal('-1.0')), ), Case( (tab_mvsp_counterpart.cashbook == gainloss_book, @@ -238,67 +249,79 @@ class Line(SecondUomMixin, metaclass=PoolMeta): cfg1 = AssetSetting.get_singleton() fee_category = getattr(getattr(cfg1, 'fee_category', None), 'id', None) - dividend_category = getattr(getattr(cfg1, 'dividend_category', None), 'id', None) + dividend_category = getattr(getattr( + cfg1, 'dividend_category', None), 'id', None) tab_assetline = cls.search([ ('cashbook.btype.feature', '=', 'asset'), ], query=True) - query = tab_line.join(tab_assetline, - condition=(tab_assetline.id==tab_line.id), - ).join(tab_inout_fee, + query = tab_line.join( + tab_assetline, + condition=(tab_assetline.id == tab_line.id), + ).join( + tab_inout_fee, # [INOUT] fee, local booked - condition=(tab_inout_fee.id==tab_line.id) & \ - tab_inout_fee.bookingtype.in_(['in', 'out']) & \ - (tab_inout_fee.category != None) & \ - (tab_inout_fee.category == fee_category), - type_ = 'LEFT OUTER', - ).join(tab_inout_divi, + condition=(tab_inout_fee.id == tab_line.id) & \ + tab_inout_fee.bookingtype.in_(['in', 'out']) & \ + (tab_inout_fee.category != None) & \ + (tab_inout_fee.category == fee_category), + type_='LEFT OUTER', + ).join( + tab_inout_divi, # [INOUT] dividend, local booked - condition=(tab_inout_divi.id==tab_line.id) & \ - tab_inout_divi.bookingtype.in_(['in', 'out']) & \ - (tab_inout_divi.category != None) & \ - (tab_inout_divi.category == dividend_category), - type_ = 'LEFT OUTER', + condition=(tab_inout_divi.id == tab_line.id) & \ + tab_inout_divi.bookingtype.in_(['in', 'out']) & \ + (tab_inout_divi.category != None) & \ + (tab_inout_divi.category == dividend_category), + type_='LEFT OUTER', - ).join(tab_mv_counterpart, - # [MV] transfer booking, select counterpart [1] - a split-booking + ).join( + tab_mv_counterpart, + # [MV] transfer booking, select counterpart [1] + # - a split-booking condition=tab_line.bookingtype.in_(['mvin', 'mvout']) & \ - ((tab_line.reference == tab_mv_counterpart.id) | \ - (tab_line.id == tab_mv_counterpart.reference)) & \ - (tab_mv_counterpart.bookingtype.in_(['spin', 'spout'])), - type_ = 'LEFT OUTER', - ).join(tab_mv_spline_fee, - # [MV] fee-line is linked to split-booking-line of counterpart [1] + ((tab_line.reference == tab_mv_counterpart.id) | \ + (tab_line.id == tab_mv_counterpart.reference)) & \ + (tab_mv_counterpart.bookingtype.in_(['spin', 'spout'])), + type_='LEFT OUTER', + ).join( + tab_mv_spline_fee, + # [MV] fee-line is linked to split-booking-line + # of counterpart [1] condition=(tab_mv_spline_fee.line == tab_mv_counterpart.id) & \ - (tab_mv_spline_fee.splittype == 'cat') & \ - (tab_mv_spline_fee.category != None) & \ - (tab_mv_spline_fee.category == fee_category), - type_ = 'LEFT OUTER', - ).join(tab_mv_spline_divi, - # [MV] dividend-line is linked to split-booking-line of counterpart [1] + (tab_mv_spline_fee.splittype == 'cat') & \ + (tab_mv_spline_fee.category != None) & \ + (tab_mv_spline_fee.category == fee_category), + type_='LEFT OUTER', + ).join( + tab_mv_spline_divi, + # [MV] dividend-line is linked to split-booking-line + # of counterpart [1] condition=(tab_mv_spline_divi.line == tab_mv_counterpart.id) & \ - (tab_mv_spline_divi.splittype == 'cat') & \ - (tab_mv_spline_divi.category != None) & \ - (tab_mv_spline_divi.category == dividend_category), - type_ = 'LEFT OUTER', + (tab_mv_spline_divi.splittype == 'cat') & \ + (tab_mv_spline_divi.category != None) & \ + (tab_mv_spline_divi.category == dividend_category), + type_='LEFT OUTER', - ).join(tab_spline_fee, + ).join( + tab_spline_fee, # [SP] fee, split booking condition=(tab_spline_fee.line == tab_line.id) & \ - tab_line.bookingtype.in_(['spin', 'spout']) & \ - (tab_spline_fee.splittype == 'cat') & \ - (tab_spline_fee.category != None) & \ - (tab_spline_fee.category == fee_category), - type_ = 'LEFT OUTER', - ).join(tab_spline_divi, + tab_line.bookingtype.in_(['spin', 'spout']) & \ + (tab_spline_fee.splittype == 'cat') & \ + (tab_spline_fee.category != None) & \ + (tab_spline_fee.category == fee_category), + type_='LEFT OUTER', + ).join( + tab_spline_divi, # [SP] dividend, split booking condition=(tab_spline_divi.line == tab_line.id) & \ - tab_line.bookingtype.in_(['spin', 'spout']) & \ - (tab_spline_divi.splittype == 'cat') & \ - (tab_spline_divi.category != None) & \ - (tab_spline_divi.category == dividend_category), - type_ = 'LEFT OUTER', + tab_line.bookingtype.in_(['spin', 'spout']) & \ + (tab_spline_divi.splittype == 'cat') & \ + (tab_spline_divi.category != None) & \ + (tab_spline_divi.category == dividend_category), + type_='LEFT OUTER', ).select( tab_line.id, Sum(Coalesce( @@ -308,8 +331,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta): # transfer = fee is positive tab_mv_spline_fee.amount, Case( - (tab_line.bookingtype == 'spin', tab_spline_fee.amount * Decimal('-1.0')), - (tab_line.bookingtype == 'spout', tab_spline_fee.amount), + (tab_line.bookingtype == 'spin', + tab_spline_fee.amount * Decimal('-1.0')), + (tab_line.bookingtype == 'spout', + tab_spline_fee.amount), ), Decimal('0.0'), )).as_('fee'), @@ -317,8 +342,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta): tab_inout_divi.credit - tab_inout_divi.debit, tab_mv_spline_divi.amount, Case( - (tab_line.bookingtype == 'spin', tab_spline_divi.amount), - (tab_line.bookingtype == 'spout', tab_spline_divi.amount * Decimal('-1.0')), + (tab_line.bookingtype == 'spin', + tab_spline_divi.amount), + (tab_line.bookingtype == 'spout', + tab_spline_divi.amount * Decimal('-1.0')), ), Decimal('0.0'), )).as_('dividend'), @@ -380,7 +407,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta): value or Decimal('0.0') ).quantize(Decimal(str(1/10**line.currency_digits))) - result = {x:{y.id: None for y in lines} for x in names} + result = {x: {y.id: None for y in lines} for x in names} # read fee, dividend name_set = set({'trade_fee', 'asset_dividend'}).intersection(set(names)) @@ -408,7 +435,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta): for record in records: line = Line2(record[0]) - result['asset_gainloss'][record[0]] = quantize_val(record[1], line) + result['asset_gainloss'][record[0]] = quantize_val( + record[1], line) return result def get_rec_name(self, name): @@ -416,10 +444,13 @@ class Line(SecondUomMixin, metaclass=PoolMeta): """ recname = super(Line, self).get_rec_name(name) if self.cashbook.feature == 'asset': - credit = self.quantity_credit if self.quantity_credit is not None else Decimal('0.0') - debit = self.quantity_debit if self.quantity_debit is not None else Decimal('0.0') + credit = self.quantity_credit \ + if self.quantity_credit is not None else Decimal('0.0') + debit = self.quantity_debit \ + if self.quantity_debit is not None else Decimal('0.0') recname += '|%(quantity)s %(uom_symbol)s' % { - 'quantity': Report.format_number(credit - debit, + 'quantity': Report.format_number( + credit - debit, lang=None, digits=self.quantity_digits), 'uom_symbol': getattr(self.quantity_uom, 'symbol', '-'), } @@ -453,10 +484,12 @@ class Line(SecondUomMixin, metaclass=PoolMeta): cashbook = Cashbook.browse([id_cashbook])[0] if isinstance(values, dict): - type_ = values.get('bookingtype', getattr(line, 'bookingtype', None)) + type_ = values.get( + 'bookingtype', getattr(line, 'bookingtype', None)) quantity = values.get('quantity', None) - else : - type_ = getattr(values, 'bookingtype', getattr(line, 'bookingtype', None)) + else: + type_ = getattr( + values, 'bookingtype', getattr(line, 'bookingtype', None)) quantity = getattr(values, 'quantity', None) if (type_ is not None) and (cashbook.feature == 'asset'): @@ -471,7 +504,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta): 'quantity_debit': quantity, 'quantity_credit': Decimal('0.0'), }) - else : + else: raise ValueError('invalid "bookingtype"') return result @@ -482,31 +515,35 @@ class Line(SecondUomMixin, metaclass=PoolMeta): """ result = super(Line, cls).get_counterpart_values( line, - splitline = splitline, - values = values + splitline=splitline, + values=values ) line_uom = getattr(line.quantity_uom, 'id', None) - booktransf_uom = getattr(getattr(line.booktransf, 'quantity_uom', {}), 'id', None) + booktransf_uom = getattr(getattr( + line.booktransf, 'quantity_uom', {}), 'id', None) if getattr(splitline, 'quantity', None) is not None: # we add values to the counterpart of a splitbooking-line asset_books = sum([ 1 if splitline.feature == 'asset' else 0, - 1 if getattr(splitline.booktransf, 'feature', '-') == 'asset' else 0, + 1 if getattr( + splitline.booktransf, 'feature', '-') == 'asset' else 0, ]) diff_uom = False if asset_books == 2: - diff_uom = (splitline.quantity_uom != splitline.booktransf.quantity_uom) and \ - (splitline.quantity_uom is not None) and \ - (splitline.booktransf.quantity_uom is not None) + diff_uom = ( + splitline.quantity_uom != + splitline.booktransf.quantity_uom) and \ + (splitline.quantity_uom is not None) and \ + (splitline.booktransf.quantity_uom is not None) result.update({ 'quantity': splitline.quantity_2nd_uom - if (asset_books == 2) and (diff_uom is True) - else splitline.quantity, + if (asset_books == 2) and (diff_uom is True) + else splitline.quantity, 'quantity_2nd_uom': splitline.quantity - if (asset_books == 2) and (diff_uom is True) else None, + if (asset_books == 2) and (diff_uom is True) else None, }) elif sum([1 if booktransf_uom is not None else 0, 1 if line_uom is not None else 0]) == 1: @@ -565,7 +602,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta): if (self.quantity is not None) and \ (self.amount is not None) and \ (self.cashbook.current_rate is not None): - return (self.quantity * self.cashbook.current_rate - + return ( + self.quantity * self.cashbook.current_rate - self.amount).quantize( Decimal(str(1/10**self.currency_digits))) @@ -579,8 +617,9 @@ class Line(SecondUomMixin, metaclass=PoolMeta): (self.amount is not None) and \ (self.amount != Decimal('0.0')) and \ (self.cashbook.current_rate is not None): - return (self.quantity * self.cashbook.current_rate * - Decimal('100.0') / self.amount - Decimal('100.0') + return ( + self.quantity * self.cashbook.current_rate * + Decimal('100.0') / self.amount - Decimal('100.0') ).quantize(Decimal(str(1/10**self.currency_digits))) @fields.depends('splitlines') diff --git a/mixin.py b/mixin.py index 97be83c..3162304 100644 --- a/mixin.py +++ b/mixin.py @@ -6,7 +6,6 @@ from trytond.model import fields from trytond.pyson import Eval, Bool, Or from trytond.pool import Pool -from trytond.transaction import Transaction from trytond.exceptions import UserError from trytond.i18n import gettext from trytond.modules.product.uom import uom_conversion_digits @@ -22,7 +21,8 @@ DEPENDSQ.extend(DEPENDS) class SecondUomMixin(object): """ two fields for second uom: quantity, rate """ - quantity_2nd_uom = fields.Numeric(string='Quantity Second UOM', + quantity_2nd_uom = fields.Numeric( + string='Quantity Second UOM', digits=(16, Eval('quantity2nd_digits', 4)), states={ 'readonly': Or( @@ -32,8 +32,10 @@ class SecondUomMixin(object): 'required': Bool(Eval('quantity2nd')), 'invisible': ~Bool(Eval('quantity2nd')), }, depends=DEPENDSQ+['quantity2nd_digits', 'quantity2nd']) - factor_2nd_uom = fields.Function(fields.Numeric(string='Conversion factor', - help='Conversion factor between the units of the participating cash books.', + factor_2nd_uom = fields.Function(fields.Numeric( + string='Conversion factor', + help='Conversion factor between the units of the ' + + 'participating cash books.', digits=uom_conversion_digits, states={ 'readonly': Or( @@ -45,15 +47,18 @@ class SecondUomMixin(object): }, depends=DEPENDSQ+['quantity2nd_digits', 'quantity2nd']), 'on_change_with_factor_2nd_uom', setter='set_factor_2nd_uom') - quantity2nd = fields.Function(fields.Many2One(model_name='product.uom', + quantity2nd = fields.Function(fields.Many2One( + model_name='product.uom', string="2nd UOM", readonly=True), 'on_change_with_quantity2nd') - quantity2nd_digits = fields.Function(fields.Integer(string='2nd UOM Digits', - readonly=True), 'on_change_with_quantity2nd_digits') + quantity2nd_digits = fields.Function(fields.Integer( + string='2nd UOM Digits', readonly=True), + 'on_change_with_quantity2nd_digits') def quantize_quantity(self, value): """ quantize for line-quantity """ - return Decimal(value).quantize(Decimal(Decimal(1) / 10 ** self.quantity_digits)) + return Decimal(value).quantize( + Decimal(Decimal(1) / 10 ** self.quantity_digits)) @classmethod def add_2nd_quantity(cls, values, from_uom): @@ -68,17 +73,18 @@ class SecondUomMixin(object): quantity_2nd_uom = values.get('quantity_2nd_uom', None) if (quantity is not None) and (booktransf is not None) and \ - (from_uom is not None): + (from_uom is not None): if quantity_2nd_uom is None: booktransf = Cashbook(booktransf) if booktransf.quantity_uom: if from_uom.id != booktransf.quantity_uom.id: # deny impossible transfer - if from_uom.category.id != booktransf.quantity_uom.category.id: + if from_uom.category.id != \ + booktransf.quantity_uom.category.id: raise UserError(gettext( 'cashbook_investment.msg_uomcat_mismatch', - cat1 = from_uom.category.rec_name, - cat2 = booktransf.quantity_uom.category.rec_name, + cat1=from_uom.category.rec_name, + cat2=booktransf.quantity_uom.category.rec_name, )) values['quantity_2nd_uom'] = Decimal(UOM.compute_qty( @@ -87,7 +93,8 @@ class SecondUomMixin(object): booktransf.quantity_uom, round=False, )).quantize(Decimal( - Decimal(1) / 10 ** booktransf.quantity_digits) + Decimal(1) / + 10 ** booktransf.quantity_digits) ) return values @@ -106,7 +113,7 @@ class SecondUomMixin(object): if line.booktransf is None: continue if (line.cashbook.quantity_uom is None) or \ - (line.booktransf.quantity_uom is None): + (line.booktransf.quantity_uom is None): continue if line.cashbook.quantity_uom.id == line.booktransf.quantity_uom.id: @@ -124,24 +131,27 @@ class SecondUomMixin(object): if len(to_write) > 0: Line2.write(*to_write) - @fields.depends('booktransf', '_parent_booktransf.quantity_uom', \ - 'quantity_uom', 'quantity_digits', 'quantity', \ + @fields.depends( + 'booktransf', '_parent_booktransf.quantity_uom', + 'quantity_uom', 'quantity_digits', 'quantity', 'quantity_2nd_uom', 'factor_2nd_uom') def on_change_booktransf(self): """ update quantity_2nd_uom """ self.on_change_factor_2nd_uom() - @fields.depends('booktransf', '_parent_booktransf.quantity_uom', \ - 'quantity_uom', 'quantity_digits', 'quantity', \ + @fields.depends( + 'booktransf', '_parent_booktransf.quantity_uom', + 'quantity_uom', 'quantity_digits', 'quantity', 'quantity_2nd_uom', 'factor_2nd_uom') def on_change_quantity(self): """ update quantity_2nd_uom """ self.on_change_factor_2nd_uom() - @fields.depends('booktransf', '_parent_booktransf.quantity_uom', \ - 'quantity_uom', 'quantity_digits', 'quantity', \ + @fields.depends( + 'booktransf', '_parent_booktransf.quantity_uom', + 'quantity_uom', 'quantity_digits', 'quantity', 'quantity_2nd_uom', 'factor_2nd_uom') def on_change_factor_2nd_uom(self): """ update quantity_2nd_uom + factor_2nd_uom @@ -153,7 +163,7 @@ class SecondUomMixin(object): self.factor_2nd_uom = None return if (self.booktransf.quantity_uom is None) or \ - (self.quantity_uom is None): + (self.quantity_uom is None): return if self.factor_2nd_uom is None: @@ -168,8 +178,9 @@ class SecondUomMixin(object): if self.quantity != Decimal('0.0'): self.factor_2nd_uom = ( self.quantity_2nd_uom / self.quantity - ).quantize(Decimal(Decimal(1) / 10 ** uom_conversion_digits[1])) - else : + ).quantize(Decimal( + Decimal(1) / 10 ** uom_conversion_digits[1])) + else: self.quantity_2nd_uom = self.quantize_quantity( self.quantity * self.factor_2nd_uom) @@ -188,7 +199,8 @@ class SecondUomMixin(object): exp = Decimal(Decimal(1) / 10 ** uom_conversion_digits[1]) return (self.quantity_2nd_uom / self.quantity).quantize(exp) - @fields.depends('booktransf', '_parent_booktransf.quantity_uom', 'quantity_uom') + @fields.depends( + 'booktransf', '_parent_booktransf.quantity_uom', 'quantity_uom') def on_change_with_quantity2nd(self, name=None): """ uom of transfer-target """ @@ -196,7 +208,7 @@ class SecondUomMixin(object): if self.quantity_uom: if self.booktransf.quantity_uom: if self.quantity_uom.id != \ - self.booktransf.quantity_uom.id: + self.booktransf.quantity_uom.id: return self.booktransf.quantity_uom.id @fields.depends('booktransf', '_parent_booktransf.quantity_digits') diff --git a/reconciliation.py b/reconciliation.py index dbcf6f7..b7b85e3 100644 --- a/reconciliation.py +++ b/reconciliation.py @@ -14,22 +14,24 @@ from decimal import Decimal class Reconciliation(metaclass=PoolMeta): __name__ = 'cashbook.recon' - start_quantity = fields.Numeric(string='Start Quantity', - readonly=True, digits=(16, Eval('quantity_digits', 4)), + start_quantity = fields.Numeric( + string='Start Quantity', readonly=True, + digits=(16, Eval('quantity_digits', 4)), states={ 'required': Eval('feature', '') == 'asset', 'invisible': Eval('feature', '') != 'asset', }, depends=['quantity_digits', 'feature']) - end_quantity = fields.Numeric(string='End Quantity', - readonly=True, digits=(16, Eval('quantity_digits', 4)), + end_quantity = fields.Numeric( + string='End Quantity', readonly=True, + digits=(16, Eval('quantity_digits', 4)), states={ 'required': Eval('feature', '') == 'asset', 'invisible': Eval('feature', '') != 'asset', }, depends=['quantity_digits', 'feature']) - quantity_digits = fields.Function(fields.Integer(string='Quantity Digits'), - 'on_change_with_quantity_digits') - quantity_uom = fields.Function(fields.Many2One(string='Symbol', - readonly=True, model_name='product.uom'), + quantity_digits = fields.Function(fields.Integer( + string='Quantity Digits'), 'on_change_with_quantity_digits') + quantity_uom = fields.Function(fields.Many2One( + string='Symbol', readonly=True, model_name='product.uom'), 'on_change_with_quantity_uom') def get_rec_name(self, name): @@ -38,9 +40,11 @@ class Reconciliation(metaclass=PoolMeta): recname = super(Reconciliation, self).get_rec_name(name) if self.cashbook.feature == 'asset': recname += ' | %(start_quantity)s %(uom_symbol)s - %(end_quantity)s %(uom_symbol)s' % { - 'start_quantity': Report.format_number(self.start_quantity or 0.0, None, + 'start_quantity': Report.format_number( + self.start_quantity or 0.0, None, digits=self.quantity_digits), - 'end_quantity': Report.format_number(self.end_quantity or 0.0, None, + 'end_quantity': Report.format_number( + self.end_quantity or 0.0, None, digits=self.quantity_digits), 'uom_symbol': getattr(self.quantity_uom, 'symbol', '-'), } @@ -94,7 +98,7 @@ class Reconciliation(metaclass=PoolMeta): if reconciliation.predecessor: values['start_quantity'] = reconciliation.predecessor.end_quantity - else : + else: values['start_quantity'] = Decimal('0.0') values['end_quantity'] = values['start_quantity'] @@ -106,13 +110,13 @@ class Reconciliation(metaclass=PoolMeta): lines_records = Line.browse(values['lines'][0][1]) values['end_quantity'] += sum([ x.quantity_credit - x.quantity_debit - for x in lines_records + for x in lines_records ]) # add quantities of already linked lines values['end_quantity'] += sum([ x.quantity_credit - x.quantity_debit - for x in reconciliation.lines + for x in reconciliation.lines ]) return values diff --git a/setup.py b/setup.py index 91d8c5c..de14b11 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ """ # Always prefer setuptools over distutils -from setuptools import setup, find_packages +from setuptools import setup # To use a consistent encoding from codecs import open from os import path @@ -36,7 +36,7 @@ with open(path.join(here, 'versiondep.txt'), encoding='utf-8') as f: l2 = i.strip().split(';') if len(l2) < 4: continue - modversion[l2[0]] = {'min':l2[1], 'max':l2[2], 'prefix':l2[3]} + modversion[l2[0]] = {'min': l2[1], 'max': l2[2], 'prefix': l2[3]} # tryton-version major_version = 6 @@ -51,19 +51,22 @@ for dep in info.get('depends', []): prefix = modversion[dep]['prefix'] if len(modversion[dep]['max']) > 0: - requires.append('%s_%s >= %s, <= %s' % - (prefix, dep, modversion[dep]['min'], modversion[dep]['max'])) - else : - requires.append('%s_%s >= %s' % - (prefix, dep, modversion[dep]['min'])) - else : - requires.append('%s_%s >= %s.%s, < %s.%s' % - ('trytond', dep, major_version, minor_version, - major_version, minor_version + 1)) -requires.append('trytond >= %s.%s, < %s.%s' % - (major_version, minor_version, major_version, minor_version + 1)) + requires.append('%s_%s >= %s, <= %s' % ( + prefix, dep, modversion[dep]['min'], + modversion[dep]['max'])) + else: + requires.append('%s_%s >= %s' % ( + prefix, dep, modversion[dep]['min'])) + else: + requires.append( + '%s_%s >= %s.%s, < %s.%s' % ( + 'trytond', dep, major_version, minor_version, + major_version, minor_version + 1)) +requires.append('trytond >= %s.%s, < %s.%s' % ( + major_version, minor_version, major_version, minor_version + 1)) -setup(name='%s_%s' % (PREFIX, MODULE), +setup( + name='%s_%s' % (PREFIX, MODULE), version=info.get('version', '0.0.1'), description='Tryton module to add investment accounts to cashbook.', long_description=long_description, @@ -74,21 +77,21 @@ setup(name='%s_%s' % (PREFIX, MODULE), author_email='service@m-ds.de', license='GPL-3', classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Plugins', - 'Framework :: Tryton', - 'Intended Audience :: Developers', - 'Intended Audience :: Customer Service', - 'Intended Audience :: Information Technology', - 'Intended Audience :: Financial and Insurance Industry', - 'Topic :: Office/Business', - 'Topic :: Office/Business :: Financial :: Accounting', - 'Natural Language :: German', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'License :: OSI Approved :: GNU General Public License (GPL)', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', + 'Development Status :: 5 - Production/Stable', + 'Environment :: Plugins', + 'Framework :: Tryton', + 'Intended Audience :: Developers', + 'Intended Audience :: Customer Service', + 'Intended Audience :: Information Technology', + 'Intended Audience :: Financial and Insurance Industry', + 'Topic :: Office/Business', + 'Topic :: Office/Business :: Financial :: Accounting', + 'Natural Language :: German', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ], keywords='tryton cashbook investment', @@ -97,7 +100,8 @@ setup(name='%s_%s' % (PREFIX, MODULE), 'trytond.modules.%s' % MODULE, ], package_data={ - 'trytond.modules.%s' % MODULE: (info.get('xml', []) + 'trytond.modules.%s' % MODULE: ( + info.get('xml', []) + ['tryton.cfg', 'locale/*.po', 'tests/*.py', 'view/*.xml', 'docs/*.txt', 'versiondep.txt', 'README.rst']), diff --git a/splitline.py b/splitline.py index 539124d..4337e72 100644 --- a/splitline.py +++ b/splitline.py @@ -22,17 +22,18 @@ STATESQ1A['readonly'] = ~And( Eval('booktransf_feature', '') == 'asset', )) + class SplitLine(SecondUomMixin, metaclass=PoolMeta): __name__ = 'cashbook.split' - quantity = fields.Numeric(string='Quantity', - digits=(16, Eval('quantity_digits', 4)), + quantity = fields.Numeric( + string='Quantity', digits=(16, Eval('quantity_digits', 4)), states=STATESQ1A, depends=DEPENDSQ1) - quantity_digits = fields.Function(fields.Integer(string='Digits', - readonly=True, states={'invisible': True}), + quantity_digits = fields.Function(fields.Integer( + string='Digits', readonly=True, states={'invisible': True}), 'on_change_with_quantity_digits') - quantity_uom = fields.Function(fields.Many2One(string='Symbol', - readonly=True, model_name='product.uom'), + quantity_uom = fields.Function(fields.Many2One( + string='Symbol', readonly=True, model_name='product.uom'), 'on_change_with_quantity_uom') def get_rec_name(self, name): @@ -41,13 +42,15 @@ class SplitLine(SecondUomMixin, metaclass=PoolMeta): recname = super(SplitLine, self).get_rec_name(name) if self.line.cashbook.feature == 'asset': recname += '|%(quantity)s %(uom_symbol)s' % { - 'quantity': Report.format_number(self.quantity or 0.0, None, + 'quantity': Report.format_number( + self.quantity or 0.0, None, digits=self.quantity_digits), 'uom_symbol': self.quantity_uom.symbol, } return recname - @fields.depends('line', '_parent_line.cashbook', 'booktransf', \ + @fields.depends( + 'line', '_parent_line.cashbook', 'booktransf', '_parent_booktransf.feature', '_parent_booktransf.quantity_uom') def on_change_with_quantity_uom(self, name=None): """ get quantity-unit of asset @@ -61,7 +64,8 @@ class SplitLine(SecondUomMixin, metaclass=PoolMeta): if self.booktransf.quantity_uom: return self.booktransf.quantity_uom.id - @fields.depends('line', '_parent_line.cashbook', 'booktransf', \ + @fields.depends( + 'line', '_parent_line.cashbook', 'booktransf', '_parent_booktransf.feature', '_parent_booktransf.quantity_digits') def on_change_with_quantity_digits(self, name=None): """ get digits from cashbook @@ -85,7 +89,8 @@ class SplitLine(SecondUomMixin, metaclass=PoolMeta): line = Line2(values.get('line', None)) if line: - values.update(cls.add_2nd_quantity(values, line.cashbook.quantity_uom)) + values.update(cls.add_2nd_quantity( + values, line.cashbook.quantity_uom)) return values # end SplitLine diff --git a/tests/__init__.py b/tests/__init__.py index 97f40bc..6b028e5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,25 +4,14 @@ import trytond.tests.test_tryton import unittest -from trytond.modules.cashbook_investment.tests.test_book import CbInvTestCase -from trytond.modules.cashbook_investment.tests.test_reconciliation import ReconTestCase -from trytond.modules.cashbook_investment.tests.test_yield import YieldTestCase +from .test_module import CashbookInvestmentTestCase __all__ = ['suite'] -class CashbookInvestmentTestCase(\ - CbInvTestCase,\ - ReconTestCase,\ - YieldTestCase,\ - ): - 'Test cashbook-investment module' - module = 'cashbook_investment' - -# end CashbookInvestmentTestCase - def suite(): suite = trytond.tests.test_tryton.suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookInvestmentTestCase)) + suite.addTests(unittest.TestLoader().loadTestsFromTestCase( + CashbookInvestmentTestCase)) return suite diff --git a/tests/test_book.py b/tests/book.py similarity index 80% rename from tests/test_book.py rename to tests/book.py index cf1a17d..02a112a 100644 --- a/tests/test_book.py +++ b/tests/book.py @@ -3,19 +3,15 @@ # The COPYRIGHT file at the top level of this repository contains the # full copyright notices and license terms. -from trytond.tests.test_tryton import ModuleTestCase, with_transaction +from trytond.tests.test_tryton import with_transaction from trytond.pool import Pool from trytond.transaction import Transaction from trytond.exceptions import UserError -from trytond.modules.cashbook.tests import CashbookTestCase -from trytond.modules.investment.tests import InvestmentTestCase from datetime import date from decimal import Decimal -class CbInvTestCase(CashbookTestCase, InvestmentTestCase): - 'Test cashbook-investment module' - module = 'cashbook_investment' +class CbInvTestCase(object): @with_transaction() def test_assetbook_create(self): @@ -67,7 +63,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') Asset.write(*[ @@ -81,7 +77,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('12.5'), }])], }]) - self.assertEqual(asset.rec_name, 'Product 1 | 12.5000 usd/u | 05/02/2022') + self.assertEqual( + asset.rec_name, 'Product 1 | 12.5000 usd/u | 05/02/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -93,8 +90,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }]) with Transaction().set_context({ - 'company': company.id, - }): + 'company': company.id}): books = Book.create([{ 'name': 'L0-Euro-None', 'btype': None, @@ -179,37 +175,51 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(len(books[0].childs), 4) - self.assertEqual(books[0].childs[0].rec_name, + self.assertEqual( + books[0].childs[0].rec_name, 'L0-Euro-None/L1-Euro-Cash | 15.00 € | Open') self.assertEqual(books[0].childs[0].current_value, None) self.assertEqual(books[0].childs[0].current_value_ref, None) self.assertEqual(books[0].childs[0].diff_amount, None) self.assertEqual(books[0].childs[0].diff_percent, None) - self.assertEqual(books[0].childs[1].rec_name, + self.assertEqual( + books[0].childs[1].rec_name, 'L0-Euro-None/L1-Euro-Depot | 15.00 € | Open | 1.0000 u') - self.assertEqual(books[0].childs[1].asset.rec_name, + self.assertEqual( + books[0].childs[1].asset.rec_name, 'Product 1 | 12.5000 usd/u | 05/02/2022') - self.assertEqual(books[0].childs[1].current_value, Decimal('11.9')) - self.assertEqual(books[0].childs[1].current_value_ref, Decimal('11.9')) - self.assertEqual(books[0].childs[1].diff_amount, Decimal('-3.1')) - self.assertEqual(books[0].childs[1].diff_percent, Decimal('-20.67')) + self.assertEqual( + books[0].childs[1].current_value, Decimal('11.9')) + self.assertEqual( + books[0].childs[1].current_value_ref, Decimal('11.9')) + self.assertEqual( + books[0].childs[1].diff_amount, Decimal('-3.1')) + self.assertEqual( + books[0].childs[1].diff_percent, Decimal('-20.67')) - self.assertEqual(books[0].childs[2].rec_name, + self.assertEqual( + books[0].childs[2].rec_name, 'L0-Euro-None/L1-USD-Cash | 15.00 usd | Open') self.assertEqual(books[0].childs[2].current_value, None) self.assertEqual(books[0].childs[2].current_value_ref, None) self.assertEqual(books[0].childs[2].diff_amount, None) self.assertEqual(books[0].childs[2].diff_percent, None) - self.assertEqual(books[0].childs[3].rec_name, + self.assertEqual( + books[0].childs[3].rec_name, 'L0-Euro-None/L1-USD-Depot | 15.00 usd | Open | 1.0000 u') - self.assertEqual(books[0].childs[3].asset.rec_name, + self.assertEqual( + books[0].childs[3].asset.rec_name, 'Product 1 | 12.5000 usd/u | 05/02/2022') - self.assertEqual(books[0].childs[3].current_value, Decimal('12.5')) - self.assertEqual(books[0].childs[3].current_value_ref, Decimal('11.9')) - self.assertEqual(books[0].childs[3].diff_amount, Decimal('-2.5')) - self.assertEqual(books[0].childs[3].diff_percent, Decimal('-16.67')) + self.assertEqual( + books[0].childs[3].current_value, Decimal('12.5')) + self.assertEqual( + books[0].childs[3].current_value_ref, Decimal('11.9')) + self.assertEqual( + books[0].childs[3].diff_amount, Decimal('-2.5')) + self.assertEqual( + books[0].childs[3].diff_percent, Decimal('-16.67')) @with_transaction() def test_assetbook_create_line(self): @@ -233,7 +243,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): party = self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) Asset.write(*[ [asset], @@ -246,7 +256,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('2.8'), }])], }]) - self.assertEqual(asset.rec_name, 'Product 1 | 2.8000 usd/u | 05/02/2022') + self.assertEqual( + asset.rec_name, 'Product 1 | 2.8000 usd/u | 05/02/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -308,16 +319,17 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[1].quantity_uom.symbol, 'u') self.assertEqual(book.symbol, '€/u') - self.assertEqual(book.asset.rec_name, 'Product 1 | 2.8000 usd/u | 05/02/2022') + self.assertEqual( + book.asset.rec_name, + 'Product 1 | 2.8000 usd/u | 05/02/2022') # wf --> check Line.wfcheck(book.lines) # check quantities at cashbook with Transaction().set_context({ - 'qdate': date(2022, 5, 5), - 'company': company.id, - }): + 'qdate': date(2022, 5, 5), + 'company': company.id}): book2, = Book.browse([book]) self.assertEqual(book.asset.rate, Decimal('2.8')) # usd self.assertEqual(book2.quantity, Decimal('1.453')) @@ -327,9 +339,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.current_value_ref, Decimal('3.87')) with Transaction().set_context({ - 'qdate': date(2022, 5, 12), - 'company': company.id, - }): + 'qdate': date(2022, 5, 12), + 'company': company.id}): book2, = Book.browse([book]) self.assertEqual(book2.quantity, Decimal('4.753')) self.assertEqual(book2.quantity_all, Decimal('4.753')) @@ -360,7 +371,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): party = self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -382,7 +393,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('1750.0'), }, ])], }]) - self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -410,7 +423,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): )], }]) - self.assertEqual(book.rec_name, 'Aurum-Storage | 1,250.00 € | Open | 20.000 g') + self.assertEqual( + book.rec_name, + 'Aurum-Storage | 1,250.00 € | Open | 20.000 g') self.assertEqual(book.balance_all, Decimal('1250.0')) self.assertEqual(len(book.lines), 1) @@ -419,13 +434,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity_uom.symbol, 'g') self.assertEqual(book.symbol, '€/g') - self.assertEqual(book.asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + book.asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') # check quantities at cashbook with Transaction().set_context({ - 'qdate': date(2022, 5, 1), - 'company': company.id, - }): + 'qdate': date(2022, 5, 1), + 'company': company.id}): book2, = Book.browse([book]) self.assertEqual(book.asset.rate, Decimal('1750.0')) # usd self.assertEqual(book2.quantity, Decimal('20.0')) @@ -464,7 +480,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): party = self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -486,7 +502,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('1750.0'), }, ])], }]) - self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -526,7 +544,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): )], }]) - self.assertEqual(book.rec_name, 'Aurum-Storage | 1,250.00 CHF | Open | 20.000 g') + self.assertEqual( + book.rec_name, + 'Aurum-Storage | 1,250.00 CHF | Open | 20.000 g') self.assertEqual(book.balance_all, Decimal('1250.0')) self.assertEqual(len(book.lines), 1) @@ -535,13 +555,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity_uom.symbol, 'g') self.assertEqual(book.symbol, 'CHF/g') - self.assertEqual(book.asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + book.asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') # check quantities at cashbook with Transaction().set_context({ - 'qdate': date(2022, 5, 1), - 'company': company.id, - }): + 'qdate': date(2022, 5, 1), + 'company': company.id}): book2, = Book.browse([book]) self.assertEqual(book.asset.rate, Decimal('1750.0')) # usd self.assertEqual(book2.quantity, Decimal('20.0')) @@ -549,7 +570,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): # usd --> chf: 1750 US$ * 0.95 / 1.05 = 1583.333 € # 1 ounce --> 20 gram: 1583.333 CHF * 20 / 28.3495 = 1117.0097 CHF self.assertEqual(book2.current_value, Decimal('1117.01')) # CHF - self.assertEqual(book2.current_value_ref, Decimal('1175.80')) # EUR + self.assertEqual( + book2.current_value_ref, Decimal('1175.80')) # EUR self.assertEqual(book2.diff_amount, Decimal('-132.99')) self.assertEqual(book2.diff_percent, Decimal('-10.64')) self.assertEqual(book2.current_rate, Decimal('55.85')) @@ -574,13 +596,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') - book = Book( - asset = asset, - quantity_uom = None, - ) + book = Book(asset=asset, quantity_uom=None) self.assertEqual(book.quantity_uom, None) book.on_change_asset() self.assertEqual(book.quantity_uom.rec_name, 'Unit') @@ -607,7 +626,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') books = Book.create([{ @@ -628,8 +647,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'number_sequ': self.prep_sequence().id, 'start_date': date(2022, 5, 1), }]) - self.assertEqual(books[0].rec_name, 'Book 1 | 0.00 usd | Open | 0.000 u') - self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open') + self.assertEqual( + books[0].rec_name, 'Book 1 | 0.00 usd | Open | 0.000 u') + self.assertEqual( + books[1].rec_name, 'Book 2 | 0.00 usd | Open') Book.write(*[ [books[0]], @@ -642,7 +663,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity': Decimal('1.0'), }])], }]) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Rev|1.00 usd|- [Cat1]|1.000 u') self.assertEqual(books[0].lines[0].quantity_digits, 3) @@ -656,7 +678,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'amount': Decimal('1.0'), }])], }]) - self.assertEqual(books[1].lines[0].rec_name, + self.assertEqual( + books[1].lines[0].rec_name, '05/01/2022|Rev|1.00 usd|- [Cat1]') self.assertEqual(books[1].lines[0].quantity_digits, 0) @@ -671,7 +694,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'booktransf': books[0].id, }])], }]) - self.assertEqual(books[1].lines[1].rec_name, + self.assertEqual( + books[1].lines[1].rec_name, '05/01/2022|from|1.00 usd|- [Book 1 | 1.00 usd | Open | 1.000 u]') self.assertEqual(books[1].lines[1].quantity_digits, 3) @@ -695,7 +719,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book, = Book.create([{ @@ -716,7 +740,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.asset.rec_name, 'Product 1 | - usd/u | -') self.assertEqual(book.quantity_uom.rec_name, 'Unit') - self.assertRaisesRegex(UserError, + self.assertRaisesRegex( + UserError, 'A value is required for field "Asset" in "Cashbook".', Book.write, *[ @@ -733,8 +758,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): """ pool = Pool() Book = pool.get('cashbook.book') - Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') type_depot = self.prep_type('Depot', 'D') @@ -746,11 +769,11 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category_in = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book, = Book.create([{ @@ -772,7 +795,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(book.rec_name, 'Asset-Book | 1.00 usd | Open | 1.5000 u') + self.assertEqual( + book.rec_name, + 'Asset-Book | 1.00 usd | Open | 1.5000 u') self.assertEqual(len(book.lines), 1) self.assertEqual(book.lines[0].amount, Decimal('1.0')) self.assertEqual(book.lines[0].credit, Decimal('1.0')) @@ -781,16 +806,19 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5')) self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0')) - self.assertRaisesRegex(UserError, - "Quantity and Amount must with same sign for line 05/01/2022|Rev|1.00 usd|buy some [Cat1].", + self.assertRaisesRegex( + UserError, + "Quantity and Amount must with same sign for line " + + "05/01/2022|Rev|1.00 usd|buy some [Cat1].", Book.write, *[ - [book], - { - 'lines': [('write', [book.lines[0]], { - 'quantity': Decimal('-1.5'), + [book], + { + 'lines': [('write', [book.lines[0]], { + 'quantity': Decimal('-1.5'), })], - }]) + } + ]) @with_transaction() def test_assetbook_check_mvout(self): @@ -800,7 +828,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') type_cash = self.prep_type() @@ -811,14 +838,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'feature': 'asset', }]) - category_in = self.prep_category(cattype='in') + self.prep_category(cattype='in') category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book2, = Book.create([{ @@ -859,22 +886,28 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].feature, 'gen') self.assertEqual(book.lines[0].booktransf_feature, 'asset') self.assertEqual(len(book2.lines), 0) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 0.00 usd | Open | 0.0000 u]') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book' + + ' | 0.00 usd | Open | 0.0000 u]') self.assertEqual(len(book.lines[0].references), 0) # update quantity Book.write(*[ [book], { - 'lines': [('write', [book.lines[0]], {'quantity': Decimal('2.5')})], + 'lines': [ + ('write', + [book.lines[0]], {'quantity': Decimal('2.5')})], }]) self.assertEqual(book.lines[0].quantity, Decimal('2.5')) self.assertEqual(book.lines[0].quantity_credit, None) self.assertEqual(book.lines[0].quantity_debit, None) # check counterpart - self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book | 0.00 usd | Open | 0.0000 u') + self.assertEqual( + book.lines[0].booktransf.rec_name, + 'Asset-Book | 0.00 usd | Open | 0.0000 u') self.assertEqual(book.lines[0].booktransf.btype.feature, 'asset') self.assertEqual(book.lines[0].booktransf_feature, 'asset') @@ -883,8 +916,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.rec_name, 'Book 1 | -1.00 usd | Open') self.assertEqual(len(book.lines), 1) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open | 2.5000 u]') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | ' + + '1.00 usd | Open | 2.5000 u]') self.assertEqual(book.lines[0].state, 'check') self.assertEqual(book.lines[0].bookingtype, 'mvout') self.assertEqual(book.lines[0].feature, 'gen') @@ -892,8 +927,11 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].credit, Decimal('0.0')) self.assertEqual(book.lines[0].debit, Decimal('1.0')) self.assertEqual(book.lines[0].quantity, Decimal('2.5')) - self.assertEqual(book.lines[0].quantity_credit, None) # feature != asset - self.assertEqual(book.lines[0].quantity_debit, None) # --> no quantity-credit/debit + self.assertEqual( + book.lines[0].quantity_credit, None) # feature != asset + # --> no quantity-credit/debit + self.assertEqual( + book.lines[0].quantity_debit, None) self.assertEqual(book.lines[0].quantity_2nd_uom, None) self.assertEqual(book.lines[0].factor_2nd_uom, None) self.assertEqual(book.lines[0].quantity2nd, None) @@ -902,10 +940,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].reference, None) self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id) - self.assertEqual(book2.rec_name, 'Asset-Book | 1.00 usd | Open | 2.5000 u') + self.assertEqual( + book2.rec_name, + 'Asset-Book | 1.00 usd | Open | 2.5000 u') self.assertEqual(len(book2.lines), 1) - self.assertEqual(book2.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer Out [Book 1 | -1.00 usd | Open]|2.5000 u') + self.assertEqual( + book2.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer Out [Book 1 | ' + + '-1.00 usd | Open]|2.5000 u') self.assertEqual(book2.lines[0].state, 'check') self.assertEqual(book2.lines[0].bookingtype, 'mvin') self.assertEqual(book2.lines[0].feature, 'asset') @@ -913,23 +955,29 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].credit, Decimal('1.0')) self.assertEqual(book2.lines[0].debit, Decimal('0.0')) self.assertEqual(book2.lines[0].quantity, Decimal('2.5')) - self.assertEqual(book2.lines[0].quantity_credit, Decimal('2.5')) # feature=asset - self.assertEqual(book2.lines[0].quantity_debit, Decimal('0.0')) # needs quantity-credit/debit + self.assertEqual( + book2.lines[0].quantity_credit, + Decimal('2.5')) # feature=asset + self.assertEqual( + book2.lines[0].quantity_debit, + Decimal('0.0')) # needs quantity-credit/debit self.assertEqual(book2.lines[0].quantity_2nd_uom, None) self.assertEqual(book2.lines[0].factor_2nd_uom, None) self.assertEqual(book2.lines[0].quantity2nd, None) self.assertEqual(book2.lines[0].quantity2nd_digits, 4) self.assertEqual(book2.lines[0].asset_rate, Decimal('0.4')) - self.assertEqual(book2.lines[0].reference.rec_name, - '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open | 2.5000 u]') + self.assertEqual( + book2.lines[0].reference.rec_name, + '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | ' + + '1.00 usd | Open | 2.5000 u]') self.assertEqual(len(book2.lines[0].references), 0) l1 = list(book.lines) l1.append(Line( - bookingtype = 'mvout', - amount = Decimal('2.5'), - quantity = Decimal('2.5'), - booktransf = book2, + bookingtype='mvout', + amount=Decimal('2.5'), + quantity=Decimal('2.5'), + booktransf=book2, )) book.lines = l1 book.lines[-1].on_change_quantity() @@ -943,7 +991,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') type_cash = self.prep_type() @@ -956,11 +1003,11 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book1, = Book.create([{ @@ -997,23 +1044,33 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }, ]) - self.assertEqual(book1.rec_name, 'Asset-Book | -10.00 usd | Open | 0.0000 u') + self.assertEqual( + book1.rec_name, + 'Asset-Book | -10.00 usd | Open | 0.0000 u') self.assertEqual(len(book1.lines), 1) - self.assertEqual(book1.lines[0].rec_name, - '05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | 0.00 usd | Open]|0.0000 u') + self.assertEqual( + book1.lines[0].rec_name, + '05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | ' + + '0.00 usd | Open]|0.0000 u') self.assertEqual(book2.rec_name, 'Cash-Book | 0.00 usd | Open') self.assertEqual(len(book2.lines), 0) Line.wfcheck(list(book1.lines)) - self.assertEqual(book1.rec_name, 'Asset-Book | -10.00 usd | Open | 0.0000 u') + self.assertEqual( + book1.rec_name, + 'Asset-Book | -10.00 usd | Open | 0.0000 u') self.assertEqual(len(book1.lines), 1) - self.assertEqual(book1.lines[0].rec_name, - '05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | 10.00 usd | Open]|0.0000 u') + self.assertEqual( + book1.lines[0].rec_name, + '05/01/2022|to|-10.00 usd|loss at sell [Cash-Book | ' + + '10.00 usd | Open]|0.0000 u') self.assertEqual(book2.rec_name, 'Cash-Book | 10.00 usd | Open') self.assertEqual(len(book2.lines), 1) - self.assertEqual(book2.lines[0].rec_name, - '05/01/2022|from|10.00 usd|loss at sell [Asset-Book | -10.00 usd | Open | 0.0000 u]') + self.assertEqual( + book2.lines[0].rec_name, + '05/01/2022|from|10.00 usd|loss at sell [Asset-Book | ' + + '-10.00 usd | Open | 0.0000 u]') @with_transaction() def test_assetbook_check_mvin(self): @@ -1023,7 +1080,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') type_cash = self.prep_type() @@ -1034,14 +1090,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'feature': 'asset', }]) - category_in = self.prep_category(cattype='in') + self.prep_category(cattype='in') category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book2, = Book.create([{ @@ -1081,12 +1137,16 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].booktransf_feature, 'asset') self.assertEqual(book.lines[0].splitline_has_quantity, False) self.assertEqual(len(book2.lines), 0) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | 0.00 usd | Open | 0.0000 u]') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | ' + + '0.00 usd | Open | 0.0000 u]') self.assertEqual(len(book.lines[0].references), 0) # check counterpart - self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book | 0.00 usd | Open | 0.0000 u') + self.assertEqual( + book.lines[0].booktransf.rec_name, + 'Asset-Book | 0.00 usd | Open | 0.0000 u') self.assertEqual(book.lines[0].booktransf.btype.feature, 'asset') self.assertEqual(book.lines[0].booktransf_feature, 'asset') @@ -1095,8 +1155,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.rec_name, 'Book 1 | 1.00 usd | Open') self.assertEqual(len(book.lines), 1) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | -1.00 usd | Open | -1.5000 u]') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | ' + + '-1.00 usd | Open | -1.5000 u]') self.assertEqual(book.lines[0].state, 'check') self.assertEqual(book.lines[0].bookingtype, 'mvin') self.assertEqual(book.lines[0].feature, 'gen') @@ -1104,8 +1166,11 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].credit, Decimal('1.0')) self.assertEqual(book.lines[0].debit, Decimal('0.0')) self.assertEqual(book.lines[0].quantity, Decimal('1.5')) - self.assertEqual(book.lines[0].quantity_credit, None) # feature != asset - self.assertEqual(book.lines[0].quantity_debit, None) # --> no quantity-credit/debit + self.assertEqual( + book.lines[0].quantity_credit, None) # feature != asset + self.assertEqual( + book.lines[0].quantity_debit, + None) # --> no quantity-credit/debit self.assertEqual(book.lines[0].quantity_2nd_uom, None) self.assertEqual(book.lines[0].factor_2nd_uom, None) self.assertEqual(book.lines[0].quantity2nd, None) @@ -1114,10 +1179,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].reference, None) self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id) - self.assertEqual(book2.rec_name, 'Asset-Book | -1.00 usd | Open | -1.5000 u') + self.assertEqual( + book2.rec_name, + 'Asset-Book | -1.00 usd | Open | -1.5000 u') self.assertEqual(len(book2.lines), 1) - self.assertEqual(book2.lines[0].rec_name, - '05/01/2022|to|-1.00 usd|Transfer In [Book 1 | 1.00 usd | Open]|-1.5000 u') + self.assertEqual( + book2.lines[0].rec_name, + '05/01/2022|to|-1.00 usd|Transfer In [Book 1 | ' + + '1.00 usd | Open]|-1.5000 u') self.assertEqual(book2.lines[0].state, 'check') self.assertEqual(book2.lines[0].bookingtype, 'mvout') self.assertEqual(book2.lines[0].feature, 'asset') @@ -1125,15 +1194,21 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].credit, Decimal('0.0')) self.assertEqual(book2.lines[0].debit, Decimal('1.0')) self.assertEqual(book2.lines[0].quantity, Decimal('1.5')) - self.assertEqual(book2.lines[0].quantity_credit, Decimal('0.0')) # feature=asset - self.assertEqual(book2.lines[0].quantity_debit, Decimal('1.5')) # needs quantity-credit/debit + self.assertEqual( + book2.lines[0].quantity_credit, + Decimal('0.0')) # feature=asset + self.assertEqual( + book2.lines[0].quantity_debit, + Decimal('1.5')) # needs quantity-credit/debit self.assertEqual(book2.lines[0].quantity_2nd_uom, None) self.assertEqual(book2.lines[0].factor_2nd_uom, None) self.assertEqual(book2.lines[0].quantity2nd, None) self.assertEqual(book2.lines[0].quantity2nd_digits, 4) self.assertEqual(book2.lines[0].asset_rate, Decimal('0.6667')) - self.assertEqual(book2.lines[0].reference.rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | -1.00 usd | Open | -1.5000 u]') + self.assertEqual( + book2.lines[0].reference.rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book | ' + + '-1.00 usd | Open | -1.5000 u]') self.assertEqual(len(book2.lines[0].references), 0) @with_transaction() @@ -1144,10 +1219,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') - type_cash = self.prep_type() + self.prep_type() type_depot = self.prep_type('Depot', 'D') BType.write(*[ [type_depot], @@ -1155,14 +1229,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'feature': 'asset', }]) - category_in = self.prep_category(cattype='in') + self.prep_category(cattype='in') category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book2, = Book.create([{ @@ -1195,7 +1269,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity': Decimal('1.5'), }])], }]) - self.assertEqual(book.rec_name, 'Asset-Book 2 | 1.00 usd | Open | 1.5000 u') + self.assertEqual( + book.rec_name, + 'Asset-Book 2 | 1.00 usd | Open | 1.5000 u') self.assertEqual(len(book.lines), 1) self.assertEqual(book.lines[0].amount, Decimal('1.0')) self.assertEqual(book.lines[0].credit, Decimal('1.0')) @@ -1206,22 +1282,30 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].feature, 'asset') self.assertEqual(book.lines[0].booktransf_feature, 'asset') self.assertEqual(len(book2.lines), 0) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | 0.00 usd | Open | 0.0000 u]|1.5000 u') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '0.00 usd | Open | 0.0000 u]|1.5000 u') self.assertEqual(len(book.lines[0].references), 0) # check counterpart - self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book 1 | 0.00 usd | Open | 0.0000 u') + self.assertEqual( + book.lines[0].booktransf.rec_name, + 'Asset-Book 1 | 0.00 usd | Open | 0.0000 u') self.assertEqual(book.lines[0].booktransf.btype.feature, 'asset') self.assertEqual(book.lines[0].booktransf_feature, 'asset') # set line to 'checked', this creates the counterpart Line.wfcheck(list(book.lines)) - self.assertEqual(book.rec_name, 'Asset-Book 2 | 1.00 usd | Open | 1.5000 u') + self.assertEqual( + book.rec_name, + 'Asset-Book 2 | 1.00 usd | Open | 1.5000 u') self.assertEqual(len(book.lines), 1) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | -1.00 usd | Open | -1.5000 u]|1.5000 u') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '-1.00 usd | Open | -1.5000 u]|1.5000 u') self.assertEqual(book.lines[0].state, 'check') self.assertEqual(book.lines[0].bookingtype, 'mvin') self.assertEqual(book.lines[0].feature, 'asset') @@ -1239,10 +1323,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].reference, None) self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id) - self.assertEqual(book2.rec_name, 'Asset-Book 1 | -1.00 usd | Open | -1.5000 u') + self.assertEqual( + book2.rec_name, + 'Asset-Book 1 | -1.00 usd | Open | -1.5000 u') self.assertEqual(len(book2.lines), 1) - self.assertEqual(book2.lines[0].rec_name, - '05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 u]|-1.5000 u') + self.assertEqual( + book2.lines[0].rec_name, + '05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | ' + + '1.00 usd | Open | 1.5000 u]|-1.5000 u') self.assertEqual(book2.lines[0].state, 'check') self.assertEqual(book2.lines[0].bookingtype, 'mvout') self.assertEqual(book2.lines[0].feature, 'asset') @@ -1257,8 +1345,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].quantity2nd, None) self.assertEqual(book2.lines[0].quantity2nd_digits, 4) self.assertEqual(book2.lines[0].asset_rate, Decimal('0.6667')) - self.assertEqual(book2.lines[0].reference.rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | -1.00 usd | Open | -1.5000 u]|1.5000 u') + self.assertEqual( + book2.lines[0].reference.rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '-1.00 usd | Open | -1.5000 u]|1.5000 u') self.assertEqual(len(book2.lines[0].references), 0) @with_transaction() @@ -1270,13 +1360,12 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') UOM = pool.get('product.uom') ProdTempl = pool.get('product.template') Asset = pool.get('investment.asset') - type_cash = self.prep_type() + self.prep_type() type_depot = self.prep_type('Depot', 'D') BType.write(*[ [type_depot], @@ -1284,17 +1373,17 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'feature': 'asset', }]) - category_in = self.prep_category(cattype='in') + self.prep_category(cattype='in') category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset1 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) asset2 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 2')) + product=self.prep_asset_product(name='Product 2')) uom_grams = UOM.search([('symbol', '=', 'g')])[0] uom_ounce = UOM.search([('symbol', '=', 'oz')])[0] @@ -1352,7 +1441,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity': Decimal('1.5'), }])], }]) - self.assertEqual(book.rec_name, 'Asset-Book 2 | 1.00 usd | Open | 1.5000 oz') + self.assertEqual( + book.rec_name, + 'Asset-Book 2 | 1.00 usd | Open | 1.5000 oz') self.assertEqual(len(book.lines), 1) self.assertEqual(book.lines[0].amount, Decimal('1.0')) self.assertEqual(book.lines[0].credit, Decimal('1.0')) @@ -1364,27 +1455,39 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity_uom.factor, 0.028349523125) self.assertEqual(book.lines[0].quantity2nd.symbol, 'g') self.assertEqual(book.lines[0].quantity2nd.factor, 0.001) - self.assertEqual(book.lines[0].quantity_2nd_uom, Decimal('42.5243')) # 1.5 oz --> g - self.assertEqual(book.lines[0].factor_2nd_uom, Decimal('28.349533333333')) + self.assertEqual( + book.lines[0].quantity_2nd_uom, + Decimal('42.5243')) # 1.5 oz --> g + self.assertEqual( + book.lines[0].factor_2nd_uom, + Decimal('28.349533333333')) self.assertEqual(book.lines[0].quantity2nd_digits, 4) self.assertEqual(book.lines[0].feature, 'asset') self.assertEqual(len(book2.lines), 0) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | 0.00 usd | Open | 0.0000 g]|1.5000 oz') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '0.00 usd | Open | 0.0000 g]|1.5000 oz') self.assertEqual(len(book.lines[0].references), 0) # check counterpart - self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book 1 | 0.00 usd | Open | 0.0000 g') + self.assertEqual( + book.lines[0].booktransf.rec_name, + 'Asset-Book 1 | 0.00 usd | Open | 0.0000 g') self.assertEqual(book.lines[0].booktransf.btype.feature, 'asset') self.assertEqual(book.lines[0].booktransf_feature, 'asset') # set line to 'checked', this creates the counterpart Line.wfcheck(list(book.lines)) - self.assertEqual(book.rec_name, 'Asset-Book 2 | 1.00 usd | Open | 1.5000 oz') + self.assertEqual( + book.rec_name, + 'Asset-Book 2 | 1.00 usd | Open | 1.5000 oz') self.assertEqual(len(book.lines), 1) - self.assertEqual(book.lines[0].rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | -1.00 usd | Open | -42.5243 g]|1.5000 oz') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '-1.00 usd | Open | -42.5243 g]|1.5000 oz') self.assertEqual(book.lines[0].state, 'check') self.assertEqual(book.lines[0].bookingtype, 'mvin') self.assertEqual(book.lines[0].feature, 'asset') @@ -1395,7 +1498,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5')) self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0')) self.assertEqual(book.lines[0].quantity_2nd_uom, Decimal('42.5243')) - self.assertEqual(book.lines[0].factor_2nd_uom, Decimal('28.349533333333')) + self.assertEqual( + book.lines[0].factor_2nd_uom, + Decimal('28.349533333333')) self.assertEqual(book.lines[0].quantity2nd.symbol, 'g') self.assertEqual(book.lines[0].quantity2nd.factor, 0.001) self.assertEqual(book.lines[0].quantity2nd_digits, 4) @@ -1403,10 +1508,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].reference, None) self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id) - self.assertEqual(book2.rec_name, 'Asset-Book 1 | -1.00 usd | Open | -42.5243 g') + self.assertEqual( + book2.rec_name, + 'Asset-Book 1 | -1.00 usd | Open | -42.5243 g') self.assertEqual(len(book2.lines), 1) - self.assertEqual(book2.lines[0].rec_name, - '05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | 1.00 usd | Open | 1.5000 oz]|-42.5243 g') + self.assertEqual( + book2.lines[0].rec_name, + '05/01/2022|to|-1.00 usd|Transfer In [Asset-Book 2 | ' + + '1.00 usd | Open | 1.5000 oz]|-42.5243 g') self.assertEqual(book2.lines[0].state, 'check') self.assertEqual(book2.lines[0].bookingtype, 'mvout') self.assertEqual(book2.lines[0].feature, 'asset') @@ -1417,13 +1526,17 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book2.lines[0].quantity_credit, Decimal('0.0')) self.assertEqual(book2.lines[0].quantity_debit, Decimal('42.5243')) self.assertEqual(book2.lines[0].quantity_2nd_uom, Decimal('1.5')) - self.assertEqual(book2.lines[0].factor_2nd_uom, Decimal('0.035273949248')) + self.assertEqual( + book2.lines[0].factor_2nd_uom, + Decimal('0.035273949248')) self.assertEqual(book2.lines[0].quantity2nd.symbol, 'oz') self.assertEqual(book2.lines[0].quantity2nd.factor, 0.028349523125) self.assertEqual(book2.lines[0].quantity2nd_digits, 4) self.assertEqual(book2.lines[0].asset_rate, Decimal('0.0235')) - self.assertEqual(book2.lines[0].reference.rec_name, - '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | -1.00 usd | Open | -42.5243 g]|1.5000 oz') + self.assertEqual( + book2.lines[0].reference.rec_name, + '05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | ' + + '-1.00 usd | Open | -42.5243 g]|1.5000 oz') self.assertEqual(len(book2.lines[0].references), 0) @with_transaction() @@ -1434,14 +1547,12 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): """ pool = Pool() Book = pool.get('cashbook.book') - Line = pool.get('cashbook.line') - Category = pool.get('cashbook.category') BType = pool.get('cashbook.type') UOM = pool.get('product.uom') ProdTempl = pool.get('product.template') Asset = pool.get('investment.asset') - type_cash = self.prep_type() + self.prep_type() type_depot = self.prep_type('Depot', 'D') BType.write(*[ [type_depot], @@ -1449,17 +1560,17 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'feature': 'asset', }]) - category_in = self.prep_category(cattype='in') + self.prep_category(cattype='in') category_out = self.prep_category(name='Out Category', cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset1 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) asset2 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 2')) + product=self.prep_asset_product(name='Product 2')) uom_grams = UOM.search([('symbol', '=', 'g')])[0] uom_min = UOM.search([('symbol', '=', 'min')])[0] @@ -1509,7 +1620,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'start_date': date(2022, 5, 1), }]) - self.assertRaisesRegex(UserError, + self.assertRaisesRegex( + UserError, r'Cannot transfer quantities between cashbooks with different unit-categories \(Time != Weight\).', Book.write, *[ @@ -1534,9 +1646,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types = self.prep_type() BType.write(*[ @@ -1547,10 +1656,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book, = Book.create([{ @@ -1595,7 +1704,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.lines[0].quantity, Decimal('4.0')) self.assertEqual(book.lines[0].quantity_uom.symbol, 'u') self.assertEqual(book.lines[0].splitline_has_quantity, False) - self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') self.assertEqual(len(book.lines[0].splitlines), 2) self.assertEqual(book.lines[0].splitlines[0].splittype, 'cat') @@ -1614,9 +1725,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types = self.prep_type() BType.write(*[ @@ -1627,10 +1735,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') books = Book.create([{ @@ -1677,7 +1785,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(books[0].rec_name, 'Book 1 | 11.00 usd | Open | 4.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | 11.00 usd | Open | 4.00 u') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) @@ -1685,18 +1795,27 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].lines[0].quantity, Decimal('4.0')) self.assertEqual(books[0].lines[0].quantity_uom.symbol, 'u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) - self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') + self.assertEqual( + books[0].lines[0].rec_name, + '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') self.assertEqual(len(books[0].lines[0].splitlines), 2) self.assertEqual(books[0].lines[0].splitlines[0].splittype, 'cat') self.assertEqual(books[0].lines[0].splitlines[0].amount, Decimal('5.0')) - self.assertEqual(books[0].lines[0].splitlines[0].quantity, Decimal('1.5')) - self.assertEqual(books[0].lines[0].splitlines[0].category.rec_name, 'Cat1') + self.assertEqual( + books[0].lines[0].splitlines[0].quantity, + Decimal('1.5')) + self.assertEqual( + books[0].lines[0].splitlines[0].category.rec_name, + 'Cat1') self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None) self.assertEqual(books[0].lines[0].splitlines[1].splittype, 'tr') self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0')) - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book 2 | 0.00 usd | Open | 0.00 u') self.assertEqual(len(books[0].lines[0].references), 0) self.assertEqual(books[0].lines[0].reference, None) @@ -1707,7 +1826,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Line.wfcheck([books[0].lines[0]]) - self.assertEqual(books[0].rec_name, 'Book 1 | 11.00 usd | Open | 4.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | 11.00 usd | Open | 4.00 u') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) @@ -1715,29 +1836,44 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].lines[0].quantity, Decimal('4.0')) self.assertEqual(books[0].lines[0].quantity_uom.symbol, 'u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) - self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') + self.assertEqual( + books[0].lines[0].rec_name, + '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u') self.assertEqual(len(books[0].lines[0].splitlines), 2) self.assertEqual(books[0].lines[0].splitlines[0].splittype, 'cat') self.assertEqual(books[0].lines[0].splitlines[0].amount, Decimal('5.0')) - self.assertEqual(books[0].lines[0].splitlines[0].quantity, Decimal('1.5')) - self.assertEqual(books[0].lines[0].splitlines[0].category.rec_name, 'Cat1') + self.assertEqual( + books[0].lines[0].splitlines[0].quantity, + Decimal('1.5')) + self.assertEqual( + books[0].lines[0].splitlines[0].category.rec_name, + 'Cat1') self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None) self.assertEqual(books[0].lines[0].splitlines[1].splittype, 'tr') self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0')) - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book 2 | -6.00 usd | Open | -2.50 u') self.assertEqual(len(books[0].lines[0].references), 1) - self.assertEqual(books[0].lines[0].references[0].rec_name, - '05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|-2.50 u') + self.assertEqual( + books[0].lines[0].references[0].rec_name, + '05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd' + + ' | Open | 4.00 u]|-2.50 u') self.assertEqual(books[0].lines[0].reference, None) - self.assertEqual(books[1].rec_name, 'Book 2 | -6.00 usd | Open | -2.50 u') + self.assertEqual( + books[1].rec_name, + 'Book 2 | -6.00 usd | Open | -2.50 u') self.assertEqual(books[1].balance_all, Decimal('-6.0')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open | 4.00 u]|-2.50 u') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd' + + ' | Open | 4.00 u]|-2.50 u') @with_transaction() def test_assetbook_split_in_category_and_assetbook_zero_quantity(self): @@ -1749,9 +1885,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types = self.prep_type() BType.write(*[ @@ -1762,10 +1895,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') books = Book.create([{ @@ -1812,20 +1945,28 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(books[0].rec_name, 'Book 1 | 11.00 usd | Open | 0.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | 11.00 usd | Open | 0.00 u') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|0.00 u') + self.assertEqual( + books[0].lines[0].rec_name, + '05/01/2022|Rev/Sp|11.00 usd|- [-]|0.00 u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|gain on sell [Cat1]|0.00 u') self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None) - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | 0.00 usd | Open | 0.00 u]|0.00 u') - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | 0.00 usd' + + ' | Open | 0.00 u]|0.00 u') + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book 2 | 0.00 usd | Open | 0.00 u') self.assertEqual(len(books[0].lines[0].references), 0) self.assertEqual(books[0].lines[0].reference, None) @@ -1836,31 +1977,45 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Line.wfcheck([books[0].lines[0]]) - self.assertEqual(books[0].rec_name, 'Book 1 | 11.00 usd | Open | 0.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | 11.00 usd | Open | 0.00 u') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|0.00 u') + self.assertEqual( + books[0].lines[0].rec_name, + '05/01/2022|Rev/Sp|11.00 usd|- [-]|0.00 u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|gain on sell [Cat1]|0.00 u') self.assertEqual(books[0].lines[0].splitlines[0].booktransf, None) - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | -6.00 usd | Open | 0.00 u]|0.00 u') - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Rev/Sp|6.00 usd|transfer zero quantity [Book 2 | -6.00 usd' + + ' | Open | 0.00 u]|0.00 u') + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book 2 | -6.00 usd | Open | 0.00 u') self.assertEqual(len(books[0].lines[0].references), 1) - self.assertEqual(books[0].lines[0].references[0].rec_name, - '05/01/2022|to|-6.00 usd|transfer zero quantity [Book 1 | 11.00 usd | Open | 0.00 u]|0.00 u') + self.assertEqual( + books[0].lines[0].references[0].rec_name, + '05/01/2022|to|-6.00 usd|transfer zero quantity [Book 1 | ' + + '11.00 usd | Open | 0.00 u]|0.00 u') self.assertEqual(books[0].lines[0].reference, None) - self.assertEqual(books[1].rec_name, 'Book 2 | -6.00 usd | Open | 0.00 u') + self.assertEqual( + books[1].rec_name, + 'Book 2 | -6.00 usd | Open | 0.00 u') self.assertEqual(books[1].balance_all, Decimal('-6.0')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|to|-6.00 usd|transfer zero quantity [Book 1 | 11.00 usd | Open | 0.00 u]|0.00 u') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|to|-6.00 usd|transfer zero quantity [Book 1 | ' + + '11.00 usd | Open | 0.00 u]|0.00 u') @with_transaction() def test_assetbook_split_in_catergory_asset_diff_unit(self): @@ -1885,10 +2040,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -1910,7 +2065,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('1750.0'), }, ])], }]) - self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -1937,10 +2094,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity_uom': gram.id, 'quantity_digits': 3, }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') self.assertEqual(books[0].balance_all, Decimal('0.0')) self.assertEqual(len(books[0].lines), 0) - self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | 0.00 € | Open | 0.000 g') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) @@ -1966,41 +2127,63 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 11.00 usd | Open | 4.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 11.00 usd | Open | 4.000 oz') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.000 oz') self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|from category [Cat1]|1.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | 0.00 € | Open | 0.000 g]|2.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) - self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, Decimal('70.874')) + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | 0.00 € | ' + + 'Open | 0.000 g]|2.500 oz') + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].quantity_2nd_uom, + Decimal('70.874')) - self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | 0.00 € | Open | 0.000 g') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) Line.wfcheck([books[0].lines[0]]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 11.00 usd | Open | 4.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 11.00 usd | Open | 4.000 oz') self.assertEqual(books[0].balance_all, Decimal('11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.000 oz') self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|from category [Cat1]|1.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | -5.71 € | Open | -70.874 g]|2.500 oz') + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Rev/Sp|6.00 usd|from cashbook [Book gram|euro | -5.71 € | ' + + 'Open | -70.874 g]|2.500 oz') - self.assertEqual(books[1].rec_name, 'Book gram|euro | -5.71 € | Open | -70.874 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | -5.71 € | Open | -70.874 g') self.assertEqual(books[1].balance_all, Decimal('-5.71')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|to|-5.71 €|from cashbook [Book ounce|usd | 11.00 usd | Open | 4.000 oz]|-70.874 g') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|to|-5.71 €|from cashbook [Book ounce|usd | ' + + '11.00 usd | Open | 4.000 oz]|-70.874 g') @with_transaction() def test_assetbook_split_in_catergory_asset_diff_unit_diff_cat(self): @@ -2010,7 +2193,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): """ pool = Pool() Book = pool.get('cashbook.book') - Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') Asset = pool.get('investment.asset') ProdTempl = pool.get('product.template') @@ -2025,13 +2207,13 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='in') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset1 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) asset2 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product Liter')) + product=self.prep_asset_product(name='Product Liter')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -2068,7 +2250,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }, ])], }, ]) - self.assertEqual(asset1.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset1.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') self.assertEqual(asset2.rec_name, 'Liquid | 10.0000 usd/l | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) @@ -2097,14 +2281,19 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity_uom': liter.id, 'quantity_digits': 3, }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') self.assertEqual(books[0].balance_all, Decimal('0.0')) self.assertEqual(len(books[0].lines), 0) - self.assertEqual(books[1].rec_name, 'Book liter|euro | 0.00 € | Open | 0.000 l') + self.assertEqual( + books[1].rec_name, + 'Book liter|euro | 0.00 € | Open | 0.000 l') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) - self.assertRaisesRegex(UserError, + self.assertRaisesRegex( + UserError, r"Cannot transfer quantities between cashbooks with different unit-categories \(Weight != Volume\).", Book.write, *[ @@ -2137,9 +2326,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): pool = Pool() Book = pool.get('cashbook.book') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types = self.prep_type() BType.write(*[ @@ -2150,10 +2336,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book, = Book.create([{ @@ -2194,12 +2380,16 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(book.balance_all, Decimal('-11.0')) self.assertEqual(len(book.lines), 1) self.assertEqual(book.lines[0].splitline_has_quantity, False) - self.assertEqual(book.lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u') + self.assertEqual( + book.lines[0].rec_name, + '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u') self.assertEqual(len(book.lines[0].splitlines), 2) - self.assertEqual(book.lines[0].splitlines[0].rec_name, + self.assertEqual( + book.lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u') - self.assertEqual(book.lines[0].splitlines[1].rec_name, + self.assertEqual( + book.lines[0].splitlines[1].rec_name, 'Exp/Sp|6.00 usd|to category [Cat1]|2.50 u') @with_transaction() @@ -2211,9 +2401,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types = self.prep_type() BType.write(*[ @@ -2224,10 +2411,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') books = Book.create([{ @@ -2274,19 +2461,25 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(books[0].rec_name, 'Book 1 | -11.00 usd | Open | -4.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | -11.00 usd | Open | -4.00 u') self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book 2 | 0.00 usd | Open | 0.00 u]|2.50 u') + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book 2 | 0.00 usd | Open ' + + '| 0.00 u]|2.50 u') self.assertEqual(len(books[0].lines[0].references), 0) self.assertEqual(books[0].lines[0].reference, None) @@ -2297,35 +2490,50 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Line.wfcheck([books[0].lines[0]]) - self.assertEqual(books[0].rec_name, 'Book 1 | -11.00 usd | Open | -4.00 u') + self.assertEqual( + books[0].rec_name, + 'Book 1 | -11.00 usd | Open | -4.00 u') self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.00 u') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]|1.50 u') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book 2 | 6.00 usd | Open | 2.50 u]|2.50 u') + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book 2 | 6.00 usd | Open' + + ' | 2.50 u]|2.50 u') self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0')) - self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, None) - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].amount_2nd_currency, + None) + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) self.assertEqual(books[0].lines[0].splitlines[1].quantity2nd, None) - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book 2 | 6.00 usd | Open | 2.50 u') self.assertEqual(len(books[0].lines[0].references), 1) - self.assertEqual(books[0].lines[0].references[0].rec_name, - '05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd | Open | -4.00 u]|2.50 u') + self.assertEqual( + books[0].lines[0].references[0].rec_name, + '05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd' + + ' | Open | -4.00 u]|2.50 u') self.assertEqual(books[0].lines[0].reference, None) self.assertEqual(books[1].rec_name, 'Book 2 | 6.00 usd | Open | 2.50 u') self.assertEqual(books[1].balance_all, Decimal('6.0')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd | Open | -4.00 u]|2.50 u') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|from|6.00 usd|to cashbook [Book 1 | -11.00 usd' + + ' | Open | -4.00 u]|2.50 u') @with_transaction() def test_assetbook_split_out_category_and_assetbook2(self): @@ -2336,9 +2544,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): Book = pool.get('cashbook.book') Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') - Asset = pool.get('investment.asset') - ProdTempl = pool.get('product.template') - Uom = pool.get('product.uom') types_asset = self.prep_type() BType.write(*[ @@ -2354,10 +2559,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') books = Book.create([{ @@ -2404,7 +2609,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]') self.assertEqual(books[0].lines[0].quantity, Decimal('2.5')) self.assertEqual(books[0].lines[0].quantity_credit, None) @@ -2413,19 +2619,26 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]') self.assertEqual(books[0].lines[0].splitlines[0].quantity, None) self.assertEqual(books[0].lines[0].splitlines[0].quantity_2nd_uom, None) - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book Asset | 0.00 usd | Open | 0.00 u]') - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book Asset | 0.00 usd | ' + + 'Open | 0.00 u]') + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, None) self.assertEqual(len(books[0].lines[0].references), 0) self.assertEqual(books[0].lines[0].reference, None) - self.assertEqual(books[1].rec_name, 'Book Asset | 0.00 usd | Open | 0.00 u') + self.assertEqual( + books[1].rec_name, + 'Book Asset | 0.00 usd | Open | 0.00 u') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) @@ -2435,7 +2648,8 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]') self.assertEqual(books[0].lines[0].splitline_has_quantity, True) self.assertEqual(books[0].lines[0].quantity, Decimal('2.5')) @@ -2444,26 +2658,40 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): self.assertEqual(books[0].lines[0].quantity_2nd_uom, None) self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book Asset | 6.00 usd | Open | 2.50 u]') + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book Asset | 6.00 usd' + + ' | Open | 2.50 u]') self.assertEqual(books[0].lines[0].splitlines[1].amount, Decimal('6.0')) - self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, None) - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].amount_2nd_currency, + None) + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) self.assertEqual(books[0].lines[0].splitlines[1].quantity2nd, None) - self.assertEqual(books[0].lines[0].splitlines[1].booktransf.rec_name, + self.assertEqual( + books[0].lines[0].splitlines[1].booktransf.rec_name, 'Book Asset | 6.00 usd | Open | 2.50 u') self.assertEqual(len(books[0].lines[0].references), 1) - self.assertEqual(books[0].lines[0].references[0].rec_name, - '05/01/2022|from|6.00 usd|to cashbook [Book Cash | -11.00 usd | Open]|2.50 u') + self.assertEqual( + books[0].lines[0].references[0].rec_name, + '05/01/2022|from|6.00 usd|to cashbook [Book Cash | ' + + '-11.00 usd | Open]|2.50 u') self.assertEqual(books[0].lines[0].reference, None) - self.assertEqual(books[1].rec_name, 'Book Asset | 6.00 usd | Open | 2.50 u') + self.assertEqual( + books[1].rec_name, + 'Book Asset | 6.00 usd | Open | 2.50 u') self.assertEqual(books[1].balance_all, Decimal('6.0')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|from|6.00 usd|to cashbook [Book Cash | -11.00 usd | Open]|2.50 u') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|from|6.00 usd|to cashbook [Book Cash | ' + + '-11.00 usd | Open]|2.50 u') @with_transaction() def test_assetbook_split_out_catergory_asset_diff_unit(self): @@ -2488,10 +2716,10 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -2513,7 +2741,9 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'rate': Decimal('1750.0'), }, ])], }]) - self.assertEqual(asset.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -2540,10 +2770,14 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity_uom': gram.id, 'quantity_digits': 3, }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') self.assertEqual(books[0].balance_all, Decimal('0.0')) self.assertEqual(len(books[0].lines), 0) - self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | 0.00 € | Open | 0.000 g') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) @@ -2569,41 +2803,63 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }])], }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | -11.00 usd | Open | -4.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | -11.00 usd | Open | -4.000 oz') self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.000 oz') self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]|1.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 0.00 € | Open | 0.000 g]|2.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].quantity, Decimal('2.5')) - self.assertEqual(books[0].lines[0].splitlines[1].quantity_2nd_uom, Decimal('70.874')) + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 0.00 € | ' + + 'Open | 0.000 g]|2.500 oz') + self.assertEqual( + books[0].lines[0].splitlines[1].quantity, + Decimal('2.5')) + self.assertEqual( + books[0].lines[0].splitlines[1].quantity_2nd_uom, + Decimal('70.874')) - self.assertEqual(books[1].rec_name, 'Book gram|euro | 0.00 € | Open | 0.000 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | 0.00 € | Open | 0.000 g') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) Line.wfcheck([books[0].lines[0]]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | -11.00 usd | Open | -4.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | -11.00 usd | Open | -4.000 oz') self.assertEqual(books[0].balance_all, Decimal('-11.0')) self.assertEqual(len(books[0].lines), 1) - self.assertEqual(books[0].lines[0].rec_name, + self.assertEqual( + books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 usd|- [-]|-4.000 oz') self.assertEqual(len(books[0].lines[0].splitlines), 2) - self.assertEqual(books[0].lines[0].splitlines[0].rec_name, + self.assertEqual( + books[0].lines[0].splitlines[0].rec_name, 'Exp/Sp|5.00 usd|to category [Cat1]|1.500 oz') - self.assertEqual(books[0].lines[0].splitlines[1].rec_name, - 'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 5.71 € | Open | 70.874 g]|2.500 oz') + self.assertEqual( + books[0].lines[0].splitlines[1].rec_name, + 'Exp/Sp|6.00 usd|to cashbook [Book gram|euro | 5.71 € | ' + + 'Open | 70.874 g]|2.500 oz') - self.assertEqual(books[1].rec_name, 'Book gram|euro | 5.71 € | Open | 70.874 g') + self.assertEqual( + books[1].rec_name, + 'Book gram|euro | 5.71 € | Open | 70.874 g') self.assertEqual(books[1].balance_all, Decimal('5.71')) self.assertEqual(len(books[1].lines), 1) - self.assertEqual(books[1].lines[0].rec_name, - '05/01/2022|from|5.71 €|to cashbook [Book ounce|usd | -11.00 usd | Open | -4.000 oz]|70.874 g') + self.assertEqual( + books[1].lines[0].rec_name, + '05/01/2022|from|5.71 €|to cashbook [Book ounce|usd | ' + + '-11.00 usd | Open | -4.000 oz]|70.874 g') @with_transaction() def test_assetbook_split_out_catergory_asset_diff_unit_diff_cat(self): @@ -2613,7 +2869,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): """ pool = Pool() Book = pool.get('cashbook.book') - Line = pool.get('cashbook.line') BType = pool.get('cashbook.type') Asset = pool.get('investment.asset') ProdTempl = pool.get('product.template') @@ -2628,13 +2883,13 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): category = self.prep_category(cattype='out') company = self.prep_company() - party = self.prep_party() + self.prep_party() asset1 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) asset2 = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product Liter')) + product=self.prep_asset_product(name='Product Liter')) # set product to ounce ounce, = Uom.search([('symbol', '=', 'oz')]) @@ -2671,8 +2926,12 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): }, ])], }, ]) - self.assertEqual(asset1.rec_name, 'Aurum | 1,750.0000 usd/oz | 05/01/2022') - self.assertEqual(asset2.rec_name, 'Liquid | 10.0000 usd/l | 05/01/2022') + self.assertEqual( + asset1.rec_name, + 'Aurum | 1,750.0000 usd/oz | 05/01/2022') + self.assertEqual( + asset2.rec_name, + 'Liquid | 10.0000 usd/l | 05/01/2022') (usd, euro) = self.prep_2nd_currency(company) self.assertEqual(company.currency.rec_name, 'Euro') @@ -2700,14 +2959,19 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase): 'quantity_uom': liter.id, 'quantity_digits': 3, }]) - self.assertEqual(books[0].rec_name, 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') + self.assertEqual( + books[0].rec_name, + 'Book ounce|usd | 0.00 usd | Open | 0.000 oz') self.assertEqual(books[0].balance_all, Decimal('0.0')) self.assertEqual(len(books[0].lines), 0) - self.assertEqual(books[1].rec_name, 'Book liter|euro | 0.00 € | Open | 0.000 l') + self.assertEqual( + books[1].rec_name, + 'Book liter|euro | 0.00 € | Open | 0.000 l') self.assertEqual(books[1].balance_all, Decimal('0.0')) self.assertEqual(len(books[1].lines), 0) - self.assertRaisesRegex(UserError, + self.assertRaisesRegex( + UserError, r"Cannot transfer quantities between cashbooks with different unit-categories \(Weight != Volume\).", Book.write, *[ diff --git a/tests/test_reconciliation.py b/tests/reconciliation.py similarity index 83% rename from tests/test_reconciliation.py rename to tests/reconciliation.py index f4001dd..fbcc94f 100644 --- a/tests/test_reconciliation.py +++ b/tests/reconciliation.py @@ -3,18 +3,15 @@ # The COPYRIGHT file at the top level of this repository contains the # full copyright notices and license terms. -from trytond.tests.test_tryton import ModuleTestCase, with_transaction +from trytond.tests.test_tryton import with_transaction from trytond.pool import Pool -from trytond.transaction import Transaction -from trytond.exceptions import UserError from datetime import date from decimal import Decimal -class ReconTestCase(ModuleTestCase): - 'Test quantity reconciliation module' - module = 'cashbook_investment' - +class ReconTestCase(object): + """ test reconciliation + """ @with_transaction() def test_recon_set_start_quantity_by_cashbook(self): """ set start-quantity of reconciliation from cashbook-setting @@ -33,7 +30,7 @@ class ReconTestCase(ModuleTestCase): }]) asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') book, = Book.create([{ @@ -53,12 +50,16 @@ class ReconTestCase(ModuleTestCase): }]) self.assertEqual(book.name, 'Asset-Book') self.assertEqual(book.reconciliations[0].feature, 'asset') - self.assertEqual(book.reconciliations[0].rec_name, - '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | 0.0000 u - 0.0000 u') + self.assertEqual( + book.reconciliations[0].rec_name, + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' + + '| 0.0000 u - 0.0000 u') Reconciliation.wfcheck(list(book.reconciliations)) - self.assertEqual(book.reconciliations[0].rec_name, - '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | 0.0000 u - 0.0000 u') + self.assertEqual( + book.reconciliations[0].rec_name, + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' + + '| 0.0000 u - 0.0000 u') @with_transaction() def test_recon_set_start_quantity_by_predecessor(self): @@ -79,7 +80,7 @@ class ReconTestCase(ModuleTestCase): }]) asset = self.prep_asset_item( company=company, - product = self.prep_asset_product(name='Product 1')) + product=self.prep_asset_product(name='Product 1')) self.assertEqual(asset.symbol, 'usd/u') category = self.prep_category(cattype='in') @@ -119,8 +120,10 @@ class ReconTestCase(ModuleTestCase): }]) self.assertEqual(book.name, 'Asset-Book') self.assertEqual(len(book.reconciliations), 1) - self.assertEqual(book.reconciliations[0].rec_name, - '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | 0.000 u - 0.000 u') + self.assertEqual( + book.reconciliations[0].rec_name, + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | ' + + '0.000 u - 0.000 u') self.assertEqual(len(book.reconciliations[0].lines), 0) Lines.wfcheck(list(book.lines)) @@ -134,8 +137,10 @@ class ReconTestCase(ModuleTestCase): self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0')) self.assertEqual(book.reconciliations[0].state, 'check') - self.assertEqual(book.reconciliations[0].rec_name, - '05/01/2022 - 05/31/2022 | 0.00 usd - 12.00 usd [2] | 0.000 u - 4.000 u') + self.assertEqual( + book.reconciliations[0].rec_name, + '05/01/2022 - 05/31/2022 | 0.00 usd - 12.00 usd [2] ' + + '| 0.000 u - 4.000 u') Reconciliation.wfdone(list(book.reconciliations)) self.assertEqual(book.reconciliations[0].state, 'done') @@ -144,10 +149,14 @@ class ReconTestCase(ModuleTestCase): 'date_from': date(2022, 5, 31), 'date_to': date(2022, 6, 30), }]) - self.assertEqual(recons[0].rec_name, - '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] | 0.000 u - 0.000 u') + self.assertEqual( + recons[0].rec_name, + '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] | ' + + '0.000 u - 0.000 u') Reconciliation.wfcheck(recons) - self.assertEqual(recons[0].rec_name, - '05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0] | 4.000 u - 4.000 u') + self.assertEqual( + recons[0].rec_name, + '05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0] | ' + + '4.000 u - 4.000 u') # end ReconTestCase diff --git a/tests/test_module.py b/tests/test_module.py new file mode 100644 index 0000000..d8459d7 --- /dev/null +++ b/tests/test_module.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds for Tryton. +# The COPYRIGHT file at the top level of this repository contains the +# full copyright notices and license terms. + + +from trytond.modules.cashbook.tests import CashbookTestCase +from trytond.modules.investment.tests import InvestmentTestCase + +from .yieldtest import YieldTestCase +from .book import CbInvTestCase +from .reconciliation import ReconTestCase + + +class CashbookInvestmentTestCase( + CashbookTestCase, + InvestmentTestCase, + CbInvTestCase, + ReconTestCase, + YieldTestCase): + 'Test cashbook-investment module' + module = 'cashbook_investment' + +# end CashbookInvestmentTestCase + + +del CashbookTestCase +del InvestmentTestCase diff --git a/tests/test_yield.py b/tests/yieldtest.py similarity index 99% rename from tests/test_yield.py rename to tests/yieldtest.py index cde2799..7a6a7b1 100644 --- a/tests/test_yield.py +++ b/tests/yieldtest.py @@ -7,13 +7,12 @@ from decimal import Decimal from datetime import date from trytond.pool import Pool from trytond.transaction import Transaction -from trytond.tests.test_tryton import ModuleTestCase, with_transaction +from trytond.tests.test_tryton import with_transaction -class YieldTestCase(ModuleTestCase): - 'Test yield calculation module' - module = 'cashbook_investment' - +class YieldTestCase(object): + """ test yield + """ def prep_yield_config(self, fee, dividend, gainloss, company): """ add config for yield-calculation fee: name of fee-category,