Module revision. Add tests.

This commit is contained in:
Sergio Morillo 2016-09-28 14:20:47 +02:00
parent a502d0e5b5
commit 20e285bb57
7 changed files with 283 additions and 77 deletions

View file

@ -1,7 +1,7 @@
# The COPYRIGHT file at the top level of this repository contains the full # The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms. # copyright notices and license terms.
from trytond.pool import Pool from trytond.pool import Pool
from workplace import WorkPlace, Employee, Calendar, CalendarDay from .workplace import WorkPlace, Employee, Calendar, CalendarDay
def register(): def register():

View file

@ -2,22 +2,22 @@
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n" msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:staff.calendar:"
msgid "Year must be unique."
msgstr "El año debe ser único."
msgctxt "field:company.employee,active:"
msgid "Active"
msgstr "Activo"
msgctxt "field:company.employee,workplace:" msgctxt "field:company.employee,workplace:"
msgid "WorkPlace" msgid "WorkPlace"
msgstr "Centro de Trabajo" msgstr "Centro de empleo"
msgctxt "field:company.workplace,active:" msgctxt "field:company.workplace,active:"
msgid "Active" msgid "Active"
msgstr "Activo" msgstr "Activo"
msgctxt "view:company.workplace:"
msgid "WorkPlaces"
msgstr "Centros de Trabajo"
msgctxt "view:company.workplace:"
msgid "WorkPlace"
msgstr "Centro de Trabajo"
msgctxt "field:company.workplace,code:" msgctxt "field:company.workplace,code:"
msgid "Code" msgid "Code"
msgstr "Código" msgstr "Código"
@ -48,48 +48,196 @@ msgstr "Fecha modificación"
msgctxt "field:company.workplace,write_uid:" msgctxt "field:company.workplace,write_uid:"
msgid "Write User" msgid "Write User"
msgstr "Usuario que escribe." msgstr "Usuario que escribe"
msgctxt "model:ir.action,name:act_workplace" msgctxt "field:staff.calendar,create_date:"
msgid "WorkPlace" msgid "Create Date"
msgstr "Centro de Trabajo" msgstr "Fecha creación"
msgctxt "model:ir.ui.menu,name:menu_workplace" msgctxt "field:staff.calendar,create_uid:"
msgid "WorkPlaces" msgid "Create User"
msgstr "Centros de Trabajo" msgstr "Usuario creación"
msgctxt "model:ir.ui.menu,name:menu_calendar"
msgid "Calendar"
msgstr "Calendarios"
msgctxt "model:res.group,name:group_workplace_admin"
msgid "WorkPlace Admin"
msgstr "Administrador de Centro de Trabajo"
msgctxt "model:company.workplace,name:"
msgid "WorkPlace"
msgstr "Centro de Trabajo"
msgctxt "field:staff.calendar,name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.calendar,year:"
msgid "year"
msgstr "Año"
msgctxt "field:staff.calendar,days:" msgctxt "field:staff.calendar,days:"
msgid "Days" msgid "Days"
msgstr "Días" msgstr "Días"
msgctxt "field:staff.calendar,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "field:staff.calendar,name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.calendar,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.calendar,rest_day:" msgctxt "field:staff.calendar,rest_day:"
msgid "Rest Day" msgid "Rest Day"
msgstr "Día de Descanso" msgstr "Día de Descanso"
msgctxt "field:staff.calendar,write_date:"
msgid "Write Date"
msgstr "Fecha modificación"
msgctxt "field:staff.calendar,write_uid:"
msgid "Write User"
msgstr "Usuario que escribe."
msgctxt "field:staff.calendar,year:"
msgid "Year"
msgstr "Año"
msgctxt "field:staff.calendar.day,calendar:"
msgid "Calendar"
msgstr "Calendarios"
msgctxt "field:staff.calendar.day,create_date:"
msgid "Create Date"
msgstr "Fecha creación"
msgctxt "field:staff.calendar.day,create_uid:"
msgid "Create User"
msgstr "Usuario creación"
msgctxt "field:staff.calendar.day,date_:"
msgid "Date"
msgstr "Fecha"
msgctxt "field:staff.calendar.day,day_type:"
msgid "Day Type"
msgstr "Tipo día"
msgctxt "field:staff.calendar.day,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "field:staff.calendar.day,name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.calendar.day,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.calendar.day,write_date:"
msgid "Write Date"
msgstr "Fecha modificación"
msgctxt "field:staff.calendar.day,write_uid:"
msgid "Write User"
msgstr "Usuario que escribe."
msgctxt "field:staff.workplace,active:"
msgid "Active"
msgstr "Activo"
msgctxt "field:staff.workplace,calendar:"
msgid "Calendar"
msgstr "Calendario"
msgctxt "field:staff.workplace,code:"
msgid "Code"
msgstr "Código"
msgctxt "field:staff.workplace,create_date:"
msgid "Create Date"
msgstr "Fecha creación"
msgctxt "field:staff.workplace,create_uid:"
msgid "Create User"
msgstr "Usuario creación"
msgctxt "field:staff.workplace,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "field:staff.workplace,name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.workplace,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:staff.workplace,write_date:"
msgid "Write Date"
msgstr "Fecha modificación"
msgctxt "field:staff.workplace,write_uid:"
msgid "Write User"
msgstr "Usuario que escribe"
msgctxt "model:company.workplace,name:"
msgid "WorkPlace"
msgstr "Centro de empleo"
msgctxt "model:ir.action,name:act_calendar"
msgid "Calendar"
msgstr "Calendarios"
msgctxt "model:ir.action,name:act_day"
msgid "Calendar Day"
msgstr "Días calendario"
msgctxt "model:ir.action,name:act_workplace"
msgid "WorkPlace"
msgstr "Centros de empleo"
msgctxt "model:ir.ui.menu,name:menu_calendar"
msgid "Calendar"
msgstr "Calendarios"
msgctxt "model:ir.ui.menu,name:menu_workplace"
msgid "WorkPlaces"
msgstr "Centros de empleo"
msgctxt "model:res.group,name:group_workplace_admin"
msgid "WorkPlace Admin"
msgstr "Administrador de Centro de empleo"
msgctxt "model:staff.calendar,name:"
msgid "Calendar"
msgstr "Calendarios"
msgctxt "model:staff.calendar.day,name:"
msgid "Calendar Day"
msgstr "Días calendario"
msgctxt "model:staff.workplace,name:"
msgid "WorkPlace"
msgstr "Centro de empleo"
msgctxt "selection:staff.calendar,rest_day:"
msgid "Saturday"
msgstr "Sábado"
msgctxt "selection:staff.calendar,rest_day:"
msgid "Sunday"
msgstr "Domingo"
msgctxt "selection:staff.calendar.day,day_type:"
msgid "Local Holiday"
msgstr "Festivo local"
msgctxt "selection:staff.calendar.day,day_type:"
msgid "Rest"
msgstr "Descanso"
msgctxt "selection:staff.calendar.day,day_type:"
msgid "holiday"
msgstr "Festivo"
msgctxt "view:staff.workplace:"
msgid "WorkPlaces"
msgstr "Centros de empleo"
msgctxt "view:staff.calendar:" msgctxt "view:staff.calendar:"
msgid "Calendars" msgid "Calendars"
msgstr "Calendarios" msgstr "Calendarios"
msgctxt "view:company.workplace:" msgctxt "view:staff.calendar:"
msgid "Calendar" msgid "Days"
msgstr "Calendario" msgstr "Días"

View file

@ -1,27 +1,65 @@
# The COPYRIGHT file at the top level of this repository contains the full # The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms. # copyright notices and license terms.
import unittest import unittest
# import doctest import datetime
import trytond.tests.test_tryton import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase from trytond.pool import Pool
# TODO: Remove if no sceneario needed. from trytond.tests.test_tryton import ModuleTestCase, with_transaction
# from trytond.tests.test_tryton import doctest_setup, doctest_teardown from trytond.modules.company.tests import create_company, set_company
class StaffWorkplaceTestCase(ModuleTestCase): class StaffWorkplaceTestCase(ModuleTestCase):
"""Test module""" """Test module"""
module = 'staff_workplace' module = 'staff_workplace'
def setUp(self): @with_transaction()
super(StaffWorkplaceTestCase, self).setUp() def test_compute_profile_prices(self):
"""Test staff profile"""
pool = Pool()
Party = pool.get('party.party')
Employee = pool.get('company.employee')
Calendar = pool.get('staff.calendar')
CalendarDay = pool.get('staff.calendar.day')
Workplace = pool.get('staff.workplace')
special_days = [
(datetime.date(2016, 1, 1), 'holiday'),
(datetime.date(2016, 1, 6), 'local_holiday'),
(datetime.date(2016, 3, 24), 'local_holiday'),
]
test_days = [
(datetime.date(2016, 1, 1), 'holiday'),
(datetime.date(2016, 1, 2), 'work'),
(datetime.date(2016, 6, 5), 'rest'),
(datetime.date(2016, 6, 15), 'work'),
(datetime.date(2016, 1, 6), 'local_holiday'),
(datetime.date(2016, 9, 1), 'work'),
(datetime.date(2016, 3, 24), 'local_holiday'),
]
party = Party(name='Pam Beesly')
party.save()
company = create_company()
calendar = Calendar(name='Calendar 1',
year=2016, rest_day='7')
calendar.save()
workplace = Workplace(name='Workplace 1', code='WP1')
workplace.calendar = calendar
workplace.save()
with set_company(company):
employee = Employee(party=party.id, company=company)
employee.workplace = workplace
employee.save()
for date, day_type in special_days:
CalendarDay(
calendar=calendar,
date_=date,
day_type=day_type).save()
for date, day_type in test_days:
self.assertEqual(workplace.date_type(date), day_type)
def suite(): def suite():
suite = trytond.tests.test_tryton.suite() suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(StaffWorkplaceTestCase)) suite.addTests(unittest.TestLoader().loadTestsFromTestCase(StaffWorkplaceTestCase))
# TODO: remove if no scenario needed.
# suite.addTests(doctest.DocFileSuite(
# 'scenario_staff_workplace.rst',
# setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
# optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite return suite

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<form string="Calendar" > <form string="Calendars" >
<label name="name"/> <label name="name"/>
<field name="name"/> <field name="name"/>
<label name="year"/> <label name="year"/>
@ -10,7 +10,9 @@
<field name="rest_day"/> <field name="rest_day"/>
<notebook> <notebook>
<page string="Days" id="days" col="2"> <page string="Days" id="days" col="2">
<field name="days" view_ids="staff_workplace.day_view_calendar" mode="calendar,form"/> <field name="days"
view_ids="staff_workplace.day_view_calendar"
mode="calendar,form"/>
</page> </page>
</notebook> </notebook>
</form> </form>

View file

@ -1,15 +1,13 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<form string="WorkPlace"> <form string="WorkPlaces" col="6">
<group id="header" col="6"> <label name="code"/>
<label name="code"/> <field name="code"/>
<field name="code"/> <label name="name"/>
<label name="name"/> <field name="name"/>
<field name="name"/> <label name="active"/>
<label name="active"/> <field name="active"/>
<field name="active"/> <label name="calendar"/>
<label name="calendar"/> <field name="calendar"/>
<field name="calendar"/>
</group>
</form> </form>

View file

@ -13,16 +13,22 @@ class Calendar(ModelView, ModelSQL):
__name__ = 'staff.calendar' __name__ = 'staff.calendar'
name = fields.Char('Name') name = fields.Char('Name')
year = fields.Integer('Year', required=True, states={'readonly': Eval('id', 0) > 0}, depends=['id']) year = fields.Integer('Year', required=True,
states={'readonly': Eval('id', 0) > 0},
depends=['id'])
days = fields.One2Many('staff.calendar.day', 'calendar', 'Days') days = fields.One2Many('staff.calendar.day', 'calendar', 'Days')
rest_day = fields.Selection([('6', 'Saturday'), ('7', 'Sunday')], 'Rest Day' rest_day = fields.Selection([
, states={'readonly': Eval('id', 0) > 0}, depends=['id']) ('6', 'Saturday'),
('7', 'Sunday')], 'Rest Day',
states={'readonly': Eval('id', 0) > 0},
depends=['id'])
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
super(Calendar, cls).__setup__() super(Calendar, cls).__setup__()
t = cls.__table__() t = cls.__table__()
cls._sql_constraints = [('year_uk', Unique(t, t.year), 'Year must be unique.')] cls._sql_constraints = [
('year_uk', Unique(t, t.year), 'Year must be unique.')]
def get_rec_name(self, name): def get_rec_name(self, name):
return str(self.name) + ' - ' + str(self.year) return str(self.name) + ' - ' + str(self.year)
@ -36,9 +42,11 @@ class Calendar(ModelView, ModelSQL):
calendarDay = pool.get('staff.calendar.day') calendarDay = pool.get('staff.calendar.day')
if date.isoweekday() == int(self.rest_day): if date.isoweekday() == int(self.rest_day):
return 'rest' return 'rest'
res = calendarDay.search_read([('calendar', '=', self), ('date_', '=', date)], fields_names=['day_type']) res = calendarDay.search_read([
('calendar', '=', self),
('date_', '=', date)], fields_names=['day_type'], limit=1)
if res: if res:
return res.day_type return res[0]['day_type']
return 'work' return 'work'
@ -67,9 +75,13 @@ class Employee:
class CalendarDay(ModelView, ModelSQL): class CalendarDay(ModelView, ModelSQL):
"""Calendar Day""" """Calendar Day"""
__name__ = 'staff.calendar.day' __name__ = 'staff.calendar.day'
name = fields.Char('Name') name = fields.Char('Name')
calendar = fields.Many2One('staff.calendar', 'Calendar', required=True, calendar = fields.Many2One('staff.calendar', 'Calendar', required=True,
states={'readonly': Eval('id', 0) > 0}) states={'readonly': Eval('id', 0) > 0},
depends=['id'])
date_ = fields.Date('Date') date_ = fields.Date('Date')
day_type = fields.Selection( day_type = fields.Selection([
[('holiday', 'holiday'), ('local_holiday', 'Local Holiday'), ('rest', 'Rest')], 'Day Type') ('holiday', 'holiday'),
('local_holiday', 'Local Holiday'),
('rest', 'Rest')], 'Day Type')

View file

@ -1,9 +1,17 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton> <tryton>
<data> <data>
<!-- WorkPlace --> <!-- WorkPlace -->
<record model="res.group" id="group_workplace_admin"> <record model="res.group" id="group_workplace_admin">
<field name="name">WorkPlace Admin</field> <field name="name">WorkPlace Admin</field>
</record> </record>
<record model="res.user-res.group" id="user_admin_group_workplace_admin">
<field name="user" ref="res.user_admin"/>
<field name="group" ref="group_workplace_admin"/>
</record>
<record model="ir.ui.view" id="workplace_view_tree"> <record model="ir.ui.view" id="workplace_view_tree">
<field name="model">staff.workplace</field> <field name="model">staff.workplace</field>
<field name="type">tree</field> <field name="type">tree</field>
@ -44,8 +52,8 @@
<field name="perm_delete" eval="False"/> <field name="perm_delete" eval="False"/>
</record> </record>
<menuitem id="menu_workplace" name="WorkPlaces" sequence="30" parent="staff.menu_staff" <menuitem id="menu_workplace" name="WorkPlaces" sequence="30"
action="act_workplace"/> parent="staff.menu_staff" action="act_workplace"/>
<!-- Employee --> <!-- Employee -->
<record model="ir.ui.view" id="employee_form"> <record model="ir.ui.view" id="employee_form">
@ -146,7 +154,7 @@
<field name="perm_delete" eval="False"/> <field name="perm_delete" eval="False"/>
</record> </record>
<menuitem id="menu_calendar" name="Calendar" sequence="50" parent="staff.menu_staff" <menuitem id="menu_calendar" name="Calendar" sequence="50"
action="act_calendar"/> parent="staff.menu_staff" action="act_calendar"/>
</data> </data>
</tryton> </tryton>