Move company_employee_code to extras depend.
Improve extras depend implementation. This commit refs #21903
This commit is contained in:
parent
56ca4461ac
commit
a8708aaca0
42
__init__.py
42
__init__.py
|
@ -1,28 +1,32 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from .timesheet import Work
|
||||
from .labor_yield import YieldAllocationMixin, YieldAllocation
|
||||
from .labor_yield import YieldAllocationProcedure
|
||||
from .yield_wizards import YieldAllocate, YieldAllocateProcedure
|
||||
from .yield_wizards import YieldAllocateGetParams
|
||||
from .yield_wizards import YieldAllocateSummary, YieldAllocateSummaryDet
|
||||
from .yield_wizards import YieldEnter, YieldEnterGetParams
|
||||
from . import timesheet
|
||||
from . import labor_yield
|
||||
from . import yield_wizards
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Work,
|
||||
YieldAllocationProcedure,
|
||||
YieldAllocation,
|
||||
YieldAllocateProcedure,
|
||||
YieldAllocateGetParams,
|
||||
YieldAllocateSummary,
|
||||
YieldAllocateSummaryDet,
|
||||
YieldEnterGetParams,
|
||||
timesheet.Work,
|
||||
labor_yield.YieldAllocationProcedure,
|
||||
labor_yield.YieldAllocation,
|
||||
yield_wizards.YieldAllocateProcedure,
|
||||
yield_wizards.YieldAllocateGetParams,
|
||||
yield_wizards.YieldAllocateSummary,
|
||||
yield_wizards.YieldAllocateSummaryDet,
|
||||
yield_wizards.YieldEnterGetParams,
|
||||
module='labor_yield', type_='model')
|
||||
|
||||
Pool.register(
|
||||
YieldEnter,
|
||||
YieldAllocate,
|
||||
module='labor_yield', type_='wizard')
|
||||
yield_wizards.YieldEnter,
|
||||
yield_wizards.YieldAllocate,
|
||||
module='labor_yield', type_='wizard')
|
||||
Pool.register(
|
||||
labor_yield.YieldAllocation2,
|
||||
module='labor_yield', type_='model',
|
||||
depends=['production_work_employee'])
|
||||
Pool.register(
|
||||
labor_yield.YieldAllocation3,
|
||||
yield_wizards.YieldAllocateSummaryDet3,
|
||||
module='labor_yield', type_='model',
|
||||
depends=['company_employee_code'])
|
||||
|
|
|
@ -63,4 +63,11 @@ this repository contains the full copyright notices and license terms. -->
|
|||
</record>
|
||||
</data>
|
||||
|
||||
<data depends="company_employee_code">
|
||||
<record model="ir.ui.view" id="yield_allocation_employee_code_view_tree">
|
||||
<field name="model">labor.yield.allocation</field>
|
||||
<field name="inherit" ref="yield_allocation_view_tree"/>
|
||||
<field name="name">yield_allocation_employee_code_tree</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -5,24 +5,10 @@ from trytond.pool import PoolMeta, Pool
|
|||
from trytond.pyson import Eval, Bool, Not, If, And, Equal
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
__all__ = ['YieldAllocationMixin', 'YieldAllocation',
|
||||
'YieldAllocationProcedure']
|
||||
|
||||
|
||||
def _is_wcenter_on():
|
||||
pool = Pool()
|
||||
ULCase = pool.get('company.employee')
|
||||
return isinstance(getattr(ULCase, 'work_center', None), fields.Field)
|
||||
|
||||
|
||||
class YieldAllocationMixin(object):
|
||||
"""Base for Yield Allocations"""
|
||||
|
||||
employee_code = fields.Function(fields.Char('Employee Code'),
|
||||
'on_change_with_employee_code')
|
||||
|
||||
work = fields.Many2One('timesheet.work', 'Work', required=True,
|
||||
select=True, ondelete='RESTRICT',
|
||||
domain=[('yield_available', '=', True)])
|
||||
|
@ -94,10 +80,6 @@ class YieldAllocationMixin(object):
|
|||
def default_quantity_digits():
|
||||
return 0
|
||||
|
||||
@fields.depends('employee')
|
||||
def on_change_with_employee_code(self, name=None):
|
||||
return self.employee.code or '' if self.employee else None
|
||||
|
||||
|
||||
class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
||||
"""Labor Yield Allocation"""
|
||||
|
@ -141,11 +123,6 @@ class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
|||
cls._error_messages.update({
|
||||
'invalid_offset_spec': ('Invalid offset specification: %s')})
|
||||
|
||||
if _is_wcenter_on():
|
||||
cls.work_center = fields.Function(
|
||||
fields.Many2One('production.work.center', 'Work center'),
|
||||
'get_work_center')
|
||||
|
||||
@staticmethod
|
||||
def default_allowed_offsets():
|
||||
return 0
|
||||
|
@ -155,7 +132,7 @@ class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
|||
|
||||
@fields.depends('procedure')
|
||||
def on_change_procedure(self):
|
||||
self.allowed_offsets = self.get_allowed_offsets()
|
||||
self.allowed_offsets = self.get_allowed_offsets()
|
||||
|
||||
@classmethod
|
||||
def _get_source_name(cls):
|
||||
|
@ -179,12 +156,6 @@ class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
|||
if offset_inv:
|
||||
cls.raise_user_error('invalid_offset_spec', offset_inv)
|
||||
|
||||
def get_work_center(self, name):
|
||||
with Transaction().set_context(date=self.date):
|
||||
if self.employee.work_center:
|
||||
return self.employee.work_center.id
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def default_date():
|
||||
Date_ = Pool().get('ir.date')
|
||||
|
@ -198,14 +169,11 @@ class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
|||
if work_id:
|
||||
Work = pool.get('timesheet.work')
|
||||
work = Work(work_id)
|
||||
if (work.yield_available and
|
||||
work.yield_record_granularity == 'company'):
|
||||
if (work.yield_available
|
||||
and work.yield_record_granularity == 'company'):
|
||||
attrs += [
|
||||
('/tree//field[@name="employee"]', 'tree_invisible', 1)]
|
||||
if _is_wcenter_on():
|
||||
attrs += [
|
||||
('/tree//field[@name="work_center"]',
|
||||
'tree_invisible', 1)]
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
|
@ -229,3 +197,36 @@ class YieldAllocationProcedure(DeactivableMixin, ModelSQL, ModelView):
|
|||
|
||||
def get_unallocated(self, date):
|
||||
return []
|
||||
|
||||
|
||||
class YieldAllocation2(metaclass=PoolMeta):
|
||||
__name__ = 'labor.yield.allocation'
|
||||
|
||||
work_center = fields.Function(
|
||||
fields.Many2One('production.work.center', 'Work center'),
|
||||
'get_work_center')
|
||||
|
||||
def get_work_center(self, name):
|
||||
with Transaction().set_context(date=self.date):
|
||||
if self.employee.work_center:
|
||||
return self.employee.work_center.id
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def view_attributes(cls):
|
||||
attrs = super(YieldAllocation, cls).view_attributes()
|
||||
if ('/tree//field[@name="employee"]', 'tree_invisible', 1) in attrs:
|
||||
attrs += [
|
||||
('/tree//field[@name="work_center"]', 'tree_invisible', 1)]
|
||||
return attrs
|
||||
|
||||
|
||||
class YieldAllocation3(metaclass=PoolMeta):
|
||||
__name__ = 'labor.yield.allocation'
|
||||
|
||||
employee_code = fields.Function(fields.Char('Employee Code'),
|
||||
'on_change_with_employee_code')
|
||||
|
||||
@fields.depends('employee')
|
||||
def on_change_with_employee_code(self, name=None):
|
||||
return self.employee.code if self.employee else None
|
||||
|
|
|
@ -98,6 +98,10 @@ msgctxt "field:labor.yield.allocation,date:"
|
|||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
|
||||
msgctxt "field:labor.yield.allocation,work_center:"
|
||||
msgid "Work center"
|
||||
msgstr "Centro de trabajo"
|
||||
|
||||
msgctxt "field:labor.yield.allocation,employee_code:"
|
||||
msgid "Employee Code"
|
||||
msgstr "Código Empleado"
|
||||
|
|
7
setup.py
7
setup.py
|
@ -10,7 +10,6 @@ from configparser import ConfigParser
|
|||
|
||||
MODULE2PREFIX = {
|
||||
'timesheet_work_notebook': 'datalife',
|
||||
'company_employee_code': 'datalife'
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,12 +57,6 @@ dependency_links = {
|
|||
'#egg=datalife_timesheet_work_notebook' % {
|
||||
'branch': branch,
|
||||
},
|
||||
'company_employee_code':
|
||||
'git+https://gitlab.com/datalifeit/'
|
||||
'trytond-company_employee_code@%(branch)s'
|
||||
'#egg=datalife_company_employee_code' % {
|
||||
'branch': branch,
|
||||
},
|
||||
}
|
||||
|
||||
requires = []
|
||||
|
|
|
@ -20,14 +20,6 @@ Create company::
|
|||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
>>> Sequence = Model.get('ir.sequence')
|
||||
>>> new_seq = Sequence(name='Employee code',
|
||||
... code='company.employee', company=company)
|
||||
>>> new_seq.save()
|
||||
>>> new_seq.reload()
|
||||
>>> company.employee_sequence = new_seq
|
||||
>>> company.save()
|
||||
>>> company.reload()
|
||||
|
||||
|
||||
Get uom and uom category::
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from typing import Sequence
|
||||
import unittest
|
||||
|
||||
import doctest
|
||||
|
@ -23,14 +22,9 @@ class LaborYieldTestCase(ModuleTestCase):
|
|||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Employee = pool.get('company.employee')
|
||||
Sequence = pool.get('ir.sequence')
|
||||
Work = pool.get('timesheet.work')
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
sequence = Sequence(name='Employee code',
|
||||
code='company.employee', company=company)
|
||||
company.employee_sequence = sequence
|
||||
company.save()
|
||||
party = Party(name='Pam Beesly')
|
||||
party.save()
|
||||
employee = Employee(party=party.id, company=company)
|
||||
|
|
|
@ -4,8 +4,6 @@ from trytond.model import fields
|
|||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval, Not, Bool
|
||||
|
||||
__all__ = ['Work']
|
||||
|
||||
|
||||
class Work(metaclass=PoolMeta):
|
||||
__name__ = 'timesheet.work'
|
||||
|
|
|
@ -6,9 +6,9 @@ depends:
|
|||
timesheet
|
||||
product
|
||||
timesheet_work_notebook
|
||||
company_employee_code
|
||||
|
||||
extras_depend:
|
||||
company_employee_code
|
||||
production_work_employee
|
||||
|
||||
xml:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tree editable="top">
|
||||
<field name="employee_code"/>
|
||||
<field name="employee"/>
|
||||
<field name="quantity" sum="Quantity"/>
|
||||
<field name="allocated" sum="Allocated"/>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='employee']" position="before">
|
||||
<field name="employee_code"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -4,7 +4,6 @@
|
|||
<tree editable="bottom">
|
||||
<field name="date"/>
|
||||
<field name="work"/>
|
||||
<field name="employee_code"/>
|
||||
<field name="employee"/>
|
||||
<field name="quantity"/>
|
||||
<field name="quantity_uom"/>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!-- The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='employee_code']" position="before">
|
||||
<xpath expr="/tree/field[@name='employee']" position="before">
|
||||
<field name="work_center"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, Bool, Not, PYSONEncoder, Date, And
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Wizard, StateView, StateAction, Button
|
||||
|
@ -10,11 +10,6 @@ from .labor_yield import YieldAllocationMixin
|
|||
from itertools import groupby
|
||||
|
||||
|
||||
__all__ = ['YieldAllocateGetParams', 'YieldAllocate', 'YieldAllocateProcedure',
|
||||
'YieldAllocateSummary', 'YieldAllocateSummaryDet',
|
||||
'EnterYield', 'YieldEnterGetParams']
|
||||
|
||||
|
||||
class YieldEnterGetParams(ModelView):
|
||||
"""Labor Yield Enter Get Params"""
|
||||
__name__ = 'labor.yield.enter.get_params'
|
||||
|
@ -84,8 +79,8 @@ class YieldAllocateProcedure(ModelView):
|
|||
"""Labor Yield Allocate Procedure Select"""
|
||||
__name__ = 'labor.yield.allocate.procedure'
|
||||
|
||||
procedure = fields.Many2One('labor.yield.allocation.procedure', 'Procedure',
|
||||
required=True)
|
||||
procedure = fields.Many2One('labor.yield.allocation.procedure',
|
||||
'Procedure', required=True)
|
||||
|
||||
|
||||
class YieldAllocateGetParams(ModelView):
|
||||
|
@ -149,6 +144,7 @@ class YieldAllocateSummaryDet(YieldAllocationMixin, ModelView):
|
|||
(self.manual or 0))
|
||||
return 0
|
||||
|
||||
|
||||
class YieldAllocateSummary(ModelView):
|
||||
"""Labor Yield Allocate Summary"""
|
||||
__name__ = 'labor.yield.allocate.summary'
|
||||
|
@ -342,3 +338,14 @@ class YieldAllocate(Wizard):
|
|||
self._delete_yield_allocations()
|
||||
self._write_yield_allocations()
|
||||
return 'end'
|
||||
|
||||
|
||||
class YieldAllocateSummaryDet3(metaclass=PoolMeta):
|
||||
__name__ = 'labor.yield.allocate.summary.detail'
|
||||
|
||||
employee_code = fields.Function(fields.Char('Employee Code'),
|
||||
'on_change_with_employee_code')
|
||||
|
||||
@fields.depends('employee')
|
||||
def on_change_with_employee_code(self, name=None):
|
||||
return self.employee.code if self.employee else None
|
||||
|
|
|
@ -53,6 +53,12 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="type">tree</field>
|
||||
<field name="name">allocate_summary_det_tree</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
<data depends="company_employee_code">
|
||||
<record model="ir.ui.view" id="allocate_summary_det_employee_code_view_tree">
|
||||
<field name="model">labor.yield.allocate.summary.detail</field>
|
||||
<field name="inherit" ref="allocate_summary_det_view_tree"/>
|
||||
<field name="name">yield_allocation_employee_code_tree</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
Loading…
Reference in New Issue