26
26
from osv import osv, fields
27
27
import decimal_precision as dp
29
from tools.translate import _
30
32
class wizard_production_make(osv.osv_memory):
31
33
_name='wizard.production.make'
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."),
41
45
'date_planned': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
44
def onchange_product_id(self, cr, uid, ids, product_id, name, context=None):
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}}
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 ,
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
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
66
location_dest=products.location_dest_id.id
67
production_id=production_obj.create(cr, uid, {
68
'product_id': product.id,
70
'product_uom': data_product,
71
'date_planned': products.date_planned ,
72
'location_src_id':location_src,
73
'location_dest_id':location_dest,
75
wf_service = netsvc.LocalService("workflow")
76
wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_confirm', cr)
66
79
wizard_production_make()