book: start-saldo + sperre bei lines>0, saldo, rec_name + tests
This commit is contained in:
parent
8fd6e0d339
commit
ae5303658e
9 changed files with 218 additions and 40 deletions
73
line.py
73
line.py
|
@ -77,6 +77,13 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
required=True, readonly=True, depends=['currency_digits'])
|
||||
credit = fields.Numeric(string='Credit', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True, readonly=True, depends=['currency_digits'])
|
||||
|
||||
balance = fields.Function(fields.Numeric(string='Balance',
|
||||
digits=(16, Eval('currency_digits', 2)),
|
||||
help='Balance of the cash book up to the current line, if the default sorting applies.',
|
||||
readonly=True, depends=['currency_digits']),
|
||||
'on_change_with_balance')
|
||||
|
||||
currency = fields.Function(fields.Many2One(model_name='currency.currency',
|
||||
string="Currency"), 'on_change_with_currency')
|
||||
currency_digits = fields.Function(fields.Integer(string='Currency Digits'),
|
||||
|
@ -94,8 +101,8 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Line, cls).__setup__()
|
||||
cls._order.insert(0, ('state', 'ASC'))
|
||||
cls._order.insert(0, ('date', 'ASC'))
|
||||
cls._order.insert(0, ('state', 'ASC'))
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
('state_val',
|
||||
|
@ -146,20 +153,6 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
pass
|
||||
|
||||
@fields.depends('bookingtype', 'category')
|
||||
def on_change_bookingtype(self):
|
||||
""" clear category if not valid type
|
||||
"""
|
||||
types = {
|
||||
'in': ['in', 'mvin'],
|
||||
'out': ['out', 'mvout'],
|
||||
}
|
||||
|
||||
if self.bookingtype:
|
||||
if self.category:
|
||||
if not self.bookingtype in types.get(self.category.cattype, ''):
|
||||
self.category = None
|
||||
|
||||
@classmethod
|
||||
def default_state(cls):
|
||||
""" default: edit
|
||||
|
@ -180,6 +173,12 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
context = Transaction().context
|
||||
return context.get('cashbook', None)
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in description +...
|
||||
"""
|
||||
return [('description',) + tuple(clause[1:])]
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" short + name
|
||||
"""
|
||||
|
@ -219,12 +218,6 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
|
||||
return [tab2]
|
||||
|
||||
@classmethod
|
||||
def search_category_view(cls, name, clause):
|
||||
""" search in category
|
||||
"""
|
||||
return [('category.rec_name',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('category')
|
||||
def on_change_with_category_view(self, name=None):
|
||||
""" show optimizef form of category for list-view
|
||||
|
@ -239,10 +232,10 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
return self.category.get_long_recname(self.category.name)
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in description +...
|
||||
def search_category_view(cls, name, clause):
|
||||
""" search in category
|
||||
"""
|
||||
return [('description',) + tuple(clause[1:])]
|
||||
return [('category.rec_name',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('date')
|
||||
def on_change_with_month(self, name=None):
|
||||
|
@ -286,6 +279,20 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
return [('cashbook.state',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('bookingtype', 'category')
|
||||
def on_change_bookingtype(self):
|
||||
""" clear category if not valid type
|
||||
"""
|
||||
types = {
|
||||
'in': ['in', 'mvin'],
|
||||
'out': ['out', 'mvout'],
|
||||
}
|
||||
|
||||
if self.bookingtype:
|
||||
if self.category:
|
||||
if not self.bookingtype in types.get(self.category.cattype, ''):
|
||||
self.category = None
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||
def on_change_with_currency(self, name=None):
|
||||
""" currency of cashbook
|
||||
|
@ -302,6 +309,23 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
else:
|
||||
return 2
|
||||
|
||||
@fields.depends('id', 'cashbook', '_parent_cashbook.start_balance', '_parent_cashbook.id')
|
||||
def on_change_with_balance(self, name=None):
|
||||
""" compute balance until current line, with current sort order
|
||||
"""
|
||||
Line = Pool().get('cashbook.line')
|
||||
|
||||
if self.cashbook:
|
||||
balance = self.cashbook.start_balance
|
||||
lines = Line.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
])
|
||||
for line in lines:
|
||||
balance += line.credit - line.debit
|
||||
if line.id == self.id:
|
||||
break
|
||||
return balance
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, values):
|
||||
""" compute debit/credit from amount
|
||||
|
@ -470,6 +494,7 @@ class LineContext(ModelView):
|
|||
""" get number of accessible cashbooks,
|
||||
depends on user-permissions
|
||||
"""
|
||||
print('-- on_change_with_num_cashbook:', Transaction().context)
|
||||
LineContext = Pool().get('cashbook.line.context')
|
||||
return LineContext.default_num_cashbook()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue