line: funktion für 'balance' + test
reconciliation: rec_name + test
This commit is contained in:
parent
f86db6dea3
commit
fd36a3f4ce
6 changed files with 206 additions and 3 deletions
15
line.py
15
line.py
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import PoolMeta
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.pyson import Eval, Or, If
|
from trytond.pyson import Eval, Or, If
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
|
@ -106,6 +106,19 @@ class Line(metaclass=PoolMeta):
|
||||||
result['quantity'] = line.quantity
|
result['quantity'] = line.quantity
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@fields.depends('id', 'date', 'cashbook', \
|
||||||
|
'_parent_cashbook.id', 'reconciliation', \
|
||||||
|
'_parent_reconciliation.start_quantity',\
|
||||||
|
'_parent_reconciliation.state')
|
||||||
|
def on_change_with_quantity_balance(self, name=None):
|
||||||
|
""" get quantity-balance
|
||||||
|
"""
|
||||||
|
Line2 = Pool().get('cashbook.line')
|
||||||
|
return Line2.get_balance_of_line(self,
|
||||||
|
field_name='quantity',
|
||||||
|
credit_name='quantity_credit',
|
||||||
|
debit_name='quantity_debit')
|
||||||
|
|
||||||
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
|
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
|
||||||
def on_change_with_asset_rate(self, name=None):
|
def on_change_with_asset_rate(self, name=None):
|
||||||
""" get rate
|
""" get rate
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
# full copyright notices and license terms.
|
# full copyright notices and license terms.
|
||||||
|
|
||||||
|
|
||||||
from trytond.pool import PoolMeta
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
|
from trytond.report import Report
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +32,20 @@ class Reconciliation(metaclass=PoolMeta):
|
||||||
readonly=True, model_name='product.uom'),
|
readonly=True, model_name='product.uom'),
|
||||||
'on_change_with_quantity_uom')
|
'on_change_with_quantity_uom')
|
||||||
|
|
||||||
|
def get_rec_name(self, name):
|
||||||
|
""" add quantities - if its a asset-cashbook
|
||||||
|
"""
|
||||||
|
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,
|
||||||
|
digits=self.quantity_digits),
|
||||||
|
'end_quantity': Report.format_number(self.end_quantity or 0.0, None,
|
||||||
|
digits=self.quantity_digits),
|
||||||
|
'uom_symbol': self.quantity_uom.symbol,
|
||||||
|
}
|
||||||
|
return recname
|
||||||
|
|
||||||
@fields.depends('cashbook', '_parent_cashbook.quantity_uom')
|
@fields.depends('cashbook', '_parent_cashbook.quantity_uom')
|
||||||
def on_change_with_quantity_uom(self, name=None):
|
def on_change_with_quantity_uom(self, name=None):
|
||||||
""" get quantity-unit of asset
|
""" get quantity-unit of asset
|
||||||
|
@ -71,7 +86,11 @@ class Reconciliation(metaclass=PoolMeta):
|
||||||
def get_values_wfcheck(cls, reconciliation):
|
def get_values_wfcheck(cls, reconciliation):
|
||||||
""" get values for 'to_write' in wf-check
|
""" get values for 'to_write' in wf-check
|
||||||
"""
|
"""
|
||||||
|
Line = Pool().get('cashbook.line')
|
||||||
|
|
||||||
values = super(Reconciliation, cls).get_values_wfcheck(reconciliation)
|
values = super(Reconciliation, cls).get_values_wfcheck(reconciliation)
|
||||||
|
if reconciliation.cashbook.feature != 'asset':
|
||||||
|
return values
|
||||||
|
|
||||||
if reconciliation.predecessor:
|
if reconciliation.predecessor:
|
||||||
values['start_quantity'] = reconciliation.predecessor.end_quantity
|
values['start_quantity'] = reconciliation.predecessor.end_quantity
|
||||||
|
@ -84,9 +103,10 @@ class Reconciliation(metaclass=PoolMeta):
|
||||||
if len(values['lines']) != 1:
|
if len(values['lines']) != 1:
|
||||||
raise ValueError('invalid number of values')
|
raise ValueError('invalid number of values')
|
||||||
|
|
||||||
|
lines_records = Line.browse(values['lines'][0][1])
|
||||||
values['end_quantity'] += sum([
|
values['end_quantity'] += sum([
|
||||||
x.quantity_credit - x.quantity_debit
|
x.quantity_credit - x.quantity_debit
|
||||||
for x in values['lines'][0][1]
|
for x in lines_records
|
||||||
])
|
])
|
||||||
|
|
||||||
# add quantities of already linked lines
|
# add quantities of already linked lines
|
||||||
|
|
|
@ -5,6 +5,11 @@ full copyright notices and license terms. -->
|
||||||
<tryton>
|
<tryton>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="recon_view_list">
|
||||||
|
<field name="model">cashbook.recon</field>
|
||||||
|
<field name="inherit" ref="cashbook.recon_view_list"/>
|
||||||
|
<field name="name">recon_list</field>
|
||||||
|
</record>
|
||||||
<record model="ir.ui.view" id="recon_view_form">
|
<record model="ir.ui.view" id="recon_view_form">
|
||||||
<field name="model">cashbook.recon</field>
|
<field name="model">cashbook.recon</field>
|
||||||
<field name="inherit" ref="cashbook.recon_view_form"/>
|
<field name="inherit" ref="cashbook.recon_view_form"/>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import trytond.tests.test_tryton
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from trytond.modules.cashbook_investment.tests.test_book import CbInvTestCase
|
from trytond.modules.cashbook_investment.tests.test_book import CbInvTestCase
|
||||||
|
from trytond.modules.cashbook_investment.tests.test_reconciliation import ReconTestCase
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['suite']
|
__all__ = ['suite']
|
||||||
|
@ -12,6 +13,7 @@ __all__ = ['suite']
|
||||||
|
|
||||||
class CashbookInvestmentTestCase(\
|
class CashbookInvestmentTestCase(\
|
||||||
CbInvTestCase,\
|
CbInvTestCase,\
|
||||||
|
ReconTestCase,\
|
||||||
):
|
):
|
||||||
'Test cashbook-investment module'
|
'Test cashbook-investment module'
|
||||||
module = 'cashbook_investment'
|
module = 'cashbook_investment'
|
||||||
|
|
152
tests/test_reconciliation.py
Normal file
152
tests/test_reconciliation.py
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
# -*- 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 datetime import date
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
|
class ReconTestCase(ModuleTestCase):
|
||||||
|
'Test quantity reconciliation module'
|
||||||
|
module = 'cashbook_investment'
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_recon_set_start_quantity_by_cashbook(self):
|
||||||
|
""" set stat-quantity from cashbook-setting
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Book = pool.get('cashbook.book')
|
||||||
|
Reconciliation = pool.get('cashbook.recon')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
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,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'reconciliations': [('create', [{
|
||||||
|
'date': date(2022, 5, 28),
|
||||||
|
'date_from': date(2022, 5, 1),
|
||||||
|
'date_to': date(2022, 5, 31),
|
||||||
|
}])],
|
||||||
|
}])
|
||||||
|
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.00 u - 0.00 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.00 u - 0.00 u')
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_recon_set_start_quantity_by_predecessor(self):
|
||||||
|
""" set stat-quantity from end_amount of predecessor
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Book = pool.get('cashbook.book')
|
||||||
|
Lines = pool.get('cashbook.line')
|
||||||
|
Reconciliation = pool.get('cashbook.recon')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
asset = self.prep_asset_item(
|
||||||
|
company=company,
|
||||||
|
product = self.prep_asset_product(name='Product 1'))
|
||||||
|
self.assertEqual(asset.symbol, 'usd/u')
|
||||||
|
|
||||||
|
category = self.prep_category(cattype='in')
|
||||||
|
party = self.prep_party()
|
||||||
|
book, = Book.create([{
|
||||||
|
'name': 'Asset-Book',
|
||||||
|
'btype': type_depot.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'reconciliations': [('create', [{
|
||||||
|
'date': date(2022, 5, 28),
|
||||||
|
'date_from': date(2022, 5, 1),
|
||||||
|
'date_to': date(2022, 5, 31),
|
||||||
|
}])],
|
||||||
|
'lines': [('create', [{
|
||||||
|
'date': date(2022, 5, 5),
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'category': category.id,
|
||||||
|
'description': 'Line 1',
|
||||||
|
'amount': Decimal('5.0'),
|
||||||
|
'quantity': Decimal('1.5'),
|
||||||
|
'party': party.id,
|
||||||
|
}, {
|
||||||
|
'date': date(2022, 5, 6),
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'category': category.id,
|
||||||
|
'description': 'Line 2',
|
||||||
|
'party': party.id,
|
||||||
|
'amount': Decimal('7.0'),
|
||||||
|
'quantity': Decimal('2.5'),
|
||||||
|
},])],
|
||||||
|
}])
|
||||||
|
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.00 u - 0.00 u')
|
||||||
|
self.assertEqual(len(book.reconciliations[0].lines), 0)
|
||||||
|
|
||||||
|
Lines.wfcheck(list(book.lines))
|
||||||
|
|
||||||
|
self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5'))
|
||||||
|
self.assertEqual(book.lines[1].quantity_balance, Decimal('4.0'))
|
||||||
|
|
||||||
|
Reconciliation.wfcheck(list(book.reconciliations))
|
||||||
|
|
||||||
|
self.assertEqual(book.lines[0].quantity_balance, Decimal('1.5'))
|
||||||
|
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.00 u - 4.00 u')
|
||||||
|
Reconciliation.wfdone(list(book.reconciliations))
|
||||||
|
self.assertEqual(book.reconciliations[0].state, 'done')
|
||||||
|
|
||||||
|
recons = Reconciliation.create([{
|
||||||
|
'cashbook': book.id,
|
||||||
|
'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.00 u - 0.00 u')
|
||||||
|
Reconciliation.wfcheck(recons)
|
||||||
|
self.assertEqual(recons[0].rec_name,
|
||||||
|
'05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0] | 4.00 u - 4.00 u')
|
||||||
|
|
||||||
|
# end ReconTestCase
|
11
view/recon_list.xml
Normal file
11
view/recon_list.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- 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. -->
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<xpath expr="/tree/field[@name='end_amount']" position="after">
|
||||||
|
<field name="start_quantity"/>
|
||||||
|
<field name="end_quantity"/>
|
||||||
|
</xpath>
|
||||||
|
</data>
|
Loading…
Reference in a new issue