tests: add company to context

This commit is contained in:
Frederik Jaeckel 2023-06-08 16:00:36 +02:00
parent 1047345ae8
commit 1f47dfe6b1
3 changed files with 2618 additions and 2593 deletions

View file

@ -21,6 +21,8 @@ DEPENDSQ.extend(DEPENDS)
class SecondUomMixin(object): class SecondUomMixin(object):
""" two fields for second uom: quantity, rate """ two fields for second uom: quantity, rate
""" """
__slots__ = ()
quantity_2nd_uom = fields.Numeric( quantity_2nd_uom = fields.Numeric(
string='Quantity Second UOM', string='Quantity Second UOM',
digits=(16, Eval('quantity2nd_digits', 4)), digits=(16, Eval('quantity2nd_digits', 4)),

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@
from trytond.tests.test_tryton import with_transaction from trytond.tests.test_tryton import with_transaction
from trytond.pool import Pool from trytond.pool import Pool
from trytond.transaction import Transaction
from datetime import date from datetime import date
from decimal import Decimal from decimal import Decimal
@ -22,44 +23,45 @@ class ReconTestCase(object):
BType = pool.get('cashbook.type') BType = pool.get('cashbook.type')
company = self.prep_company() company = self.prep_company()
type_depot = self.prep_type('Depot', 'D') with Transaction().set_context({'company': company.id}):
BType.write(*[ type_depot = self.prep_type('Depot', 'D')
[type_depot], BType.write(*[
{ [type_depot],
'feature': 'asset', {
}]) 'feature': 'asset',
asset = self.prep_asset_item( }])
company=company, asset = self.prep_asset_item(
product=self.prep_asset_product(name='Product 1')) company=company,
self.assertEqual(asset.symbol, 'usd/u') product=self.prep_asset_product(name='Product 1'))
self.assertEqual(asset.symbol, 'usd/u')
book, = Book.create([{ book, = Book.create([{
'name': 'Asset-Book', 'name': 'Asset-Book',
'btype': type_depot.id, 'btype': type_depot.id,
'company': company.id, 'company': company.id,
'currency': company.currency.id, 'currency': company.currency.id,
'asset': asset.id, 'asset': asset.id,
'quantity_uom': asset.uom.id, 'quantity_uom': asset.uom.id,
'start_date': date(2022, 5, 1), 'start_date': date(2022, 5, 1),
'number_sequ': self.prep_sequence().id, 'number_sequ': self.prep_sequence().id,
'reconciliations': [('create', [{ 'reconciliations': [('create', [{
'date': date(2022, 5, 28), 'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1), 'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31), 'date_to': date(2022, 5, 31),
}])], }])],
}]) }])
self.assertEqual(book.name, 'Asset-Book') self.assertEqual(book.name, 'Asset-Book')
self.assertEqual(book.reconciliations[0].feature, 'asset') self.assertEqual(book.reconciliations[0].feature, 'asset')
self.assertEqual( self.assertEqual(
book.reconciliations[0].rec_name, book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' +
'| 0.0000 u - 0.0000 u') '| 0.0000 u - 0.0000 u')
Reconciliation.wfcheck(list(book.reconciliations)) Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual( self.assertEqual(
book.reconciliations[0].rec_name, book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' +
'| 0.0000 u - 0.0000 u') '| 0.0000 u - 0.0000 u')
@with_transaction() @with_transaction()
def test_recon_set_start_quantity_by_predecessor(self): def test_recon_set_start_quantity_by_predecessor(self):
@ -72,91 +74,92 @@ class ReconTestCase(object):
BType = pool.get('cashbook.type') BType = pool.get('cashbook.type')
company = self.prep_company() company = self.prep_company()
type_depot = self.prep_type('Depot', 'D') with Transaction().set_context({'company': company.id}):
BType.write(*[ type_depot = self.prep_type('Depot', 'D')
[type_depot], BType.write(*[
{ [type_depot],
'feature': 'asset', {
}]) 'feature': 'asset',
asset = self.prep_asset_item( }])
company=company, asset = self.prep_asset_item(
product=self.prep_asset_product(name='Product 1')) company=company,
self.assertEqual(asset.symbol, 'usd/u') product=self.prep_asset_product(name='Product 1'))
self.assertEqual(asset.symbol, 'usd/u')
category = self.prep_category(cattype='in') category = self.prep_category(cattype='in')
party = self.prep_party() party = self.prep_party()
book, = Book.create([{ book, = Book.create([{
'name': 'Asset-Book', 'name': 'Asset-Book',
'btype': type_depot.id, 'btype': type_depot.id,
'company': company.id, 'company': company.id,
'currency': company.currency.id, 'currency': company.currency.id,
'asset': asset.id, 'asset': asset.id,
'quantity_uom': asset.uom.id, 'quantity_uom': asset.uom.id,
'quantity_digits': 3, 'quantity_digits': 3,
'start_date': date(2022, 5, 1), 'start_date': date(2022, 5, 1),
'number_sequ': self.prep_sequence().id, 'number_sequ': self.prep_sequence().id,
'reconciliations': [('create', [{ 'reconciliations': [('create', [{
'date': date(2022, 5, 28), 'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1), 'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31), 'date_to': date(2022, 5, 31),
}])], }])],
'lines': [('create', [{ 'lines': [('create', [{
'date': date(2022, 5, 5), 'date': date(2022, 5, 5),
'bookingtype': 'in', 'bookingtype': 'in',
'category': category.id, 'category': category.id,
'description': 'Line 1', 'description': 'Line 1',
'amount': Decimal('5.0'), 'amount': Decimal('5.0'),
'quantity': Decimal('1.5'), 'quantity': Decimal('1.5'),
'party': party.id, 'party': party.id,
}, { }, {
'date': date(2022, 5, 6), 'date': date(2022, 5, 6),
'bookingtype': 'in', 'bookingtype': 'in',
'category': category.id, 'category': category.id,
'description': 'Line 2', 'description': 'Line 2',
'party': party.id, 'party': party.id,
'amount': Decimal('7.0'), 'amount': Decimal('7.0'),
'quantity': Decimal('2.5'), 'quantity': Decimal('2.5'),
},])], },])],
}]) }])
self.assertEqual(book.name, 'Asset-Book') self.assertEqual(book.name, 'Asset-Book')
self.assertEqual(len(book.reconciliations), 1) self.assertEqual(len(book.reconciliations), 1)
self.assertEqual( self.assertEqual(
book.reconciliations[0].rec_name, book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | ' + '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] | ' +
'0.000 u - 0.000 u') '0.000 u - 0.000 u')
self.assertEqual(len(book.reconciliations[0].lines), 0) self.assertEqual(len(book.reconciliations[0].lines), 0)
Lines.wfcheck(list(book.lines)) Lines.wfcheck(list(book.lines))
self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5')) self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5'))
self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0')) self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0'))
Reconciliation.wfcheck(list(book.reconciliations)) Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5')) self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5'))
self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0')) self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0'))
self.assertEqual(book.reconciliations[0].state, 'check') self.assertEqual(book.reconciliations[0].state, 'check')
self.assertEqual( self.assertEqual(
book.reconciliations[0].rec_name, book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 12.00 usd [2] ' + '05/01/2022 - 05/31/2022 | 0.00 usd - 12.00 usd [2] ' +
'| 0.000 u - 4.000 u') '| 0.000 u - 4.000 u')
Reconciliation.wfdone(list(book.reconciliations)) Reconciliation.wfdone(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'done') self.assertEqual(book.reconciliations[0].state, 'done')
recons = Reconciliation.create([{ recons = Reconciliation.create([{
'cashbook': book.id, 'cashbook': book.id,
'date_from': date(2022, 5, 31), 'date_from': date(2022, 5, 31),
'date_to': date(2022, 6, 30), 'date_to': date(2022, 6, 30),
}]) }])
self.assertEqual( self.assertEqual(
recons[0].rec_name, recons[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] | ' + '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] | ' +
'0.000 u - 0.000 u') '0.000 u - 0.000 u')
Reconciliation.wfcheck(recons) Reconciliation.wfcheck(recons)
self.assertEqual( self.assertEqual(
recons[0].rec_name, recons[0].rec_name,
'05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0] | ' + '05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0] | ' +
'4.000 u - 4.000 u') '4.000 u - 4.000 u')
# end ReconTestCase # end ReconTestCase