book, line, category, types: berechtigung für company-user + test,
book: währung neu, line: buchungstyp, betrag, credit, debit, währung, sortierung
This commit is contained in:
parent
1a85b8e80e
commit
d57d76ba3b
20 changed files with 620 additions and 115 deletions
112
line.py
112
line.py
|
@ -10,8 +10,10 @@ from trytond.transaction import Transaction
|
|||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from decimal import Decimal
|
||||
from sql import Cast, Literal
|
||||
from sql.functions import DatePart
|
||||
from sql.conditionals import Case
|
||||
from .book import sel_state_book
|
||||
|
||||
|
||||
|
@ -21,6 +23,13 @@ sel_linetype = [
|
|||
('done', 'Done'),
|
||||
]
|
||||
|
||||
sel_bookingtype = [
|
||||
('in', 'Revenue'),
|
||||
('out', 'Expense'),
|
||||
('mvin', 'Transfer from'),
|
||||
('mvout', 'Transfer to'),
|
||||
]
|
||||
|
||||
STATES = {
|
||||
'readonly': Or(
|
||||
Eval('state', '') != 'edit',
|
||||
|
@ -47,6 +56,21 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
states=STATES, depends=DEPENDS)
|
||||
category_view = fields.Function(fields.Char(string='Category', readonly=True),
|
||||
'on_change_with_category_view', searcher='search_category_view')
|
||||
|
||||
bookingtype = fields.Selection(string='Type', required=True,
|
||||
help='Type of Booking', selection=sel_bookingtype,
|
||||
states=STATES, depends=DEPENDS)
|
||||
amount = fields.Numeric(string='Amount', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True, states=STATES, depends=DEPENDS+['currency_digits'])
|
||||
debit = fields.Numeric(string='Debit', digits=(16, Eval('currency_digits', 2)),
|
||||
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'])
|
||||
currency = fields.Function(fields.Many2One(model_name='currency.currency',
|
||||
string="Currency"), 'on_change_with_currency')
|
||||
currency_digits = fields.Function(fields.Integer(string='Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
|
||||
state = fields.Selection(string='State', required=True, readonly=True,
|
||||
select=True, selection=sel_linetype)
|
||||
state_string = state.translated('state')
|
||||
|
@ -59,6 +83,7 @@ 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'))
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
|
@ -138,6 +163,23 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
'desc': (self.description or '-')[:40],
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def order_state(tables):
|
||||
""" edit = 0, check/done = 1
|
||||
"""
|
||||
Line = Pool().get('cashbook.line')
|
||||
tab_line = Line.__table__()
|
||||
table, _ = tables[None]
|
||||
|
||||
query = tab_line.select(
|
||||
Case(
|
||||
(tab_line.state == 'edit', 1),
|
||||
(tab_line.state.in_(['check', 'done']), 0),
|
||||
else_ = 2),
|
||||
where=tab_line.id==table.id
|
||||
)
|
||||
return [query]
|
||||
|
||||
@staticmethod
|
||||
def order_category_view(tables):
|
||||
""" order: name
|
||||
|
@ -219,11 +261,65 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
return [('cashbook.state',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||
def on_change_with_currency(self, name=None):
|
||||
""" currency of cashbook
|
||||
"""
|
||||
if self.cashbook:
|
||||
return self.cashbook.currency.id
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
""" currency of cashbook
|
||||
"""
|
||||
if self.cashbook:
|
||||
return self.cashbook.currency.digits
|
||||
else:
|
||||
return 2
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, values):
|
||||
""" compute debit/credit from amount
|
||||
"""
|
||||
if isinstance(values, dict):
|
||||
type_ = values.get('bookingtype', None)
|
||||
amount = values.get('amount', None)
|
||||
else :
|
||||
type_ = getattr(values, 'bookingtype', None)
|
||||
amount = getattr(values, 'amount', None)
|
||||
|
||||
if type_:
|
||||
if amount is not None:
|
||||
if type_ in ['in', 'mvin']:
|
||||
return {
|
||||
'debit': Decimal('0.0'),
|
||||
'credit': amount,
|
||||
}
|
||||
elif type_ in ['out', 'mvout']:
|
||||
return {
|
||||
'debit': amount,
|
||||
'credit': Decimal('0.0'),
|
||||
}
|
||||
else :
|
||||
raise ValueError('invalid "bookingtype"')
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
""" add debit/credit
|
||||
"""
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for vals in vlist:
|
||||
vals.update(cls.get_debit_credit(vals))
|
||||
return super(Line, cls).create(vlist)
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
""" deny update if cashbook.line!='open'
|
||||
""" deny update if cashbook.line!='open',
|
||||
add or update debit/credit
|
||||
"""
|
||||
actions = iter(args)
|
||||
to_write = []
|
||||
for lines, values in zip(actions, actions):
|
||||
for line in lines:
|
||||
if line.cashbook.state != 'open':
|
||||
|
@ -232,7 +328,19 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
bookname = line.cashbook.rec_name,
|
||||
state_txt = line.cashbook.state_string,
|
||||
))
|
||||
super(Line, cls).write(*args)
|
||||
|
||||
# debit / credit
|
||||
if len(set(values.keys()).intersection(set({'amount', 'bookingtype'}))) > 0:
|
||||
for line in lines:
|
||||
values2 = {}
|
||||
values2.update(values)
|
||||
values2.update(cls.get_debit_credit({
|
||||
x:values.get(x, getattr(line, x)) for x in ['amount', 'bookingtype']
|
||||
}))
|
||||
to_write.extend([lines, values2])
|
||||
else :
|
||||
to_write.extend([lines, values])
|
||||
super(Line, cls).write(*to_write)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue