2022-12-21 23:32:26 +00:00
|
|
|
# -*- 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.tests.test_tryton import ModuleTestCase, 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'
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_create(self):
|
|
|
|
""" create cashbook, set 'btype' to asset
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
BType = pool.get('cashbook.type')
|
|
|
|
|
|
|
|
types = self.prep_type()
|
|
|
|
company = self.prep_company()
|
|
|
|
book, = Book.create([{
|
|
|
|
'name': 'Book 1',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
}])
|
|
|
|
|
|
|
|
BType.write(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.name, 'Book 1')
|
|
|
|
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
|
|
|
|
self.assertEqual(book.btype.rec_name, 'CAS - Cash')
|
|
|
|
self.assertEqual(book.state, 'open')
|
|
|
|
self.assertEqual(book.state_string, 'Open')
|
|
|
|
self.assertEqual(book.feature, 'asset')
|
|
|
|
self.assertEqual(book.quantity_digits, 4)
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_create_line(self):
|
|
|
|
""" create cashbook, add line
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
2022-12-30 22:55:00 +00:00
|
|
|
Line = pool.get('cashbook.line')
|
2022-12-21 23:32:26 +00:00
|
|
|
BType = pool.get('cashbook.type')
|
2022-12-22 23:34:45 +00:00
|
|
|
Asset = pool.get('investment.asset')
|
2022-12-21 23:32:26 +00:00
|
|
|
|
|
|
|
types = self.prep_type()
|
|
|
|
BType.write(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
category = self.prep_category(cattype='in')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
party = self.prep_party()
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
2022-12-22 23:34:45 +00:00
|
|
|
|
|
|
|
Asset.write(*[
|
|
|
|
[asset],
|
|
|
|
{
|
|
|
|
'rates': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'rate': Decimal('2.5'),
|
|
|
|
}, {
|
|
|
|
'date': date(2022, 5, 2),
|
|
|
|
'rate': Decimal('2.8'),
|
|
|
|
}])],
|
|
|
|
}])
|
|
|
|
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')
|
2022-12-21 23:32:26 +00:00
|
|
|
self.assertEqual(asset.symbol, 'usd/u')
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'start_date': date(2022, 4, 1),
|
|
|
|
'name': 'Book 1',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
2022-12-22 23:34:45 +00:00
|
|
|
'currency': euro.id,
|
2022-12-21 23:32:26 +00:00
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': asset.uom.id,
|
|
|
|
'quantity_digits': 3,
|
|
|
|
'lines': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'description': 'Text 1',
|
|
|
|
'category': category.id,
|
|
|
|
'bookingtype': 'in',
|
|
|
|
'amount': Decimal('2.5'),
|
|
|
|
'party': party.id,
|
|
|
|
'quantity': Decimal('1.453'),
|
2022-12-22 23:34:45 +00:00
|
|
|
}, {
|
|
|
|
'date': date(2022, 5, 10),
|
|
|
|
'description': 'Text 2',
|
|
|
|
'category': category.id,
|
|
|
|
'bookingtype': 'in',
|
|
|
|
'amount': Decimal('4.0'),
|
|
|
|
'party': party.id,
|
|
|
|
'quantity': Decimal('3.3'),
|
2022-12-21 23:32:26 +00:00
|
|
|
}],
|
|
|
|
)],
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.name, 'Book 1')
|
2022-12-22 23:34:45 +00:00
|
|
|
self.assertEqual(book.rec_name, 'Book 1 | 6.50 € | Open')
|
2022-12-21 23:32:26 +00:00
|
|
|
self.assertEqual(book.state, 'open')
|
|
|
|
self.assertEqual(book.feature, 'asset')
|
|
|
|
self.assertEqual(book.quantity_digits, 3)
|
2022-12-22 23:34:45 +00:00
|
|
|
self.assertEqual(book.balance_all, Decimal('6.5'))
|
|
|
|
self.assertEqual(len(book.lines), 2)
|
|
|
|
|
2022-12-21 23:32:26 +00:00
|
|
|
self.assertEqual(book.lines[0].amount, Decimal('2.5'))
|
|
|
|
self.assertEqual(book.lines[0].quantity, Decimal('1.453'))
|
2022-12-30 22:55:00 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_credit, Decimal('1.453'))
|
|
|
|
self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0'))
|
2022-12-21 23:32:26 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_digits, 3)
|
2022-12-22 15:01:10 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_uom.symbol, 'u')
|
2022-12-22 23:34:45 +00:00
|
|
|
|
|
|
|
self.assertEqual(book.lines[1].amount, Decimal('4.0'))
|
|
|
|
self.assertEqual(book.lines[1].quantity, Decimal('3.3'))
|
2022-12-30 22:55:00 +00:00
|
|
|
self.assertEqual(book.lines[1].quantity_credit, Decimal('3.3'))
|
|
|
|
self.assertEqual(book.lines[1].quantity_debit, Decimal('0.0'))
|
2022-12-22 23:34:45 +00:00
|
|
|
self.assertEqual(book.lines[1].quantity_digits, 3)
|
|
|
|
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')
|
|
|
|
|
2022-12-30 22:55:00 +00:00
|
|
|
# wf --> check
|
|
|
|
Line.wfcheck(book.lines)
|
|
|
|
|
2022-12-22 23:34:45 +00:00
|
|
|
# check quantities at cashbook
|
|
|
|
with Transaction().set_context({
|
|
|
|
'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'))
|
|
|
|
self.assertEqual(book2.quantity_all, Decimal('4.753'))
|
|
|
|
# 2.8 / 1.05 * 1.453 = 3.87466
|
|
|
|
self.assertEqual(book2.current_value, Decimal('3.87'))
|
|
|
|
self.assertEqual(book2.current_value_ref, Decimal('3.87'))
|
|
|
|
|
|
|
|
with Transaction().set_context({
|
|
|
|
'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'))
|
|
|
|
# 2.8 / 1.05 * 4.753 = 12.67466
|
|
|
|
self.assertEqual(book2.current_value, Decimal('12.67'))
|
|
|
|
self.assertEqual(book2.current_value_ref, Decimal('12.67'))
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_check_uom_and_currency_convert(self):
|
|
|
|
""" asset in US$/Ounce, cashbook in EUR/Gram
|
|
|
|
"""
|
|
|
|
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(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
category = self.prep_category(cattype='in')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
party = self.prep_party()
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
|
|
|
|
# set product to ounce
|
|
|
|
ounce, = Uom.search([('symbol', '=', 'oz')])
|
|
|
|
gram, = Uom.search([('symbol', '=', 'g')])
|
|
|
|
|
|
|
|
ProdTempl.write(*[
|
|
|
|
[asset.product.template],
|
|
|
|
{
|
|
|
|
'default_uom': ounce.id,
|
|
|
|
'name': 'Aurum',
|
|
|
|
}])
|
|
|
|
|
|
|
|
Asset.write(*[
|
|
|
|
[asset],
|
|
|
|
{
|
|
|
|
'uom': ounce.id,
|
|
|
|
'rates': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'rate': Decimal('1750.0'),
|
|
|
|
}, ])],
|
|
|
|
}])
|
|
|
|
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')
|
|
|
|
self.assertEqual(asset.symbol, 'usd/oz')
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'start_date': date(2022, 4, 1),
|
|
|
|
'name': 'Aurum-Storage',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': euro.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': gram.id,
|
|
|
|
'quantity_digits': 3,
|
|
|
|
'lines': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'description': 'store some metal',
|
|
|
|
'category': category.id,
|
|
|
|
'bookingtype': 'in',
|
|
|
|
'amount': Decimal('1250.0'),
|
|
|
|
'party': party.id,
|
|
|
|
'quantity': Decimal('20.0'),
|
|
|
|
}],
|
|
|
|
)],
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.rec_name, 'Aurum-Storage | 1,250.00 € | Open')
|
|
|
|
self.assertEqual(book.balance_all, Decimal('1250.0'))
|
|
|
|
self.assertEqual(len(book.lines), 1)
|
|
|
|
|
|
|
|
self.assertEqual(book.lines[0].amount, Decimal('1250.0'))
|
|
|
|
self.assertEqual(book.lines[0].quantity, Decimal('20.0'))
|
|
|
|
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')
|
|
|
|
|
|
|
|
# check quantities at cashbook
|
|
|
|
with Transaction().set_context({
|
|
|
|
'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'))
|
|
|
|
self.assertEqual(book2.quantity_all, Decimal('20.0'))
|
2022-12-23 18:15:20 +00:00
|
|
|
# usd --> eur: 1750 US$ / 1.05 = 1666.666 €
|
|
|
|
# 1 ounce --> 20 gram: 1666.666 € * 20 / 28.3495 = 1175.7996 €
|
2022-12-22 23:34:45 +00:00
|
|
|
# bette we use 'Troy Ounce': 1 oz.tr. = 31.1034768 gram
|
|
|
|
self.assertEqual(book2.current_value, Decimal('1175.80'))
|
|
|
|
self.assertEqual(book2.current_value_ref, Decimal('1175.80'))
|
2022-12-23 18:15:20 +00:00
|
|
|
self.assertEqual(book2.diff_amount, Decimal('-74.20'))
|
|
|
|
self.assertEqual(book2.diff_percent, Decimal('-5.94'))
|
2022-12-24 12:14:51 +00:00
|
|
|
self.assertEqual(book2.current_rate, Decimal('58.79'))
|
2022-12-23 18:15:20 +00:00
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_check_uom_and_currency_convert2(self):
|
|
|
|
""" asset in US$/Ounce, cashbook in CHF/Gram,
|
|
|
|
company-currency EUR
|
|
|
|
"""
|
|
|
|
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')
|
|
|
|
Currency = pool.get('currency.currency')
|
|
|
|
|
|
|
|
types = self.prep_type()
|
|
|
|
BType.write(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
category = self.prep_category(cattype='in')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
party = self.prep_party()
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
|
|
|
|
# set product to ounce
|
|
|
|
ounce, = Uom.search([('symbol', '=', 'oz')])
|
|
|
|
gram, = Uom.search([('symbol', '=', 'g')])
|
|
|
|
|
|
|
|
ProdTempl.write(*[
|
|
|
|
[asset.product.template],
|
|
|
|
{
|
|
|
|
'default_uom': ounce.id,
|
|
|
|
'name': 'Aurum',
|
|
|
|
}])
|
|
|
|
|
|
|
|
Asset.write(*[
|
|
|
|
[asset],
|
|
|
|
{
|
|
|
|
'uom': ounce.id,
|
|
|
|
'rates': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'rate': Decimal('1750.0'),
|
|
|
|
}, ])],
|
|
|
|
}])
|
|
|
|
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')
|
|
|
|
self.assertEqual(asset.symbol, 'usd/oz')
|
|
|
|
chf, = Currency.create([{
|
|
|
|
'name': 'Swiss Franc',
|
|
|
|
'code': 'CHF',
|
|
|
|
'numeric_code': '756',
|
|
|
|
'symbol': 'CHF',
|
|
|
|
'rounding': Decimal('0.01'),
|
|
|
|
'digits': 2,
|
|
|
|
'rates': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'rate': Decimal('0.95'),
|
|
|
|
}])],
|
|
|
|
}])
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'start_date': date(2022, 4, 1),
|
|
|
|
'name': 'Aurum-Storage',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': chf.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': gram.id,
|
|
|
|
'quantity_digits': 3,
|
|
|
|
'lines': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'description': 'store some metal',
|
|
|
|
'category': category.id,
|
|
|
|
'bookingtype': 'in',
|
|
|
|
'amount': Decimal('1250.0'),
|
|
|
|
'party': party.id,
|
|
|
|
'quantity': Decimal('20.0'),
|
|
|
|
}],
|
|
|
|
)],
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.rec_name, 'Aurum-Storage | 1,250.00 CHF | Open')
|
|
|
|
self.assertEqual(book.balance_all, Decimal('1250.0'))
|
|
|
|
self.assertEqual(len(book.lines), 1)
|
|
|
|
|
|
|
|
self.assertEqual(book.lines[0].amount, Decimal('1250.0'))
|
|
|
|
self.assertEqual(book.lines[0].quantity, Decimal('20.0'))
|
|
|
|
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')
|
|
|
|
|
|
|
|
# check quantities at cashbook
|
|
|
|
with Transaction().set_context({
|
|
|
|
'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'))
|
|
|
|
self.assertEqual(book2.quantity_all, Decimal('20.0'))
|
|
|
|
# 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.diff_amount, Decimal('-132.99'))
|
|
|
|
self.assertEqual(book2.diff_percent, Decimal('-10.64'))
|
2022-12-24 12:14:51 +00:00
|
|
|
self.assertEqual(book2.current_rate, Decimal('55.85'))
|
2022-12-21 23:32:26 +00:00
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_book_uom(self):
|
|
|
|
""" check default auf uom
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
BType = pool.get('cashbook.type')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
types = self.prep_type()
|
|
|
|
BType.write(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
'name': 'Asset',
|
|
|
|
'short': 'A',
|
|
|
|
}])
|
|
|
|
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
self.assertEqual(asset.symbol, 'usd/u')
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_book_with_asset(self):
|
|
|
|
""" create cashbook, set 'btype' to asset
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
BType = pool.get('cashbook.type')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
types = self.prep_type()
|
|
|
|
BType.write(*[
|
|
|
|
[types],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
'name': 'Asset',
|
|
|
|
'short': 'A',
|
|
|
|
}])
|
|
|
|
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
self.assertEqual(asset.symbol, 'usd/u')
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'name': 'Book 1',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': asset.uom.id,
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.name, 'Book 1')
|
|
|
|
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
|
|
|
|
self.assertEqual(book.btype.rec_name, 'A - Asset')
|
|
|
|
self.assertEqual(book.state, 'open')
|
|
|
|
self.assertEqual(book.feature, 'asset')
|
|
|
|
self.assertEqual(book.asset.rec_name, 'Product 1 | - usd/u | -')
|
|
|
|
self.assertEqual(book.quantity_uom.rec_name, 'Unit')
|
|
|
|
|
|
|
|
self.assertRaisesRegex(UserError,
|
|
|
|
'A value is required for field "Asset" in "Cashbook".',
|
|
|
|
Book.write,
|
|
|
|
*[
|
|
|
|
[book],
|
|
|
|
{
|
|
|
|
'asset': None,
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2023-01-02 20:59:16 +00:00
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_check_sign_mismatch(self):
|
|
|
|
""" create cashbook + line, bookingtype 'in',
|
|
|
|
check detection of sign mismatch between quantity and amount
|
|
|
|
"""
|
|
|
|
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')
|
|
|
|
BType.write(*[
|
|
|
|
[type_depot],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
|
|
|
|
category_in = self.prep_category(cattype='in')
|
|
|
|
company = self.prep_company()
|
|
|
|
party = self.prep_party()
|
|
|
|
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
self.assertEqual(asset.symbol, 'usd/u')
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'name': 'Asset-Book',
|
|
|
|
'btype': type_depot.id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': asset.uom.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'start_date': date(2022, 5, 1),
|
|
|
|
'lines': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'description': 'buy some',
|
|
|
|
'category': category_in.id,
|
|
|
|
'bookingtype': 'in',
|
|
|
|
'amount': Decimal('1.0'),
|
|
|
|
'quantity': Decimal('1.5'),
|
|
|
|
}])],
|
|
|
|
}])
|
|
|
|
|
|
|
|
self.assertEqual(book.rec_name, 'Asset-Book | 1.00 usd | Open')
|
|
|
|
self.assertEqual(len(book.lines), 1)
|
|
|
|
self.assertEqual(book.lines[0].amount, Decimal('1.0'))
|
|
|
|
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, 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].",
|
|
|
|
Book.write,
|
|
|
|
*[
|
|
|
|
[book],
|
|
|
|
{
|
|
|
|
'lines': [('write', [book.lines[0]], {
|
|
|
|
'quantity': Decimal('-1.5'),
|
|
|
|
})],
|
|
|
|
}])
|
|
|
|
|
2022-12-25 12:37:17 +00:00
|
|
|
@with_transaction()
|
|
|
|
def test_assetbook_check_bookingtype_mvout(self):
|
|
|
|
""" create cashbook + line, bookingtype 'mvout'
|
2022-12-30 22:55:00 +00:00
|
|
|
transfer from cash to depot (buy asset, pay from cash)
|
2022-12-25 12:37:17 +00:00
|
|
|
"""
|
|
|
|
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()
|
|
|
|
type_depot = self.prep_type('Depot', 'D')
|
|
|
|
BType.write(*[
|
|
|
|
[type_depot],
|
|
|
|
{
|
|
|
|
'feature': 'asset',
|
|
|
|
}])
|
|
|
|
|
|
|
|
category_in = self.prep_category(cattype='in')
|
|
|
|
category_out = self.prep_category(name='Out Category', cattype='out')
|
|
|
|
company = self.prep_company()
|
|
|
|
party = self.prep_party()
|
|
|
|
|
|
|
|
asset = self.prep_asset_item(
|
|
|
|
company=company,
|
|
|
|
product = self.prep_asset_product(name='Product 1'))
|
|
|
|
self.assertEqual(asset.symbol, 'usd/u')
|
|
|
|
|
|
|
|
book2, = Book.create([{
|
|
|
|
'name': 'Asset-Book',
|
|
|
|
'btype': type_depot.id,
|
|
|
|
'asset': asset.id,
|
|
|
|
'quantity_uom': asset.uom.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'start_date': date(2022, 5, 1),
|
|
|
|
}])
|
|
|
|
|
|
|
|
book, = Book.create([{
|
|
|
|
'name': 'Book 1',
|
|
|
|
'btype': type_cash.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'start_date': date(2022, 5, 1),
|
|
|
|
'lines': [('create', [{
|
|
|
|
'date': date(2022, 5, 1),
|
|
|
|
'description': 'Transfer Out',
|
|
|
|
'category': category_out.id,
|
|
|
|
'bookingtype': 'mvout',
|
|
|
|
'amount': Decimal('1.0'),
|
|
|
|
'booktransf': book2.id,
|
|
|
|
'quantity': Decimal('1.5'),
|
|
|
|
}])],
|
|
|
|
}])
|
|
|
|
self.assertEqual(book.rec_name, 'Book 1 | -1.00 usd | Open')
|
|
|
|
self.assertEqual(len(book.lines), 1)
|
|
|
|
self.assertEqual(book.lines[0].quantity, Decimal('1.5'))
|
2022-12-31 15:15:23 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_credit, Decimal('0.0'))
|
|
|
|
self.assertEqual(book.lines[0].quantity_debit, Decimal('1.5'))
|
2022-12-25 12:37:17 +00:00
|
|
|
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]')
|
|
|
|
self.assertEqual(len(book.lines[0].references), 0)
|
|
|
|
|
2022-12-31 15:15:23 +00:00
|
|
|
# update quantity
|
|
|
|
Book.write(*[
|
|
|
|
[book],
|
|
|
|
{
|
|
|
|
'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, Decimal('0.0'))
|
|
|
|
self.assertEqual(book.lines[0].quantity_debit, Decimal('2.5'))
|
|
|
|
|
2022-12-25 12:37:17 +00:00
|
|
|
# check counterpart
|
|
|
|
self.assertEqual(book.lines[0].booktransf.rec_name, 'Asset-Book | 0.00 usd | Open')
|
|
|
|
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(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]')
|
|
|
|
self.assertEqual(book.lines[0].state, 'check')
|
2022-12-30 22:55:00 +00:00
|
|
|
self.assertEqual(book.lines[0].bookingtype, 'mvout')
|
2022-12-31 15:15:23 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity, Decimal('2.5'))
|
2022-12-30 22:55:00 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_credit, Decimal('0.0'))
|
2022-12-31 15:15:23 +00:00
|
|
|
self.assertEqual(book.lines[0].quantity_debit, Decimal('2.5'))
|
2022-12-25 12:37:17 +00:00
|
|
|
self.assertEqual(len(book.lines[0].references), 1)
|
|
|
|
self.assertEqual(book.lines[0].reference, None)
|
|
|
|
self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id)
|
|
|
|
|
|
|
|
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]')
|
|
|
|
self.assertEqual(book2.lines[0].state, 'check')
|
2022-12-31 15:15:23 +00:00
|
|
|
self.assertEqual(book2.lines[0].quantity, Decimal('2.5'))
|
|
|
|
self.assertEqual(book2.lines[0].quantity_credit, Decimal('2.5'))
|
2022-12-30 22:55:00 +00:00
|
|
|
self.assertEqual(book2.lines[0].quantity_debit, Decimal('0.0'))
|
|
|
|
self.assertEqual(book2.lines[0].bookingtype, 'mvin')
|
2022-12-31 15:15:23 +00:00
|
|
|
self.assertEqual(book2.lines[0].asset_rate, Decimal('0.4'))
|
2022-12-25 12:37:17 +00:00
|
|
|
self.assertEqual(book2.lines[0].reference.rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 1.00 usd | Open]')
|
|
|
|
self.assertEqual(len(book2.lines[0].references), 0)
|
|
|
|
|
2022-12-21 23:32:26 +00:00
|
|
|
# end CbInvTestCase
|