~vauxoo/addons-vauxoo/mrp_production_make_confirm_wzd_dev_luis

« back to all changes in this revision

Viewing changes to mrp_production_make_wzd/wizard/wizard_production_make.py

  • Committer: Luis Torres
  • Date: 2012-08-13 19:17:48 UTC
  • Revision ID: luis_t@vauxoo.com-20120813191748-feox7z7rf32wz1q4
[IMP][mrp_production_made_wzd]Change fields and metod to create manufacturing orders

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from osv import osv, fields
27
27
import decimal_precision as dp
28
28
import time
 
29
from tools.translate import _
 
30
import netsvc
29
31
 
30
32
class wizard_production_make(osv.osv_memory):
31
33
    _name='wizard.production.make'
32
34
    
33
35
    _columns = {
34
 
        'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft':[('readonly',False)]}),
 
36
        'products_ids': fields.many2many('product.product','production_make','product_id','production_make_id','Products'),
35
37
        'product_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product UoM'), required=True, states={'draft':[('readonly',False)]}, readonly=True),
36
 
        'product_uom': fields.many2one('product.uom', 'Product UOM', required=True, states={'draft':[('readonly',False)]}, readonly=True),
37
38
        'date_planned': fields.datetime('Scheduled date', required=True, select=1),
38
 
        'move_created_ids': fields.one2many('stock.move', 'production_id', 'Products to Produce', domain=[('state','not in', ('done', 'cancel'))], states={'done':[('readonly',True)]}),
 
39
        'location_src_id': fields.many2one('stock.location', 'Raw Materials Location',
 
40
            readonly=True, states={'draft':[('readonly',False)]}, help="Location where the system will look for components."),
 
41
        'location_dest_id': fields.many2one('stock.location', 'Finished Products Location',
 
42
            readonly=True, states={'draft':[('readonly',False)]}, help="Location where the system will stock the finished products."),
39
43
    }
40
44
    _defaults = {
41
45
        'date_planned': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 
42
46
    }
43
 
    
44
 
    def onchange_product_id(self, cr, uid, ids, product_id, name, context=None):
45
 
        if product_id:
46
 
            prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
47
 
            return {'value': {'name': prod.name, 'product_uom': prod.uom_id.id}}
48
 
        return {}
49
47
        
50
48
    def action_add_production(self, cr, uid, ids, context=None):
51
49
        production_obj=self.pool.get('mrp.production')
 
50
        product_obj=self.pool.get('product.product')
52
51
        new_production_obj=self.pool.get('wizard.production.make')
53
 
        product=new_production_obj.browse(cr, uid, ids, context=context)[0]
54
 
        production_obj.create(cr, uid, {
55
 
            'product_id': product.product_id.id,
56
 
            'product_qty': product.product_qty,
57
 
            'product_uom': product.product_uom.id,
58
 
            'date_planned': product.date_planned ,
59
 
            'location_src_id':'12' ,
60
 
            'location_dest_id':'11' ,
61
 
            'move_created_ids':product.move_created_ids ,
62
 
            #~ 'prodlot_id': ,
 
52
        products=new_production_obj.browse(cr, uid, ids, context=context)[0]
 
53
        for product in products.products_ids:
 
54
            data_product=product_obj.browse(cr, uid, product.id, context=context).uom_id.id
 
55
            if not product.categ_id.location_src_id.id and not products.location_src_id.id: 
 
56
                raise osv.except_osv(_('Error!'),_("Not set a location of raw material for the product: "+product.name))
 
57
            if not product.categ_id.location_dest_id.id and not products.location_dest_id.id: 
 
58
                raise osv.except_osv(_('Error!'),_("Not set a location of finished products for the product: "+product.name))
 
59
            if product.categ_id.location_src_id.id:
 
60
                location_src=product.categ_id.location_src_id.id
 
61
            else:
 
62
                location_src=products.location_src_id.id
 
63
            if product.categ_id.location_dest_id.id:
 
64
                location_dest=product.categ_id.location_dest_id.id
 
65
            else:
 
66
                location_dest=products.location_dest_id.id
 
67
            production_id=production_obj.create(cr, uid, {
 
68
                'product_id': product.id,
 
69
                'product_qty': '1.0',
 
70
                'product_uom': data_product,
 
71
                'date_planned': products.date_planned ,
 
72
                'location_src_id':location_src,
 
73
                'location_dest_id':location_dest,
63
74
                })
64
 
        return ''
 
75
            wf_service = netsvc.LocalService("workflow")
 
76
            wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_confirm', cr)
 
77
        return {}
65
78
        
66
79
wizard_production_make()
67
80