~romaia/stoq/quality

« back to all changes in this revision

Viewing changes to stoqlib/gui/editors/productioneditor.py

  • Committer: Ronaldo Maia
  • Date: 2011-10-26 15:20:52 UTC
  • Revision ID: romaia@async.com.br-20111026152052-i9f0sgl9h6mhe2qa
Move add produced/lost funcionality from ProductionItemSearch to ProductionDetailsDialog. Add funcionality to allocate more material for the production and return remainng quantity after the production is closed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
##
22
22
## Author(s): Stoq Team <stoq-devel@async.com.br>
23
23
##
24
 
""" Production editors """
 
24
""" Production editors
 
25
 
 
26
This file contains several editors used in the production process:
 
27
 
 
28
L{ProductionItemEditor}: A base class with some information about the product or
 
29
                         material (description, location, unit). See subclasses
 
30
                         for specifc usage.
 
31
 
 
32
L{ProducedItemSlave}: A slave for serial number input.
 
33
 
 
34
L{ProductionItemProducedEditor}: A dialog to enter the number of itens produced.
 
35
                                 This uses the L{ProducedItemSlave} slave for
 
36
                                 serial number input
 
37
L{ProductionItemLostEditor}: A dialog to input the number of items lost.
 
38
 
 
39
L{ProductionServiceEditor}: Editor for an service item in the production order
 
40
L{ProductionMaterialEditor}: Item for an production material in the production
 
41
                             order
 
42
 
 
43
 
 
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
 
47
 
 
48
"""
25
49
 
26
50
import datetime
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
35
 
 
36
59
from stoqlib.database.runtime import get_current_user
 
60
 
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,
41
65
                                       ProductionService)
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
47
71
 
48
72
_ = stoqlib_gettext
49
73
 
 
74
 
 
75
 
 
76
 
50
77
class ProductionItemEditor(BaseEditor):
51
78
    """This is a base class for all items used in a production:
52
79
        - ProductionItem (For both Produced and Lost items)
97
124
 
98
125
 
99
126
 
100
 
from stoqlib.gui.editors.baseeditor import BaseEditorSlave
101
 
 
102
127
class ProducedItemSlave(BaseEditorSlave):
103
128
    """
104
129
    """
135
160
 
136
161
class ProductionItemProducedEditor(ProductionItemEditor):
137
162
    title = _(u'Produce Items')
138
 
 
139
163
    quantity_title = _(u'Produced:')
140
164
    quantity_attribute = 'produced'
141
165
 
160
184
 
161
185
    def validate_confirm(self):
162
186
        serials = []
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)
165
190
        try:
166
191
            self.model.produce(self.produced, get_current_user(self.conn),
167
192
                               serials)
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.'))
171
196
            return False
172
197
        return True
173
198
 
177
202
                _(u'Produced value should be greater than zero.'))
178
203
 
179
204
 
180
 
 
181
 
 
182
 
 
183
 
 
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
188
210
 
189
211
    def validate_confirm(self):
190
212
        try:
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.'))
195
 
            return False
196
 
        return True
197
 
 
198
 
    def on_quantity__validate(self, widget, value):
199
 
        if value <= 0:
200
 
            return ValidationError(
201
 
                _(u'Produced value should be greater than zero.'))
202
 
 
203
 
 
204
 
 
 
215
            info(_(u'Can not lose this quantity. Not enough materials '
 
216
                    'allocated to this production.'))
 
217
            return False
 
218
        return True
 
219
 
 
220
    def get_max_quantity(self):
 
221
        return self.model.allocated - self.model.lost - self.model.consumed
 
222
 
 
223
    def on_quantity__validate(self, widget, value):
 
224
        if value <= 0:
 
225
            return ValidationError(
 
226
                _(u'Lost value should be greater than zero.'))
 
227
 
 
228
 
 
229
class ProductionMaterialAllocateEditor(ProductionItemProducedEditor):
 
230
    title = _(u'Allocate Items')
 
231
    quantity_title = _(u'Allocate:')
 
232
    quantity_attribute = 'allocate'
 
233
    model_type = ProductionMaterial
 
234
 
 
235
    def validate_confirm(self):
 
236
        try:
 
237
            self.model.allocate(self.allocate)
 
238
        except (ValueError, AssertionError):
 
239
            info(_(u'Can not allocate this quantity.'))
 
240
            return False
 
241
        return True
 
242
 
 
243
    def get_max_quantity(self):
 
244
        return self.model.get_stock_quantity()
 
245
 
 
246
    def on_quantity__validate(self, widget, value):
 
247
        if value <= 0:
 
248
            return ValidationError(
 
249
                _(u'Lost value should be greater than zero.'))
 
250
 
 
251
 
 
252
#
 
253
#   Production Wizard Editors
 
254
#
205
255
 
206
256
class ProductionServiceEditor(ProductionItemEditor):
207
257
    model_type = ProductionService