22
22
## Author(s): Stoq Team <stoq-devel@async.com.br>
24
""" Production editors """
24
""" Production editors
26
This file contains several editors used in the production process:
28
L{ProductionItemEditor}: A base class with some information about the product or
29
material (description, location, unit). See subclasses
32
L{ProducedItemSlave}: A slave for serial number input.
34
L{ProductionItemProducedEditor}: A dialog to enter the number of itens produced.
35
This uses the L{ProducedItemSlave} slave for
37
L{ProductionItemLostEditor}: A dialog to input the number of items lost.
39
L{ProductionServiceEditor}: Editor for an service item in the production order
40
L{ProductionMaterialEditor}: Item for an production material in the production
44
L{QualityTestResultEditor}: An editor for a quality test result
45
L{ProducedItemQualityTestsDialog}: A dialog listing all quality test results
46
made for an produced item
27
51
from decimal import Decimal
32
56
from kiwi.datatypes import ValidationError
33
57
from kiwi.python import Settable
34
58
from kiwi.ui.objectlist import Column
36
59
from stoqlib.database.runtime import get_current_user
37
61
from stoqlib.domain.product import ProductQualityTest
38
62
from stoqlib.domain.production import ProductionProducedItem
39
63
from stoqlib.domain.production import (ProductionItem, ProductionMaterial,
40
64
ProductionItemQualityResult,
42
from stoqlib.gui.editors.baseeditor import BaseEditor
66
from stoqlib.gui.editors.baseeditor import BaseEditor, BaseEditorSlave
43
67
from stoqlib.gui.base.lists import ModelListDialog
44
68
from stoqlib.lib.defaults import DECIMAL_PRECISION
45
69
from stoqlib.lib.message import info
161
185
def validate_confirm(self):
163
for i in range(self.produced):
164
serials.append(self.serial_slave.model.serial_number + i)
187
if self.serial_slave:
188
for i in range(self.produced):
189
serials.append(self.serial_slave.model.serial_number + i)
166
191
self.model.produce(self.produced, get_current_user(self.conn),
168
193
except (ValueError, AssertionError):
169
194
info(_(u'Can not produce this quantity. Not enough materials '
170
'can be allocated to produce this item.'))
195
'allocated to this production.'))
177
202
_(u'Produced value should be greater than zero.'))
184
class ProductionItemLostEditor(ProductionItemProducedEditor):
205
class ProductionMaterialLostEditor(ProductionItemProducedEditor):
185
206
title = _(u'Lost Items')
186
207
quantity_title = _(u'Lost:')
187
208
quantity_attribute = 'lost'
209
model_type = ProductionMaterial
189
211
def validate_confirm(self):
191
213
self.model.add_lost(self.lost)
192
214
except (ValueError, AssertionError):
193
info(_(u'Can not lost this quantity. Not enough materials can '
194
'be allocated to this item.'))
198
def on_quantity__validate(self, widget, value):
200
return ValidationError(
201
_(u'Produced value should be greater than zero.'))
215
info(_(u'Can not lose this quantity. Not enough materials '
216
'allocated to this production.'))
220
def get_max_quantity(self):
221
return self.model.allocated - self.model.lost - self.model.consumed
223
def on_quantity__validate(self, widget, value):
225
return ValidationError(
226
_(u'Lost value should be greater than zero.'))
229
class ProductionMaterialAllocateEditor(ProductionItemProducedEditor):
230
title = _(u'Allocate Items')
231
quantity_title = _(u'Allocate:')
232
quantity_attribute = 'allocate'
233
model_type = ProductionMaterial
235
def validate_confirm(self):
237
self.model.allocate(self.allocate)
238
except (ValueError, AssertionError):
239
info(_(u'Can not allocate this quantity.'))
243
def get_max_quantity(self):
244
return self.model.get_stock_quantity()
246
def on_quantity__validate(self, widget, value):
248
return ValidationError(
249
_(u'Lost value should be greater than zero.'))
253
# Production Wizard Editors
206
256
class ProductionServiceEditor(ProductionItemEditor):
207
257
model_type = ProductionService