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 ##############################################################################
23 from openerp.osv import fields, osv
25 class make_procurement(osv.osv_memory):
26 _name = 'make.procurement'
27 _description = 'Make Procurements'
29 def onchange_product_id(self, cr, uid, ids, prod_id):
30 """ On Change of Product ID getting the value of related UoM.
31 @param self: The object pointer.
32 @param cr: A database cursor
33 @param uid: ID of the user currently logged in
34 @param ids: List of IDs selected
35 @param prod_id: Changed ID of Product
36 @return: A dictionary which gives the UoM of the changed Product
38 product = self.pool.get('product.product').browse(cr, uid, prod_id)
39 return {'value': {'uom_id': product.uom_id.id}}
42 'qty': fields.float('Quantity', digits=(16,2), required=True),
43 'product_id': fields.many2one('product.product', 'Product', required=True, readonly=1),
44 'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True),
45 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
46 'date_planned': fields.date('Planned Date', required=True),
50 'date_planned': fields.date.context_today,
51 'qty': lambda *args: 1.0,
54 def make_procurement(self, cr, uid, ids, context=None):
55 """ Creates procurement order for selected product.
56 @param self: The object pointer.
57 @param cr: A database cursor
58 @param uid: ID of the user currently logged in
59 @param ids: List of IDs selected
60 @param context: A standard dictionary
61 @return: A dictionary which loads Procurement form view.
63 user = self.pool.get('res.users').browse(cr, uid, uid, context=context).login
64 wh_obj = self.pool.get('stock.warehouse')
65 procurement_obj = self.pool.get('procurement.order')
66 data_obj = self.pool.get('ir.model.data')
68 for proc in self.browse(cr, uid, ids, context=context):
69 wh = wh_obj.browse(cr, uid, proc.warehouse_id.id, context=context)
70 procure_id = procurement_obj.create(cr, uid, {
71 'name':'INT: '+str(user),
72 'date_planned': proc.date_planned,
73 'product_id': proc.product_id.id,
74 'product_qty': proc.qty,
75 'product_uom': proc.uom_id.id,
76 'location_id': wh.lot_stock_id.id,
77 'procure_method':'make_to_order',
79 procurement_obj.signal_button_confirm(cr, uid, [procure_id])
81 id2 = data_obj._get_id(cr, uid, 'procurement', 'procurement_tree_view')
82 id3 = data_obj._get_id(cr, uid, 'procurement', 'procurement_form_view')
85 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
87 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
91 'view_mode': 'tree,form',
92 'res_model': 'procurement.order',
93 'res_id' : procure_id,
94 'views': [(id3,'form'),(id2,'tree')],
95 'type': 'ir.actions.act_window',
98 def default_get(self, cr, uid, fields, context=None):
99 """ To get default values for the object.
100 @param self: The object pointer.
101 @param cr: A database cursor
102 @param uid: ID of the user currently logged in
103 @param fields: List of fields for which we want default values
104 @param context: A standard dictionary
105 @return: A dictionary which of fields with values.
109 record_id = context.get('active_id')
111 res = super(make_procurement, self).default_get(cr, uid, fields, context=context)
113 if record_id and 'product_id' in fields:
114 proxy = self.pool.get('product.product')
115 product_ids = proxy.search(cr, uid, [('id', '=', record_id)], context=context, limit=1)
117 product_id = product_ids[0]
119 product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
120 res['product_id'] = product.id
121 res['uom_id'] = product.uom_id.id
123 if 'warehouse_id' in fields:
124 warehouse_id = self.pool.get('stock.warehouse').search(cr, uid, [], context=context)
125 res['warehouse_id'] = warehouse_id[0] if warehouse_id else False
129 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: