neu: kategorie, config + test
This commit is contained in:
parent
b9bb433c39
commit
d6a8b254a3
28 changed files with 1255 additions and 35 deletions
47
model.py
Normal file
47
model.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# -*- 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.model import MultiValueMixin, ValueMixin, fields, Unique
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class UserValueMixin(ValueMixin):
|
||||
iduser = fields.Many2One(model_name='res.user', string="User",
|
||||
select=True, ondelete='CASCADE', required=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(UserValueMixin, cls).__setup__()
|
||||
tab_val = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
('val_uniq',
|
||||
Unique(tab_val, tab_val.iduser),
|
||||
'cashbook.msg_setting_already_exists'),
|
||||
])
|
||||
|
||||
# end UserValueMixin
|
||||
|
||||
|
||||
class UserMultiValueMixin(MultiValueMixin):
|
||||
|
||||
def updt_multivalue_pattern(self, pattern):
|
||||
""" add values to pattern
|
||||
"""
|
||||
pattern.setdefault('iduser', Transaction().user)
|
||||
return pattern
|
||||
|
||||
def get_multivalue(self, name, **pattern):
|
||||
Value = self.multivalue_model(name)
|
||||
if issubclass(Value, UserValueMixin):
|
||||
pattern = self.updt_multivalue_pattern(pattern)
|
||||
return super(UserMultiValueMixin, self).get_multivalue(name, **pattern)
|
||||
|
||||
def set_multivalue(self, name, value, **pattern):
|
||||
Value = self.multivalue_model(name)
|
||||
if issubclass(Value, UserValueMixin):
|
||||
pattern = self.updt_multivalue_pattern(pattern)
|
||||
return super(UserMultiValueMixin, self).set_multivalue(name, value, **pattern)
|
||||
|
||||
# end UserMultiValueMixin
|
Loading…
Add table
Add a link
Reference in a new issue