Migrate to 6.0

This commit is contained in:
Sergio Morillo 2021-09-25 16:43:44 +02:00
parent a47cad01cd
commit 66e509ca18
6 changed files with 34 additions and 27 deletions

View File

@ -1,13 +1,13 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.pool import Pool
from .category import Category
from .timesheet import Work, WorkCategory
from . import category
from . import timesheet
def register():
Pool.register(
Category,
Work,
WorkCategory,
category.Category,
timesheet.Work,
timesheet.WorkCategory,
module='timesheet_work_category', type_='model')

View File

@ -2,15 +2,9 @@
# copyright notices and license terms.
from trytond.model import (ModelSQL, ModelView, fields, Unique,
DeactivableMixin, tree)
from trytond.pyson import Eval
from trytond.exceptions import UserError
from trytond.i18n import gettext
__all__ = ['Category']
STATES = {
'readonly': ~Eval('active'),
}
DEPENDS = ['active']
SEPARATOR = ' / '
@ -19,9 +13,9 @@ class Category(tree(), DeactivableMixin, ModelSQL, ModelView):
__name__ = 'timesheet.work.category'
name = fields.Char('Name', required=True)
parent = fields.Many2One('timesheet.work.category', 'Parent',
select=True, states=STATES, depends=DEPENDS)
select=True)
childs = fields.One2Many('timesheet.work.category', 'parent',
'Children', states=STATES, depends=DEPENDS)
'Children')
@classmethod
def __setup__(cls):
@ -29,12 +23,9 @@ class Category(tree(), DeactivableMixin, ModelSQL, ModelView):
t = cls.__table__()
cls._sql_constraints = [
('name_parent_uniq', Unique(t, t.name, t.parent),
'The name of a party category must be unique by parent.'),
'timesheet_work_category.'
'msg_timesheet_work_category_name_parent_uniq'),
]
cls._error_messages.update({
'wrong_name': ('Invalid category name "%%s": You can not use '
'"%s" in name field.' % SEPARATOR),
})
@classmethod
def validate(cls, categories):
@ -44,7 +35,10 @@ class Category(tree(), DeactivableMixin, ModelSQL, ModelView):
def check_name(self):
if SEPARATOR in self.name:
self.raise_user_error('wrong_name', (self.name,))
raise UserError(gettext(
'timesheet_work_category.'
'msg_timesheet_work_category_wrong_name',
category=self.name))
def get_rec_name(self, name):
if self.parent:

View File

@ -42,12 +42,12 @@ msgctxt "field:timesheet.work.category,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "error:timesheet.work.category:"
msgctxt "model:ir.message,text:msg_timesheet_work_category_name_parent_uniq"
msgid "The name of a party category must be unique by parent."
msgstr "El nombre de la categoría del tercero debe ser único según el padre."
msgctxt "error:timesheet.work.category:"
msgid "Invalid category name \"%s\": You can not use \" / \" in name field."
msgctxt "model:ir.message,text:msg_timesheet_work_category_name_parent_uniq"
msgid "Invalid category name \"%(category)s\": You can not use \" / \" in name field."
msgstr ""
"El nombre de la categoría \"%s\" no es correcto: No puede utilizar \" / \" "
"El nombre de la categoría \"%(category)s\" no es correcto: No puede utilizar \" / \" "
"en el campo nombre."

14
message.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tryton>
<data grouped="1">
<!-- timesheet.work.category -->
<record model="ir.message" id="msg_timesheet_work_category_wrong_name">
<field name="text">Invalid category name "%(category)s": You can not use " / " in name field.</field>
</record>
<record model="ir.message" id="msg_timesheet_work_category_name_parent_uniq">
<field name="text">The name of a party category must be unique by parent.</field>
</record>
</data>
</tryton>

View File

@ -4,8 +4,6 @@ from trytond.model import fields, ModelSQL
from trytond.pool import PoolMeta
from trytond.transaction import Transaction
__all__ = ['Work', 'WorkCategory']
class Work(metaclass=PoolMeta):
__name__ = 'timesheet.work'

View File

@ -7,3 +7,4 @@ depends:
xml:
category.xml
timesheet.xml
message.xml