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,27 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
#, fuzzy
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Наличен в график"
#, fuzzy
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Наличен в график"
#, fuzzy
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Редове от график"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Редове от график"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible en fulls de treball"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible en fulls de treball"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Línies del full de treball"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Full de treball"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Treballs del full"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Verfügbar für Zeiterfassung"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Verfügbar für Zeiterfassung"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Zeiterfassungspositionen"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Aufgabe"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Aufgaben"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible en partes de trabajo"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible en partes de trabajo"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Líneas del parte de trabajo"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Partes de trabajo"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Partes de trabajo"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Saadaval töögraafikutes"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Saadaval töögraafikutes"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Töögraafiku read"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Töögraafiku tööd"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Töögraafiku tööd"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "موجود در جدول زمانی"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "موجود در جدول زمانی"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "خطوط جدول زمانی"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "جدول زمانی کارها"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "جدول زمانی کارها"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible sur les relevés de temps"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponible sur les relevés de temps"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Lignes de relevé de temps"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Travaille de relevé de temps"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Lignes de relevé de temps des travaux"

View File

@@ -0,0 +1,25 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
#, fuzzy
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Időpozíció"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Időpozíció"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponibile sul registro delle attività"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponibile sul registro delle attività"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Linea di attività"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Registro attività"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Registro attività"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "ມີໃຫ້ໃຊ້ໃນໃບຕິດຕາມເວລາ"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "ມີໃຫ້ໃຊ້ໃນໃບຕິດຕາມເວລາ"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "ລາຍການ ໃນໃບຕິດຕາມເວລາ"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "ໜ້າວຽກໃນໃບຕິດຕາມເວລາ"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "ໜ້າວຽກໃນໃບຕິດຕາມເວລາ"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Beschikbaar in tijdsregistratie"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Beschikbaar in tijdregistartie"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Tijdregistratieregels"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "aanwezigheidsblad werken"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Tijdsregistratie werken"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponível em folhas de registro de trabalho"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponível em folhas de registro de trabalho"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Linhas do Horário de Trabalho"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Trabalho com Planilha de Horas"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Horários de Trabalho"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponibil pe foile de pontaj"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Disponibil pe foile de pontaj"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Rânduri foaie de pontaj"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Lucru pe foaie de pontaj"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Lucru pe foaie de pontaj"

View File

@@ -0,0 +1,27 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
#, fuzzy
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Доступно в табелях"
#, fuzzy
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Доступно в табелях"
#, fuzzy
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Строки табеля"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Строки табеля"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Na evidenci"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Na evidenci"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Postavke evidence"
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Evidentirano delo"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Evidentirane naloge"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr "Zaman çizelgelerinde ki boşluklar"
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr "Zaman çizelgelerinde ki boşluklar"
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr "Zaman Çizelgesi Hatlar"
#, fuzzy
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr "Zaman Çizelgesi İşler"
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr "Zaman Çizelgesi İşler"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.routing.operation,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_available:"
msgid "Available on timesheets"
msgstr ""
msgctxt "field:production.work,timesheet_lines:"
msgid "Timesheet Lines"
msgstr ""
msgctxt "field:production.work,timesheet_work:"
msgid "Timesheet Work"
msgstr ""
msgctxt "field:production.work,timesheet_works:"
msgid "Timesheet Works"
msgstr ""

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.model import fields
from trytond.pool import PoolMeta
class Operation(metaclass=PoolMeta):
__name__ = 'production.routing.operation'
timesheet_available = fields.Boolean('Available on timesheets')
@classmethod
def default_timesheet_available(cls):
return False

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="operation_view_list">
<field name="model">production.routing.operation</field>
<field name="inherit"
ref="production_routing.operation_view_list"/>
<field name="name">operation_list</field>
</record>
<record model="ir.ui.view" id="operation_view_form">
<field name="model">production.routing.operation</field>
<field name="inherit"
ref="production_routing.operation_view_form"/>
<field name="name">operation_form</field>
</record>
</data>
</tryton>

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,109 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
from trytond.modules.company.tests import (
CompanyTestMixin, create_company, create_employee, set_company)
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
class ProductionWorkTimesheetTestCase(CompanyTestMixin, ModuleTestCase):
'Test Production Work Timesheet module'
module = 'production_work_timesheet'
def create_work(self, production_state='draft'):
pool = Pool()
Work = pool.get('production.work')
Operation = pool.get('production.routing.operation')
WorkCenter = pool.get('production.work.center')
Production = pool.get('production')
work_center = WorkCenter(name='Work Center')
work_center.save()
operation = Operation(name='Operation')
operation.timesheet_available = True
operation.save()
production = Production(state=production_state)
production.save()
work = Work(
production=production,
operation=operation,
work_center=work_center)
return work
@with_transaction()
def test_set_timesheet_work(self):
'Test _set_timesheet_work'
pool = Pool()
Work = pool.get('production.work')
TimesheetWork = pool.get('timesheet.work')
Date = pool.get('ir.date')
company = create_company()
with set_company(company):
# Test on create
work = self.create_work()
work.save()
self.assertEqual(len(work.timesheet_works), 1)
# Test on write
work.operation.timesheet_available = False
work.operation.save()
work.sequence = 1 # trigger write
work.save()
self.assertFalse(work.timesheet_works)
# Test delete
work = self.create_work()
work.save()
timesheet_work, = work.timesheet_works
timesheet_work_id = timesheet_work.id
Work.delete([work])
self.assertFalse(
TimesheetWork.search([('id', '=', timesheet_work_id)]))
# Test create as done
work = self.create_work(production_state='done')
work.save()
timesheet_work, = work.timesheet_works
self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
# Set write as done
work = self.create_work()
work.save()
work.production.state = 'done'
work.production.save()
work.state = 'done' # Trigger a write to update state
work.save()
timesheet_work, = work.timesheet_works
self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
@with_transaction()
def test_timesheet_lines(self):
'Test timesheet_lines'
pool = Pool()
TimesheetLine = pool.get('timesheet.line')
company = create_company()
with set_company(company):
work = self.create_work()
work.save()
employee = create_employee(company)
timesheet_line = TimesheetLine(
employee=employee,
duration=datetime.timedelta(1))
work.timesheet_lines = [timesheet_line]
work.save()
self.assertEqual(len(work.timesheet_lines), 1)
del ModuleTestCase

View File

@@ -0,0 +1,19 @@
# 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.pool import Pool, PoolMeta
class Work(metaclass=PoolMeta):
__name__ = 'timesheet.work'
@classmethod
def _get_origin(cls):
return super()._get_origin() + ['production.work']
def _validate_company(self):
pool = Pool()
ProductionWork = pool.get('production.work')
result = super()._validate_company()
if isinstance(self.origin, ProductionWork):
result &= self.company == self.origin.company
return result

View File

@@ -0,0 +1,16 @@
[tryton]
version=7.8.0
depends:
ir
production_routing
production_work
timesheet
xml:
work.xml
routing.xml
[register]
model:
work.Work
routing.Operation
timesheet.Work

View File

@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='name']" position="after">
<label name="timesheet_available"/>
<field name="timesheet_available"/>
</xpath>
</data>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='name']" position="after">
<field name="timesheet_available"/>
</xpath>
</data>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='cycles']" position="after">
<field name="timesheet_lines" colspan="4"/>
</xpath>
</data>

View File

@@ -0,0 +1,112 @@
# 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 collections import defaultdict
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.transaction import Transaction
class Work(metaclass=PoolMeta):
__name__ = 'production.work'
timesheet_works = fields.One2Many(
'timesheet.work', 'origin', 'Timesheet Works', readonly=True, size=1)
timesheet_work = fields.Function(
fields.Many2One('timesheet.work', "Timesheet Work"),
'get_timesheet_work')
timesheet_available = fields.Function(
fields.Boolean('Available on timesheets'),
'on_change_with_timesheet_available')
timesheet_lines = fields.Function(
fields.One2Many('timesheet.line', None, 'Timesheet Lines',
states={
'invisible': ~Eval('timesheet_works'),
},
domain=[
('company', '=', Eval('company', -1)),
('work', '=', Eval('timesheet_work', -1)),
]),
'get_timesheet_lines', setter='set_timesheet_lines')
def get_timesheet_work(self, name):
if self.timesheet_works:
timesheet_work, = self.timesheet_works
return timesheet_work.id
@fields.depends('operation')
def on_change_with_timesheet_available(self, name=None):
if self.operation:
return self.operation.timesheet_available
def get_timesheet_lines(self, name):
if self.timesheet_works:
return [l.id for w in self.timesheet_works
for l in w.timesheet_lines]
else:
return []
@classmethod
def set_timesheet_lines(cls, works, name, value):
pool = Pool()
TimesheetWork = pool.get('timesheet.work')
if value:
timesheet_works = [tw for w in works for tw in w.timesheet_works]
TimesheetWork.write(timesheet_works, {
'timesheet_lines': value,
})
@classmethod
def on_modification(cls, mode, works, field_names=None):
super().on_modification(mode, works, field_names=field_names)
if mode in {'create', 'write'}:
cls._set_timesheet_work(works)
@classmethod
def on_delete(cls, works):
pool = Pool()
TimesheetWork = pool.get('timesheet.work')
callback = super().on_delete(works)
timesheet_works = [w for pw in works for w in pw.timesheet_works]
callback.append(lambda: TimesheetWork.delete(timesheet_works))
return callback
@classmethod
def _set_timesheet_work(cls, works):
pool = Pool()
Timesheet = pool.get('timesheet.work')
Date = pool.get('ir.date')
to_create = []
to_delete = []
to_write = defaultdict(list)
for work in works:
with Transaction().set_context(company=work.company.id):
today = Date.today()
if work.timesheet_available:
ended = work.state in {'done', 'cancelled'}
if not work.timesheet_works:
to_create.append({
'origin': str(work),
'company': work.company.id,
'timesheet_end_date': today if ended else None,
})
elif ended:
for timesheet in work.timesheet_works:
date = max([today]
+ [l.date for l in timesheet.timesheet_lines])
to_write[date].append(timesheet)
if (not work.timesheet_available
and work.timesheet_works):
if all(not w.timesheet_lines
for w in work.timesheet_works):
to_delete.extend(work.timesheet_works)
if to_create:
Timesheet.create(to_create)
if to_delete:
Timesheet.delete(to_delete)
for date, timesheets in list(to_write.items()):
Timesheet.write(timesheets, {
'timesheet_end_date': date,
})

View File

@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="work_view_form">
<field name="model">production.work</field>
<field name="inherit" ref="production_work.work_view_form"/>
<field name="name">work_form</field>
</record>
</data>
</tryton>