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:
|
||||
return 2
|
||||
|
||||
@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
|
||||
@classmethod
|
||||
def get_balance_of_line(cls, line, field_name='amount', credit_name='credit', debit_name='debit'):
|
||||
""" get balance of current line,
|
||||
try to speed up by usage of last reconcilitaion
|
||||
"""
|
||||
pool = Pool()
|
||||
Reconciliation = pool.get('cashbook.recon')
|
||||
Line = pool.get('cashbook.line')
|
||||
Line2 = pool.get('cashbook.line')
|
||||
|
||||
def get_from_last_recon(line2):
|
||||
""" search last reconciliation in state 'done',
|
||||
generate query
|
||||
"""
|
||||
query2 = []
|
||||
end_amount = None
|
||||
end_value = None
|
||||
|
||||
recons = Reconciliation.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('cashbook.id', '=', line.cashbook.id),
|
||||
('date_to', '<=', line2.date),
|
||||
('state', '=', 'done'),
|
||||
], order=[('date_from', 'DESC')], limit=1)
|
||||
|
@ -705,42 +702,56 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
('reconciliation.id', '!=', recons[0]),
|
||||
],
|
||||
])
|
||||
end_amount = recons[0].end_amount
|
||||
return (query2, end_amount)
|
||||
end_value = getattr(recons[0], 'end_%s' % field_name)
|
||||
return (query2, end_value)
|
||||
|
||||
if self.cashbook:
|
||||
if line.cashbook:
|
||||
query = [
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('cashbook.id', '=', line.cashbook.id),
|
||||
]
|
||||
balance = Decimal('0.0')
|
||||
|
||||
# get existing reconciliation, starting before current line
|
||||
# this will speed up calculation of by-line-balance
|
||||
if self.date is not None:
|
||||
if self.reconciliation:
|
||||
if self.reconciliation.state == 'done':
|
||||
if line.date is not None:
|
||||
if line.reconciliation:
|
||||
if line.reconciliation.state == 'done':
|
||||
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 :
|
||||
(query2, balance2) = get_from_last_recon(self)
|
||||
(query2, balance2) = get_from_last_recon(line)
|
||||
query.extend(query2)
|
||||
if balance2 is not None:
|
||||
balance = balance2
|
||||
else :
|
||||
(query2, balance2) = get_from_last_recon(self)
|
||||
(query2, balance2) = get_from_last_recon(line)
|
||||
query.extend(query2)
|
||||
if balance2 is not None:
|
||||
balance = balance2
|
||||
|
||||
lines = Line.search(query)
|
||||
for line in lines:
|
||||
balance += line.credit - line.debit
|
||||
if line.id == self.id:
|
||||
lines = Line2.search(query)
|
||||
for line3 in lines:
|
||||
balance += getattr(line3, credit_name) - getattr(line3, debit_name)
|
||||
if line3.id == line.id:
|
||||
break
|
||||
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
|
||||
def clear_by_bookingtype(cls, values, line=None):
|
||||
""" clear some fields by value of bookingtype
|
||||
|
|
|
@ -1454,6 +1454,10 @@ msgctxt "field:cashbook.recon,predecessor:"
|
|||
msgid "Predecessor"
|
||||
msgstr "Vorgänger"
|
||||
|
||||
msgctxt "field:cashbook.recon,feature:"
|
||||
msgid "Feature"
|
||||
msgstr "Merkmal"
|
||||
|
||||
|
||||
#############################
|
||||
# cashbook.runrepbook.start #
|
||||
|
|
|
@ -1378,6 +1378,10 @@ msgctxt "field:cashbook.recon,predecessor:"
|
|||
msgid "Predecessor"
|
||||
msgstr "Predecessor"
|
||||
|
||||
msgctxt "field:cashbook.recon,feature:"
|
||||
msgid "Feature"
|
||||
msgstr "Feature"
|
||||
|
||||
msgctxt "model:cashbook.runrepbook.start,name:"
|
||||
msgid "Cashbook Report"
|
||||
msgstr "Cashbook Report"
|
||||
|
|
|
@ -40,6 +40,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
||||
date = fields.Date(string='Date', required=True, select=True,
|
||||
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',
|
||||
required=True,
|
||||
|
@ -342,6 +344,13 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
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')
|
||||
def on_change_with_predecessor(self, name=None):
|
||||
""" get predecessor
|
||||
|
@ -366,7 +375,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
""" currency of cashbook
|
||||
""" currency-digits of cashbook
|
||||
"""
|
||||
if self.cashbook:
|
||||
return self.cashbook.currency.digits
|
||||
|
|
|
@ -231,6 +231,7 @@ class ReconTestCase(ModuleTestCase):
|
|||
}])
|
||||
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].feature, 'gen')
|
||||
|
||||
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]')
|
||||
|
|
|
@ -33,4 +33,6 @@ full copyright notices and license terms. -->
|
|||
|
||||
<field name="lines" colspan="6"
|
||||
view_ids="cashbook.line_recon_view_list,cashbook.line_view_form"/>
|
||||
|
||||
<field name="feature"/>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue