1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import netsvc
from tools.misc import UpdateableStr, UpdateableDict
import pooler
import wizard
from osv import osv
arch = UpdateableStr()
fields = UpdateableDict()
def get_default(val):
def fct(uid, data, state):
return val
return fct
def _get_cases(self, cr, uid, data, context):
wrk_obj=pooler.get_pool(cr.dbname).get('mrp.production.workcenter.line').browse(cr,uid,data['id'])
prod_obj=pooler.get_pool(cr.dbname).get('product.product').browse(cr,uid,wrk_obj.production_id.product_id.id)
fields.clear()
arch_lst = ['<?xml version="1.0"?>', '<form string="Quality Testing">']
arch_lst.append('<field name="test_date"/>')
fields['test_date'] = {'string':'Testing Date','type':'date','default': get_default(time.strftime('%Y-%m-%d'))}
arch_lst.append('<field name="tester" colspan="1"/>')
fields['tester'] = {'string': 'Tester','type': 'many2one', 'relation': 'hr.employee'}
arch_lst.append('<field name="product"/>')
fields['product'] = {'string': 'Product','readonly':True,
'type': 'many2one', 'relation': 'product.product',
'default':get_default(prod_obj.id)}
arch_lst.append('\n')
if prod_obj.production_test:
for case in prod_obj.production_test:
arch_lst.append('<label colspan="4" string="%s :" />' % case.name.name)
arch_lst.append('\n')
arch_lst.append('<separator colspan="4"/>')
arch_lst.append('\n')
arch_lst.append('<field name="min%s" colspan="1"/>' % (case.name.id,))
fields['min'+'%s'%case.name.id]={'string':'Min Limit',
'type':'float','readonly':True,'default':get_default(case.min_limit)}
arch_lst.append('<field name="max%s" colspan="1"/>' % (case.name.id,))
fields['max'+'%s'%case.name.id]={'string':'Max Limit',
'type':'float','readonly':True,'default':get_default(case.max_limit)}
arch_lst.append('<field name="actual%s" colspan="1"/>' % (case.name.id,))
fields['actual'+'%s'%case.name.id]={'string':'Actual','type':'float'}
arch_lst.append('<field name="uom%s" colspan="1"/>' % (case.name.id,))
fields['uom'+'%s'%case.name.id] = {'string': 'UOM','readonly':True,
'type': 'many2one', 'relation': 'product.uom',
'default':get_default(case.uom.id)}
arch_lst.append('<field name="active%s" colspan="1"/>' % (case.name.id,))
fields['active'+'%s'%case.name.id] = {'string': 'Active',
'type': 'boolean'}
arch_lst.append('\n')
arch_lst.append('\n')
arch_lst.append('</form>')
arch.string = ''.join(arch_lst)
return {}
def check(self, cr, uid, data, context):
test_obj=pooler.get_pool(cr.dbname).get('testing.result')
test_config=pooler.get_pool(cr.dbname).get('quality.test.config')
wrk=pooler.get_pool(cr.dbname).get('mrp.production.workcenter.line')
wrk_obj=wrk.browse(cr,uid,data['id'])
prod_obj=pooler.get_pool(cr.dbname).get('product.product').browse(cr,uid,wrk_obj.production_id.product_id.id)
if prod_obj.production_test:
flag=False
res={}
res={'type':'in_prod','product':data['form']['product'],'tester':data['form']['tester'],'test_date':data['form']['test_date']}
test_id=test_obj.create(cr,uid,res)
for case in prod_obj.production_test:
actual=data['form']['actual%s'%(case.name.id,)]
min=data['form']['min%s'%(case.name.id,)]
max=data['form']['max%s'%(case.name.id,)]
if data['form']['active%s'%(case.name.id,)]:
if actual> 0.00:
val={}
if (actual >=min and actual <= max):
state='accepted'
else:
state='rejected'
flag=True
val={'name':case.name.id,'min_limit':case.min_limit,'max_limit':case.max_limit,'uom':case.uom.id,
'actual_val':actual,'state':state,'test_id':test_id}
test_config.create(cr,uid,val)
if flag:
wrk.write(cr,uid,data['id'],{'qlty_test_reject':True})
wrk.write(cr,uid,data['id'],{'qlty_test_accept':False})
else:
wrk.write(cr,uid,data['id'],{'qlty_test_accept':True})
wrk.write(cr,uid,data['id'],{'qlty_test_reject':False})
return {}
class wizard_qty_test_prod(wizard.interface):
states = {
'init': {
'actions': [_get_cases],
'result': {'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('ok','OK')]}
},
'ok': {
'actions': [check],
'result': {'type': 'state', 'state': 'end'},
}
}
wizard_qty_test_prod('qty_test_prod')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: