1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
25 from osv import fields, osv
27 class make_procurement(osv.osv_memory):
28 _name = 'make.procurement'
29 _description = 'Make Procurements'
31 def onchange_product_id(self, cr, uid, ids, prod_id):
33 @summary: On Change of Product ID getting the value of related UoM.
35 @param self: The object pointer.
36 @param cr: A database cursor
37 @param uid: ID of the user currently logged in
38 @param ids: List of IDs selected
39 @param prod_id: Changed ID of Product
41 @return: A dictionary which gives the UoM of the changed Product
44 product = self.pool.get('product.product').browse(cr, uid, prod_id)
45 return {'value': {'uom_id': product.uom_id.id}}
48 'qty': fields.float('Quantity', digits=(16,2), required=True),
49 'product_id': fields.many2one('product.product', 'Product', required=True, readonly=1),
50 'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True),
51 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
52 'date_planned': fields.date('Planned Date', required=True),
56 'date_planned': lambda *args: time.strftime('%Y-%m-%d'),
57 'qty': lambda *args: 1.0,
60 def make_procurement(self, cr, uid, ids, context=None):
62 @summary: Creates procurement order for selected product.
64 @param self: The object pointer.
65 @param cr: A database cursor
66 @param uid: ID of the user currently logged in
67 @param ids: List of IDs selected
68 @param context: A standard dictionary
70 @return: A dictionary which loads Procurement form view.
73 user = self.pool.get('res.users').browse(cr, uid, uid, context).login
74 for proc in self.browse(cr, uid, ids):
75 wh = self.pool.get('stock.warehouse').browse(cr, uid, proc.warehouse_id.id, context)
76 procure_id = self.pool.get('mrp.procurement').create(cr, uid, {
77 'name':'INT: '+str(user),
78 'date_planned': proc.date_planned,
79 'product_id': proc.product_id.id,
80 'product_qty': proc.qty,
81 'product_uom': proc.uom_id.id,
82 'location_id': wh.lot_stock_id.id,
83 'procure_method':'make_to_order',
85 wf_service = netsvc.LocalService("workflow")
86 wf_service.trg_validate(uid, 'mrp.procurement', procure_id, 'button_confirm', cr)
88 data_obj = self.pool.get('ir.model.data')
89 id2 = data_obj._get_id(cr, uid, 'mrp', 'mrp_procurement_tree_view')
90 id3 = data_obj._get_id(cr, uid, 'mrp', 'mrp_procurement_form_view')
92 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
94 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
98 'view_mode': 'tree,form',
99 'res_model': 'mrp.procurement',
100 'res_id' : procure_id,
101 'views': [(id3,'form'),(id2,'tree')],
102 'type': 'ir.actions.act_window',
105 def default_get(self, cr, uid, fields, context=None):
107 @summary: To get default values for the object.
109 @param self: The object pointer.
110 @param cr: A database cursor
111 @param uid: ID of the user currently logged in
112 @param fields: List of fields for which we want default values
113 @param context: A standard dictionary
115 @return: A dictionary which of fields with values.
118 record_id = context and context.get('record_id', False) or False
120 res = super(make_procurement, self).default_get(cr, uid, fields, context=context)
123 product_id = self.pool.get('product.product').browse(cr, uid, record_id, context=context).id
124 res['product_id'] = product_id
129 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: