Move, refactor and abstract labor yield allocation model from stock_unit_load_labor module to labor_yield module.This commit refs #1448
This commit is contained in:
parent
2ba6117c29
commit
760db01ef6
|
@ -2,8 +2,8 @@
|
|||
# the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from timesheet import Work
|
||||
from labor_yield import YieldAllocationMixin, YieldAllocationProcedure
|
||||
from labor_yield import YieldAllocate, YieldAllocateProcedure
|
||||
from labor_yield import YieldAllocationMixin, YieldAllocation, YieldAllocationProcedure
|
||||
from labor_yield import YieldAllocate, YieldAllocateProcedure, YieldAllocateSummary, YieldAllocateSummaryDet
|
||||
|
||||
|
||||
def register():
|
||||
|
@ -11,6 +11,8 @@ def register():
|
|||
Work,
|
||||
YieldAllocationProcedure,
|
||||
YieldAllocateProcedure,
|
||||
YieldAllocateSummary,
|
||||
YieldAllocateSummaryDet,
|
||||
module='labor_yield', type_='model')
|
||||
|
||||
Pool.register(
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval, Id, Bool, Equal, Not, If, And
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval, Id, Bool, Not
|
||||
from trytond.wizard import Wizard, StateTransition, StateView, Button
|
||||
from itertools import groupby
|
||||
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
__all__ = ['YieldAllocationMixin', 'YieldAllocationProcedure',
|
||||
'YieldAllocate', 'YieldAllocateProcedure']
|
||||
__all__ = ['YieldAllocationMixin', 'YieldAllocation',
|
||||
'YieldAllocationProcedure',
|
||||
'YieldAllocate', 'YieldAllocateProcedure', 'YieldAllocateSummary', 'YieldAllocateSummaryDet']
|
||||
|
||||
|
||||
class YieldAllocationMixin(object):
|
||||
|
@ -50,6 +51,26 @@ class YieldAllocationMixin(object):
|
|||
return 0
|
||||
|
||||
|
||||
class YieldAllocation(YieldAllocationMixin, ModelSQL, ModelView):
|
||||
"""Labor Yield Allocation"""
|
||||
__name__ = 'labor.yield.allocation'
|
||||
|
||||
source = fields.Reference('Cost source', selection='get_source_name', required=True, select=True)
|
||||
|
||||
@classmethod
|
||||
def _get_source_name(cls):
|
||||
return ['']
|
||||
|
||||
@classmethod
|
||||
def get_source_name(cls):
|
||||
Model = Pool().get('ir.model')
|
||||
models = cls._get_source_name()
|
||||
models = Model.search([
|
||||
('model', 'in', models),
|
||||
])
|
||||
return [('', '')] + [(m.model, m.name) for m in models]
|
||||
|
||||
|
||||
class YieldAllocationProcedure(ModelSQL, ModelView):
|
||||
"""Labor Yield Allocation Procedure"""
|
||||
__name__ = 'labor.yield.allocation.procedure'
|
||||
|
@ -72,6 +93,19 @@ class YieldAllocateProcedure(ModelView):
|
|||
procedure = fields.Many2One('labor.yield.allocation.procedure', 'Procedure')
|
||||
|
||||
|
||||
class YieldAllocateSummaryDet(YieldAllocationMixin, ModelView):
|
||||
"""Labor Yield Allocate Summary Detail"""
|
||||
__name__ = 'labor.yield.allocate.summary.detail'
|
||||
|
||||
|
||||
class YieldAllocateSummary(ModelView):
|
||||
"""Labor Yield Allocate Summary"""
|
||||
__name__ = 'labor.yield.allocate.summary'
|
||||
|
||||
details = fields.One2Many('labor.yield.allocate.summary.detail', None, 'Yield Details',
|
||||
order=[('employee.party', 'ASC')])
|
||||
|
||||
|
||||
class YieldAllocate(Wizard):
|
||||
"""Labor Yield Allocate"""
|
||||
__name__ = 'labor.yield.allocate'
|
||||
|
@ -83,6 +117,11 @@ class YieldAllocate(Wizard):
|
|||
Button('OK', 'go_params', 'tryton-ok', default=True,
|
||||
states={'readonly': Not(Bool(Eval('procedure')))})])
|
||||
go_params = StateTransition()
|
||||
summary = StateView(
|
||||
'labor.yield.allocate.summary',
|
||||
'labor_yield.allocate_summary_view_form',
|
||||
[Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Allocate', 'do_', 'tryton-executable', default=True)])
|
||||
do_ = StateTransition()
|
||||
|
||||
def transition_start(self):
|
||||
|
@ -94,14 +133,29 @@ class YieldAllocate(Wizard):
|
|||
res = YieldAllocateProcedure.search([])
|
||||
return {'procedure': res[0].id if res else None}
|
||||
|
||||
@staticmethod
|
||||
def _get_params_state(active_procedure):
|
||||
raise NotImplementedError
|
||||
def _get_params_state(self, active_procedure):
|
||||
return 'summary'
|
||||
|
||||
def transition_go_params(self):
|
||||
return self._get_params_state(self.procedure.procedure.id)
|
||||
|
||||
def _write_yield_allocations(self):
|
||||
def _get_allocations(self):
|
||||
return []
|
||||
|
||||
def default_summary(self, fields):
|
||||
details = []
|
||||
yield_allocs = self._get_allocations()
|
||||
if yield_allocs:
|
||||
yield_allocs.sort(key=lambda a: a.get('employee'))
|
||||
for employee, eallocs_ in groupby(yield_allocs, lambda x: x.get('employee')):
|
||||
eallocs = list(eallocs_)
|
||||
details.append({'employee': employee,
|
||||
'work': self.procedure.procedure.work.id,
|
||||
'quantity': sum(ea.get('quantity') for ea in eallocs)})
|
||||
|
||||
return {'details': details}
|
||||
|
||||
def _write_yield_allocations(self, procedure_id):
|
||||
raise NotImplementedError
|
||||
|
||||
def transition_do_(self):
|
||||
|
|
|
@ -58,13 +58,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<record model="ir.action.wizard" id="wizard_yield_allocate">
|
||||
<field name="name">Labor Yield Allocate</field>
|
||||
<field name="wiz_name">labor.yield.allocate</field>
|
||||
<!--<field name="model"></field>-->
|
||||
</record>
|
||||
<!--<record model="ir.action.keyword" id="act_yield_allocate_keyword1">-->
|
||||
<!--<field name="keyword">form_action</field>-->
|
||||
<!--<field name="model">,-1</field>-->
|
||||
<!--<field name="action" ref="wizard_yield_allocate"/>-->
|
||||
<!--</record>-->
|
||||
<record model="ir.action-res.group" id="wizard_yield_allocate-group_timesheet_admin">
|
||||
<field name="action" ref="wizard_yield_allocate"/>
|
||||
<field name="group" ref="timesheet.group_timesheet_admin"/>
|
||||
|
@ -77,6 +71,21 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="type">form</field>
|
||||
<field name="name">allocate_procedure_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="allocate_summary_view_form">
|
||||
<field name="model">labor.yield.allocate.summary</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">allocate_summary_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="allocate_summary_det_view_form">
|
||||
<field name="model">labor.yield.allocate.summary.detail</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">allocate_summary_det_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="allocate_summary_det_view_tree">
|
||||
<field name="model">labor.yield.allocate.summary.detail</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">allocate_summary_det_tree</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
|
@ -10,6 +10,42 @@ msgctxt "field:labor.yield.allocate.procedure,procedure:"
|
|||
msgid "Procedure"
|
||||
msgstr "Procedimiento"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary,details:"
|
||||
msgid "Yield Details"
|
||||
msgstr "Detalles productividad"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary,id:"
|
||||
msgid "ID"
|
||||
msgstr "Identificador"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,date:"
|
||||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,employee:"
|
||||
msgid "Employee"
|
||||
msgstr "Empleado"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,id:"
|
||||
msgid "ID"
|
||||
msgstr "Identificador"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,quantity:"
|
||||
msgid "Quantity"
|
||||
msgstr "Cantidad"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,quantity_digits:"
|
||||
msgid "Quantity Digits"
|
||||
msgstr "Cantidad Digitos"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,quantity_uom:"
|
||||
msgid "Quantity UoM"
|
||||
msgstr "UdM Cantidad"
|
||||
|
||||
msgctxt "field:labor.yield.allocate.summary.detail,work:"
|
||||
msgid "Work"
|
||||
msgstr "Trabajo"
|
||||
|
||||
msgctxt "field:labor.yield.allocation.procedure,active:"
|
||||
msgid "Active"
|
||||
msgstr "Activo"
|
||||
|
@ -56,7 +92,7 @@ msgstr "Procedimiento Asignación Productividad"
|
|||
|
||||
msgctxt "model:ir.action,name:wizard_yield_allocate"
|
||||
msgid "Labor Yield Allocate"
|
||||
msgstr "Asignar productividad"
|
||||
msgstr "Asignar Productividad"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_yield"
|
||||
msgid "Yield"
|
||||
|
@ -78,6 +114,14 @@ msgctxt "model:labor.yield.allocate.procedure,name:"
|
|||
msgid "Labor Yield Allocate Procedure Select"
|
||||
msgstr "Asignar productividad selección de procedimiento"
|
||||
|
||||
msgctxt "model:labor.yield.allocate.summary,name:"
|
||||
msgid "Labor Yield Allocate Summary"
|
||||
msgstr "Asignar productividad resumen"
|
||||
|
||||
msgctxt "model:labor.yield.allocate.summary.detail,name:"
|
||||
msgid "Labor Yield Allocate Summary Detail"
|
||||
msgstr "Asignar productividad detalle de resumen"
|
||||
|
||||
msgctxt "model:labor.yield.allocation.procedure,name:"
|
||||
msgid "Labor Yield Allocation Procedure"
|
||||
msgstr "Procedimiento de asignación de productividad"
|
||||
|
@ -97,3 +141,19 @@ msgstr "Cancelar"
|
|||
msgctxt "wizard_button:labor.yield.allocate,procedure,go_params:"
|
||||
msgid "OK"
|
||||
msgstr "Aceptar"
|
||||
|
||||
msgctxt "wizard_button:labor.yield.allocate,summary,do_:"
|
||||
msgid "Allocate"
|
||||
msgstr "Asignar"
|
||||
|
||||
msgctxt "wizard_button:labor.yield.allocate,summary,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancelar"
|
||||
|
||||
msgctxt "view:labor.yield.allocate.summary:"
|
||||
msgid "Labor Yield Allocate"
|
||||
msgstr "Asignar Productividad"
|
||||
|
||||
msgctxt "view:labor.yield.allocate.summary.detail:"
|
||||
msgid "Labor Yield Allocate"
|
||||
msgstr "Asignar Productividad"
|
|
@ -0,0 +1,47 @@
|
|||
====================================
|
||||
Labor Yield Scenario
|
||||
====================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from proteus import config, Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||
... get_company
|
||||
>>> import datetime
|
||||
|
||||
Create a database::
|
||||
|
||||
>>> config_ = config.set_trytond()
|
||||
>>> config_.pool.test = True
|
||||
|
||||
Install stock_unit_load_labor_yield::
|
||||
|
||||
>>> Module = Model.get('ir.module')
|
||||
>>> module, = Module.find([
|
||||
... ('name', '=', 'labor_yield'),
|
||||
... ])
|
||||
>>> module.click('install')
|
||||
>>> Wizard('ir.module.install_upgrade').execute('upgrade')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Reload the context::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> Group = Model.get('res.group')
|
||||
>>> config_._context = User.get_preferences(True, config_.context)
|
||||
|
||||
Check allocate wizard::
|
||||
|
||||
>>> Procedure = Model.get('labor.yield.allocation.procedure')
|
||||
>>> procedure = Procedure(name='Allocation Procedure')
|
||||
>>> procedure.save()
|
||||
>>> allocate = Wizard('labor.yield.allocate')
|
||||
>>> allocate.execute('go_params')
|
||||
>>> allocate.execute('do_')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
NotImplementedError
|
|
@ -19,4 +19,9 @@ def suite():
|
|||
suite = test_suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
LaborYieldTestCase))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_labor_yield.rst',
|
||||
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
|
|
|
@ -5,6 +5,7 @@ depends:
|
|||
res
|
||||
timesheet
|
||||
company_employee_team
|
||||
product
|
||||
|
||||
xml:
|
||||
labor_yield.xml
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<form string="Labor Yield Allocate Summary Detail">
|
||||
<label name="work"/>
|
||||
<field name="work"/>
|
||||
<label name="employee"/>
|
||||
<field name="employee"/>
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
</form>
|
|
@ -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. -->
|
||||
<tree string="Labor Yield Allocate Summary Detail">
|
||||
<field name="work"/>
|
||||
<field name="employee"/>
|
||||
<field name="quantity"/>
|
||||
</tree>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<form string="Labor Yield Allocate">
|
||||
<field name="details" colspan="4"/>
|
||||
</form>
|
Loading…
Reference in New Issue