line: balance-berechnung ausgelagert,
reconciliation: Feld 'feature'
This commit is contained in:
parent
e0a6d39bdb
commit
b809d51fe0
6 changed files with 57 additions and 26 deletions
61
line.py
61
line.py
|
@ -672,27 +672,24 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
||||||
else:
|
else:
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
@fields.depends('id', 'date', 'cashbook', \
|
@classmethod
|
||||||
'_parent_cashbook.id', 'reconciliation', \
|
def get_balance_of_line(cls, line, field_name='amount', credit_name='credit', debit_name='debit'):
|
||||||
'_parent_reconciliation.start_amount',\
|
""" get balance of current line,
|
||||||
'_parent_reconciliation.state')
|
try to speed up by usage of last reconcilitaion
|
||||||
def on_change_with_balance(self, name=None):
|
|
||||||
""" compute balance until current line, with current sort order,
|
|
||||||
try to use a reconciliation as start to speed up calculation
|
|
||||||
"""
|
"""
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Reconciliation = pool.get('cashbook.recon')
|
Reconciliation = pool.get('cashbook.recon')
|
||||||
Line = pool.get('cashbook.line')
|
Line2 = pool.get('cashbook.line')
|
||||||
|
|
||||||
def get_from_last_recon(line2):
|
def get_from_last_recon(line2):
|
||||||
""" search last reconciliation in state 'done',
|
""" search last reconciliation in state 'done',
|
||||||
generate query
|
generate query
|
||||||
"""
|
"""
|
||||||
query2 = []
|
query2 = []
|
||||||
end_amount = None
|
end_value = None
|
||||||
|
|
||||||
recons = Reconciliation.search([
|
recons = Reconciliation.search([
|
||||||
('cashbook.id', '=', self.cashbook.id),
|
('cashbook.id', '=', line.cashbook.id),
|
||||||
('date_to', '<=', line2.date),
|
('date_to', '<=', line2.date),
|
||||||
('state', '=', 'done'),
|
('state', '=', 'done'),
|
||||||
], order=[('date_from', 'DESC')], limit=1)
|
], order=[('date_from', 'DESC')], limit=1)
|
||||||
|
@ -705,42 +702,56 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
||||||
('reconciliation.id', '!=', recons[0]),
|
('reconciliation.id', '!=', recons[0]),
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
end_amount = recons[0].end_amount
|
end_value = getattr(recons[0], 'end_%s' % field_name)
|
||||||
return (query2, end_amount)
|
return (query2, end_value)
|
||||||
|
|
||||||
if self.cashbook:
|
if line.cashbook:
|
||||||
query = [
|
query = [
|
||||||
('cashbook.id', '=', self.cashbook.id),
|
('cashbook.id', '=', line.cashbook.id),
|
||||||
]
|
]
|
||||||
balance = Decimal('0.0')
|
balance = Decimal('0.0')
|
||||||
|
|
||||||
# get existing reconciliation, starting before current line
|
# get existing reconciliation, starting before current line
|
||||||
# this will speed up calculation of by-line-balance
|
# this will speed up calculation of by-line-balance
|
||||||
if self.date is not None:
|
if line.date is not None:
|
||||||
if self.reconciliation:
|
if line.reconciliation:
|
||||||
if self.reconciliation.state == 'done':
|
if line.reconciliation.state == 'done':
|
||||||
query.append(
|
query.append(
|
||||||
('reconciliation.id', '=', self.reconciliation.id),
|
('reconciliation.id', '=', line.reconciliation.id),
|
||||||
)
|
)
|
||||||
balance = self.reconciliation.start_amount
|
balance = getattr(line.reconciliation, 'start_%s' % field_name)
|
||||||
else :
|
else :
|
||||||
(query2, balance2) = get_from_last_recon(self)
|
(query2, balance2) = get_from_last_recon(line)
|
||||||
query.extend(query2)
|
query.extend(query2)
|
||||||
if balance2 is not None:
|
if balance2 is not None:
|
||||||
balance = balance2
|
balance = balance2
|
||||||
else :
|
else :
|
||||||
(query2, balance2) = get_from_last_recon(self)
|
(query2, balance2) = get_from_last_recon(line)
|
||||||
query.extend(query2)
|
query.extend(query2)
|
||||||
if balance2 is not None:
|
if balance2 is not None:
|
||||||
balance = balance2
|
balance = balance2
|
||||||
|
|
||||||
lines = Line.search(query)
|
lines = Line2.search(query)
|
||||||
for line in lines:
|
for line3 in lines:
|
||||||
balance += line.credit - line.debit
|
balance += getattr(line3, credit_name) - getattr(line3, debit_name)
|
||||||
if line.id == self.id:
|
if line3.id == line.id:
|
||||||
break
|
break
|
||||||
return balance
|
return balance
|
||||||
|
|
||||||
|
@fields.depends('id', 'date', 'cashbook', \
|
||||||
|
'_parent_cashbook.id', 'reconciliation', \
|
||||||
|
'_parent_reconciliation.start_amount',\
|
||||||
|
'_parent_reconciliation.state')
|
||||||
|
def on_change_with_balance(self, name=None):
|
||||||
|
""" compute balance until current line, with current sort order,
|
||||||
|
try to use a reconciliation as start to speed up calculation
|
||||||
|
"""
|
||||||
|
Line2 = Pool().get('cashbook.line')
|
||||||
|
return Line2.get_balance_of_line(self,
|
||||||
|
field_name='amount',
|
||||||
|
credit_name='credit',
|
||||||
|
debit_name='debit')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_by_bookingtype(cls, values, line=None):
|
def clear_by_bookingtype(cls, values, line=None):
|
||||||
""" clear some fields by value of bookingtype
|
""" clear some fields by value of bookingtype
|
||||||
|
|
|
@ -1454,6 +1454,10 @@ msgctxt "field:cashbook.recon,predecessor:"
|
||||||
msgid "Predecessor"
|
msgid "Predecessor"
|
||||||
msgstr "Vorgänger"
|
msgstr "Vorgänger"
|
||||||
|
|
||||||
|
msgctxt "field:cashbook.recon,feature:"
|
||||||
|
msgid "Feature"
|
||||||
|
msgstr "Merkmal"
|
||||||
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# cashbook.runrepbook.start #
|
# cashbook.runrepbook.start #
|
||||||
|
|
|
@ -1378,6 +1378,10 @@ msgctxt "field:cashbook.recon,predecessor:"
|
||||||
msgid "Predecessor"
|
msgid "Predecessor"
|
||||||
msgstr "Predecessor"
|
msgstr "Predecessor"
|
||||||
|
|
||||||
|
msgctxt "field:cashbook.recon,feature:"
|
||||||
|
msgid "Feature"
|
||||||
|
msgstr "Feature"
|
||||||
|
|
||||||
msgctxt "model:cashbook.runrepbook.start,name:"
|
msgctxt "model:cashbook.runrepbook.start,name:"
|
||||||
msgid "Cashbook Report"
|
msgid "Cashbook Report"
|
||||||
msgstr "Cashbook Report"
|
msgstr "Cashbook Report"
|
||||||
|
|
|
@ -40,6 +40,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
||||||
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
||||||
date = fields.Date(string='Date', required=True, select=True,
|
date = fields.Date(string='Date', required=True, select=True,
|
||||||
states=STATES, depends=DEPENDS)
|
states=STATES, depends=DEPENDS)
|
||||||
|
feature = fields.Function(fields.Char(string='Feature', readonly=True,
|
||||||
|
states={'invisible': True}), 'on_change_with_feature')
|
||||||
|
|
||||||
date_from = fields.Date(string='Start Date',
|
date_from = fields.Date(string='Start Date',
|
||||||
required=True,
|
required=True,
|
||||||
|
@ -342,6 +344,13 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
||||||
IrDate = Pool().get('ir.date')
|
IrDate = Pool().get('ir.date')
|
||||||
return IrDate.today()
|
return IrDate.today()
|
||||||
|
|
||||||
|
@fields.depends('cashbook', '_parent_cashbook.btype')
|
||||||
|
def on_change_with_feature(self, name=None):
|
||||||
|
""" get feature-set
|
||||||
|
"""
|
||||||
|
if self.cashbook:
|
||||||
|
return self.cashbook.btype.feature
|
||||||
|
|
||||||
@fields.depends('cashbook', '_parent_cashbook.id', 'date_from')
|
@fields.depends('cashbook', '_parent_cashbook.id', 'date_from')
|
||||||
def on_change_with_predecessor(self, name=None):
|
def on_change_with_predecessor(self, name=None):
|
||||||
""" get predecessor
|
""" get predecessor
|
||||||
|
@ -366,7 +375,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
||||||
|
|
||||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||||
def on_change_with_currency_digits(self, name=None):
|
def on_change_with_currency_digits(self, name=None):
|
||||||
""" currency of cashbook
|
""" currency-digits of cashbook
|
||||||
"""
|
"""
|
||||||
if self.cashbook:
|
if self.cashbook:
|
||||||
return self.cashbook.currency.digits
|
return self.cashbook.currency.digits
|
||||||
|
|
|
@ -231,6 +231,7 @@ class ReconTestCase(ModuleTestCase):
|
||||||
}])
|
}])
|
||||||
self.assertEqual(book.name, 'Book 1')
|
self.assertEqual(book.name, 'Book 1')
|
||||||
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
|
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
|
||||||
|
self.assertEqual(book.reconciliations[0].feature, 'gen')
|
||||||
|
|
||||||
Reconciliation.wfcheck(list(book.reconciliations))
|
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]')
|
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
|
||||||
|
|
|
@ -33,4 +33,6 @@ full copyright notices and license terms. -->
|
||||||
|
|
||||||
<field name="lines" colspan="6"
|
<field name="lines" colspan="6"
|
||||||
view_ids="cashbook.line_recon_view_list,cashbook.line_view_form"/>
|
view_ids="cashbook.line_recon_view_list,cashbook.line_view_form"/>
|
||||||
|
|
||||||
|
<field name="feature"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue