Add managing for offset_2 and offset_3 columns. This commit refs #1513

This commit is contained in:
Nicolás López 2016-10-04 15:02:13 +02:00
parent a862cbd4e5
commit a732c04943
5 changed files with 84 additions and 19 deletions

View File

@ -4,6 +4,7 @@ from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Id, Bool, Not, If
from trytond.wizard import Wizard, StateTransition, StateView, Button
from trytond.transaction import Transaction
from itertools import groupby
__metaclass__ = PoolMeta
@ -147,6 +148,16 @@ class YieldAllocateSummaryDet(YieldAllocationMixin, ModelView):
states={'readonly': Not(Bool(Eval('employee')))},
depends=['quantity_digits', 'employee'])
offset_2 = fields.Float(
'Offset 2', digits=(16, Eval('quantity_digits', 2)),
states={'readonly': Not(Bool(Eval('employee')))},
depends=['quantity_digits', 'employee'])
offset_3 = fields.Float(
'Offset 3', digits=(16, Eval('quantity_digits', 2)),
states={'readonly': Not(Bool(Eval('employee')))},
depends=['quantity_digits', 'employee'])
@classmethod
def __setup__(cls):
super(YieldAllocateSummaryDet, cls).__setup__()
@ -154,10 +165,11 @@ class YieldAllocateSummaryDet(YieldAllocationMixin, ModelView):
cls.employee.readonly = True
cls.quantity.readonly = True
@fields.depends('offset_1', 'quantity', 'employee')
@fields.depends('offset_1', 'offset_2', 'offset_3', 'quantity', 'employee')
def on_change_with_allocated(self):
if self.employee:
return (self.quantity or 0) + (self.offset_1 or 0)
return ((self.quantity or 0) + (self.offset_1 or 0) +
(self.offset_2 or 0) + (self.offset_3 or 0))
return 0
@ -191,7 +203,9 @@ class YieldAllocate(Wizard):
'labor.yield.allocate.summary',
'labor_yield.allocate_summary_view_form',
[Button('Cancel', 'end', 'tryton-cancel'),
Button('Allocate', 'do_', 'tryton-executable', default=True)])
Button('Save', 'offset_', 'tryton-executable', default=True),
Button('Allocate', 'do_', 'tryton-executable')])
offset_ = StateTransition()
do_ = StateTransition()
def transition_start(self):
@ -252,11 +266,12 @@ class YieldAllocate(Wizard):
res = Allocation.search([
('procedure', '=', procedure.id),
('date', '=', date_),
('offset_', '=', 1)])
offsets = {r.employee.id: r.quantity for r in res}
('offset_', 'in', [1, 2, 3])])
offsets = {(r.employee.id, r.offset_): r.quantity for r in res}
for d in details:
if d.get('employee', None):
d['offset_1'] = offsets.get(d['employee'], 0)
for i in range(1, 4):
d['offset_%s' % i] = offsets.get((d['employee'], i), 0)
return details
def default_summary(self, fields):
@ -284,24 +299,40 @@ class YieldAllocate(Wizard):
('procedure', '=', procedure)])
Allocation.delete(to_delete)
def _get_offset_allocations(self):
procedure = self.procedure.procedure
date_ = self.get_params.date
offset_allocs = []
for sd in self.summary.details:
for i in range(1, 4):
offset_qty = getattr(sd, 'offset_%s' % i, 0)
if offset_qty > 0:
offset_allocs.append(
{'procedure': procedure.id,
'offset_': i,
'date': date_,
'employee': sd.employee.id,
'quantity': offset_qty})
return offset_allocs
def transition_offset_(self):
pool = Pool()
Allocation = pool.get('labor.yield.allocation')
offset_allocs = self._get_offset_allocations()
if offset_allocs:
with Transaction().set_context(active_test=False):
Allocation.create(offset_allocs)
return 'end'
def _write_yield_allocations(self):
pool = Pool()
procedure = self.procedure.procedure
Allocation = pool.get('labor.yield.allocation')
date_ = self.get_params.date
yield_allocs = self._get_allocations(procedure.id)
yield_allocs.extend([
{'procedure': procedure.id,
'offset_': 1,
'date': date_,
'employee': sd.employee.id,
'quantity': sd.offset_1}
for sd in self.summary.details
if sd.offset_1 > 0])
yield_allocs.extend(self._get_offset_allocations())
if yield_allocs:
Allocation.create(yield_allocs)
with Transaction().set_context(active_test=False):
Allocation.create(yield_allocs)
def transition_do_(self):
self._delete_yield_allocations()

View File

@ -250,6 +250,14 @@ msgctxt "field:labor.yield.allocate.summary.detail,offset_1:"
msgid "Offset 1"
msgstr "Ajuste 1"
msgctxt "field:labor.yield.allocate.summary.detail,offset_2:"
msgid "Offset 2"
msgstr "Ajuste 2"
msgctxt "field:labor.yield.allocate.summary.detail,offset_3:"
msgid "Offset 3"
msgstr "Ajuste 3"
msgctxt "field:labor.yield.allocation.procedure,allowed_offsets:"
msgid "Allowed offsets"
msgstr "Ajustes permitidos"
@ -268,4 +276,20 @@ msgstr "Cancelar"
msgctxt "wizard_button:labor.yield.allocate,get_params,summary:"
msgid "Summary"
msgstr "Resumen"
msgstr "Resumen"
msgctxt "view:labor.yield.allocate.summary.detail:"
msgid "Offset 1"
msgstr "Ajuste 1"
msgctxt "view:labor.yield.allocate.summary.detail:"
msgid "Offset 2"
msgstr "Ajuste 2"
msgctxt "view:labor.yield.allocate.summary.detail:"
msgid "Offset 3"
msgstr "Ajuste 3"
msgctxt "wizard_button:labor.yield.allocate,summary,offset_:"
msgid "Save"
msgstr "Guardar"

View File

@ -8,4 +8,10 @@
<field name="quantity"/>
<label name="allocated"/>
<field name="allocated"/>
<label name="offset_1"/>
<field name="offset_1"/>
<label name="offset_2"/>
<field name="offset_2"/>
<label name="offset_3"/>
<field name="offset_3"/>
</form>

View File

@ -6,4 +6,6 @@
<field name="quantity" sum="Quantity"/>
<field name="allocated" sum="Allocated"/>
<field name="offset_1" sum="Offset 1"/>
<field name="offset_2" sum="Offset 2"/>
<field name="offset_3" sum="Offset 3"/>
</tree>

View File

@ -2,5 +2,7 @@
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form string="Labor Yield Allocate">
<label name="date"/>
<field name="date"/>
<field name="details" colspan="4"/>
</form>