first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,94 @@
===================
Attendance Scenario
===================
Imports::
>>> import datetime as dt
>>> from dateutil.relativedelta import relativedelta
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual, assertTrue
>>> now = dt.datetime.now()
>>> tomorrow = now + relativedelta(days=1)
>>> next_week = now + relativedelta(days=7)
Activate attendance.line module::
>>> config = activate_modules('attendance')
Create a company::
>>> _ = create_company()
>>> company = get_company()
Create an employee::
>>> Party = Model.get('party.party')
>>> Employee = Model.get('company.employee')
>>> employee = Employee()
>>> party = Party(name='Employee')
>>> party.save()
>>> employee.party = party
>>> employee.company = company
>>> employee.save()
Create an attendance record for the employee::
>>> Attendance = Model.get('attendance.line')
>>> attendance = Attendance()
>>> attendance.type
'in'
>>> attendance.employee = employee
>>> attendance.at = now
>>> attendance.save()
>>> assertEqual(attendance.date, now.date())
>>> assertTrue(attendance.rec_name)
When creating a new attendance the type is automatically set::
>>> attendance = Attendance()
>>> attendance.employee = employee
>>> attendance.at = now + relativedelta(hours=2)
>>> attendance.type
'out'
>>> attendance.save()
Close the period::
>>> Period = Model.get('attendance.period')
>>> period = Period()
>>> period.ends_at = now + relativedelta(hours=4)
>>> period.click('close')
>>> period.state
'closed'
>>> bool(period.rec_name)
True
You can't create attendances in closed periods::
>>> attendance = Attendance()
>>> attendance.employee = employee
>>> attendance.at = now
>>> attendance.type = 'in'
>>> attendance.save()
Traceback (most recent call last):
...
PeriodClosedError: ...
But it is possible in open periods::
>>> attendance.at = tomorrow
>>> attendance.save()
Update attendance date time, update its date::
>>> attendance.at = next_week
>>> attendance.save()
>>> assertEqual(attendance.date, next_week.date())

View File

@@ -0,0 +1,86 @@
=========================
Attendance Sheet Scenario
=========================
Imports::
>>> import datetime as dt
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
Activate attendance.line module::
>>> config = activate_modules('attendance')
Create a company::
>>> _ = create_company()
>>> company = get_company()
Create employees::
>>> Party = Model.get('party.party')
>>> Employee = Model.get('company.employee')
>>> employee1 = Employee()
>>> party1 = Party(name='Employee 1')
>>> party1.save()
>>> employee1.party = party1
>>> employee1.company = company
>>> employee1.save()
>>> employee2 = Employee()
>>> party2 = Party(name='Employee 2')
>>> party2.save()
>>> employee2.party = party2
>>> employee2.company = company
>>> employee2.save()
Fill attendances::
>>> Attendance = Model.get('attendance.line')
>>> def present(employee, type, at):
... attendance = Attendance(employee=employee, at=at)
... attendance.type = type
... attendance.save()
>>> present(employee1, 'in', dt.datetime(2020, 4, 1, 9))
>>> present(employee1, 'out', dt.datetime(2020, 4, 1, 12))
>>> present(employee1, 'in', dt.datetime(2020, 4, 1, 13))
>>> present(employee1, 'in', dt.datetime(2020, 4, 1, 15))
>>> present(employee1, 'out', dt.datetime(2020, 4, 1, 18))
Check attendance sheet::
>>> Sheet = Model.get('attendance.sheet')
>>> sheet, = Sheet.find([])
>>> sheet.duration
datetime.timedelta(seconds=28800)
>>> sheet.date
datetime.date(2020, 4, 1)
>>> len(sheet.lines)
3
>>> sum([l.duration for l in sheet.lines], dt.timedelta())
datetime.timedelta(seconds=28800)
Fill attendance over 1 day::
>>> present(employee1, 'in', dt.datetime(2020, 4, 2, 20))
>>> present(employee1, 'out', dt.datetime(2020, 4, 3, 6))
Check attendance sheet::
>>> sheet, = Sheet.find([('date', '=', dt.date(2020, 4, 2))])
>>> sheet.duration
datetime.timedelta(seconds=36000)
Add attendance for other employee::
>>> present(employee2, 'in', dt.datetime(2020, 4, 1, 10))
>>> present(employee2, 'out', dt.datetime(2020, 4, 1, 16))
Check attendance sheet::
>>> sheet, = Sheet.find([('employee', '=', employee2.id)])
>>> sheet.duration
datetime.timedelta(seconds=21600)

View File

@@ -0,0 +1,77 @@
=============================
Attendance Timesheet Scenario
=============================
Imports::
>>> import datetime as dt
>>> from proteus import Model
>>> from trytond import backend
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate attendance.line module::
>>> config = activate_modules(['attendance', 'timesheet'])
Create a company::
>>> _ = create_company()
>>> company = get_company()
Create work::
>>> Work = Model.get('timesheet.work')
>>> work = Work(name="Work")
>>> work.save()
Create an employee::
>>> Party = Model.get('party.party')
>>> Employee = Model.get('company.employee')
>>> employee = Employee()
>>> party = Party(name='Employee')
>>> party.save()
>>> employee.party = party
>>> employee.company = company
>>> employee.save()
Fill attendance::
>>> Attendance = Model.get('attendance.line')
>>> def present(employee, type, at):
... attendance = Attendance(employee=employee, at=at)
... attendance.type = type
... attendance.save()
>>> present(employee, 'in', dt.datetime(2020, 4, 1, 9))
>>> present(employee, 'out', dt.datetime(2020, 4, 1, 12))
>>> present(employee, 'in', dt.datetime(2020, 4, 1, 13))
>>> present(employee, 'out', dt.datetime(2020, 4, 1, 18))
Fill time sheet::
>>> Timesheet = Model.get('timesheet.line')
>>> def spend(employee, work, date, duration):
... timesheet = Timesheet(employee=employee, work=work)
... timesheet.date = date
... timesheet.duration = duration
... timesheet.save()
>>> spend(employee, work, dt.date(2020, 4, 1), dt.timedelta(hours=7))
>>> spend(employee, work, dt.date(2020, 4, 2), dt.timedelta(hours=2))
Check attendance time sheet::
>>> Sheet = Model.get('attendance.sheet')
>>> sheet, = Sheet.find([('date', '=', dt.date(2020, 4, 1))])
>>> sheet.duration
datetime.timedelta(seconds=28800)
>>> sheet.timesheet_duration
datetime.timedelta(seconds=25200)
>>> if backend.name != 'sqlite':
... sheet, = Sheet.find([('date', '=', dt.date(2020, 4, 2))])
... sheet.duration
... assertEqual(sheet.timesheet_duration, dt.timedelta(hours=2))

View File

@@ -0,0 +1,14 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.modules.company.tests import CompanyTestMixin
from trytond.tests.test_tryton import ModuleTestCase
class CompanyAttendanceTestCase(CompanyTestMixin, ModuleTestCase):
'Test Company Attendance module'
module = 'attendance'
extras = ['timesheet']
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)