~eduardo-bayardo-bias/bias-trunk/bias_trunk

« back to all changes in this revision

Viewing changes to medical_lab/wizard/wizard_create_lab_pos.py

  • Committer: Eduardo Bayardo
  • Date: 2011-06-23 21:44:20 UTC
  • Revision ID: eduardo@eduardo-20110623214420-w63z1yahu6bo8kw9
agregue vista de costos de movimientos de stock para tener traceabilidad de costo estandar en modulo bias_product_related_cost

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
import wizard
 
24
import pooler
 
25
from tools.translate import _
 
26
 
 
27
pos_form = """<?xml version="1.0"?>
 
28
<form string="Create POS">
 
29
    <separator colspan="4" string="Select Doctor" />
 
30
    <field name="doctor_id"/>
 
31
</form>
 
32
"""
 
33
 
 
34
pos_fields = {
 
35
    'doctor_id': {
 
36
        'string': 'Doctor',
 
37
        'type': 'many2one',
 
38
        'relation': 'medical.physician',
 
39
        'required': True
 
40
    },
 
41
}
 
42
 
 
43
def _create_pos(obj, cr, uid, data, context):
 
44
 
 
45
    pool = pooler.get_pool(cr.dbname)
 
46
    pos_obj = pool.get('pos.order')
 
47
    patient_obj = pool.get('medical.patient')
 
48
    lab_test_obj = pool.get('medical.patient.lab.test')#lab_test_ids
 
49
 
 
50
    pos_data={}
 
51
    
 
52
    patient = patient_obj.browse( cr, uid, data['ids'])[0]
 
53
    if patient.name.insurance:
 
54
        pos_data['partner_id'] = patient.name.insurance[0].company.id
 
55
        pos_data['note']="Patient name :"+patient.name.name+" with insurance No. : "+patient.name.insurance[0].name
 
56
    else:
 
57
        pos_data['partner_id'] = patient.name.id
 
58
    
 
59
    lab_test_ids = lab_test_obj.search(cr, uid, [('doctor_id','=',data['form']['doctor_id']),('state','=','draft'),('patient_id','=',patient.id)])
 
60
    test_line=[]
 
61
    for test in lab_test_obj.browse(cr, uid, lab_test_ids):
 
62
        test_line.append((0,0,{'product_id':test.name.product_id.id,
 
63
                                'qty':1,
 
64
                                'price_unit':test.name.product_id.lst_price}))
 
65
    if test_line:
 
66
        pos_data['lines'] = test_line
 
67
        pos_id = pos_obj.create(cr, uid, pos_data)
 
68
 
 
69
        return {
 
70
            'domain': "[('id','=', "+str(pos_id)+")]",
 
71
            'name': 'POS',
 
72
            'view_type': 'form',
 
73
            'view_mode': 'tree,form',
 
74
            'res_model': 'pos.order',
 
75
            'type': 'ir.actions.act_window'
 
76
        }
 
77
    raise  wizard.except_wizard(_('UserError'),_('No Lab test exist for selected Dr.'))
 
78
 
 
79
class make_lab_pos(wizard.interface):
 
80
    states = {
 
81
        'init': {
 
82
            'actions': [],
 
83
            'result': {
 
84
                'type': 'form',
 
85
                'arch': pos_form,
 
86
                'fields': pos_fields,
 
87
                'state': [
 
88
                    ('end', 'Cancel'),
 
89
                    ('create_pos', 'Create POS')
 
90
                ]
 
91
            }
 
92
        },
 
93
        'create_pos': {
 
94
            'actions': [],
 
95
            'result': {
 
96
                'type': 'action',
 
97
                'action': _create_pos,
 
98
                'state': 'end'
 
99
            }
 
100
        },
 
101
    }
 
102
 
 
103
make_lab_pos("patient.create_lab_pos")
 
104
 
 
105
 
 
106
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
107