2010-03-09 06:39:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
2014-07-07 14:58:47 +00:00
|
|
|
from openerp.osv import fields, osv, orm
|
|
|
|
from openerp.tools.translate import _
|
2010-03-09 06:39:45 +00:00
|
|
|
|
|
|
|
class make_procurement(osv.osv_memory):
|
|
|
|
_name = 'make.procurement'
|
|
|
|
_description = 'Make Procurements'
|
|
|
|
|
|
|
|
def onchange_product_id(self, cr, uid, ids, prod_id):
|
2010-04-05 12:28:03 +00:00
|
|
|
""" On Change of Product ID getting the value of related UoM.
|
|
|
|
@param self: The object pointer.
|
|
|
|
@param cr: A database cursor
|
|
|
|
@param uid: ID of the user currently logged in
|
|
|
|
@param ids: List of IDs selected
|
|
|
|
@param prod_id: Changed ID of Product
|
|
|
|
@return: A dictionary which gives the UoM of the changed Product
|
2010-03-10 06:59:59 +00:00
|
|
|
"""
|
2010-03-09 06:39:45 +00:00
|
|
|
product = self.pool.get('product.product').browse(cr, uid, prod_id)
|
|
|
|
return {'value': {'uom_id': product.uom_id.id}}
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'qty': fields.float('Quantity', digits=(16,2), required=True),
|
|
|
|
'product_id': fields.many2one('product.product', 'Product', required=True, readonly=1),
|
|
|
|
'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True),
|
|
|
|
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
|
|
|
|
'date_planned': fields.date('Planned Date', required=True),
|
|
|
|
}
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
_defaults = {
|
2012-02-13 18:07:41 +00:00
|
|
|
'date_planned': fields.date.context_today,
|
2010-08-13 12:20:05 +00:00
|
|
|
'qty': lambda *args: 1.0,
|
2010-03-09 06:39:45 +00:00
|
|
|
}
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
def make_procurement(self, cr, uid, ids, context=None):
|
2010-04-05 12:28:03 +00:00
|
|
|
""" Creates procurement order for selected product.
|
|
|
|
@param self: The object pointer.
|
|
|
|
@param cr: A database cursor
|
|
|
|
@param uid: ID of the user currently logged in
|
2010-08-13 12:20:05 +00:00
|
|
|
@param ids: List of IDs selected
|
|
|
|
@param context: A standard dictionary
|
|
|
|
@return: A dictionary which loads Procurement form view.
|
2010-03-10 06:59:59 +00:00
|
|
|
"""
|
2010-11-22 10:37:53 +00:00
|
|
|
user = self.pool.get('res.users').browse(cr, uid, uid, context=context).login
|
2010-03-15 12:18:15 +00:00
|
|
|
wh_obj = self.pool.get('stock.warehouse')
|
2010-08-13 12:20:05 +00:00
|
|
|
procurement_obj = self.pool.get('procurement.order')
|
2010-03-15 12:18:15 +00:00
|
|
|
data_obj = self.pool.get('ir.model.data')
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-11-22 10:37:53 +00:00
|
|
|
for proc in self.browse(cr, uid, ids, context=context):
|
|
|
|
wh = wh_obj.browse(cr, uid, proc.warehouse_id.id, context=context)
|
2010-03-15 12:18:15 +00:00
|
|
|
procure_id = procurement_obj.create(cr, uid, {
|
2010-03-10 06:59:59 +00:00
|
|
|
'name':'INT: '+str(user),
|
2010-03-09 06:39:45 +00:00
|
|
|
'date_planned': proc.date_planned,
|
|
|
|
'product_id': proc.product_id.id,
|
|
|
|
'product_qty': proc.qty,
|
|
|
|
'product_uom': proc.uom_id.id,
|
2015-03-27 11:23:34 +00:00
|
|
|
'warehouse_id': proc.warehouse_id.id,
|
2010-03-09 06:39:45 +00:00
|
|
|
'location_id': wh.lot_stock_id.id,
|
2013-05-13 15:27:17 +00:00
|
|
|
'company_id': wh.company_id.id,
|
2016-07-20 12:03:31 +00:00
|
|
|
}, context=context)
|
2014-07-07 09:50:30 +00:00
|
|
|
procurement_obj.signal_workflow(cr, uid, [procure_id], 'button_confirm')
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-05-27 12:47:06 +00:00
|
|
|
id2 = data_obj._get_id(cr, uid, 'procurement', 'procurement_tree_view')
|
|
|
|
id3 = data_obj._get_id(cr, uid, 'procurement', 'procurement_form_view')
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
if id2:
|
|
|
|
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
|
|
|
if id3:
|
|
|
|
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
return {
|
2010-08-13 12:20:05 +00:00
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'tree,form',
|
|
|
|
'res_model': 'procurement.order',
|
|
|
|
'res_id' : procure_id,
|
|
|
|
'views': [(id3,'form'),(id2,'tree')],
|
|
|
|
'type': 'ir.actions.act_window',
|
2010-03-09 06:39:45 +00:00
|
|
|
}
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
def default_get(self, cr, uid, fields, context=None):
|
2010-04-05 12:28:03 +00:00
|
|
|
""" To get default values for the object.
|
|
|
|
@param self: The object pointer.
|
|
|
|
@param cr: A database cursor
|
|
|
|
@param uid: ID of the user currently logged in
|
2010-08-13 12:20:05 +00:00
|
|
|
@param fields: List of fields for which we want default values
|
|
|
|
@param context: A standard dictionary
|
|
|
|
@return: A dictionary which of fields with values.
|
2010-03-10 06:59:59 +00:00
|
|
|
"""
|
2010-11-23 07:05:05 +00:00
|
|
|
if context is None:
|
2010-11-22 10:37:53 +00:00
|
|
|
context = {}
|
2012-08-13 13:35:28 +00:00
|
|
|
record_id = context.get('active_id')
|
2010-03-09 06:39:45 +00:00
|
|
|
|
2014-07-07 14:58:47 +00:00
|
|
|
if context.get('active_model') == 'product.template':
|
|
|
|
product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', '=', context.get('active_id'))], context=context)
|
|
|
|
if len(product_ids) == 1:
|
|
|
|
record_id = product_ids[0]
|
|
|
|
else:
|
|
|
|
raise orm.except_orm(_('Warning'), _('Please use the Product Variant vue to request a procurement.'))
|
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
res = super(make_procurement, self).default_get(cr, uid, fields, context=context)
|
2012-08-13 13:35:28 +00:00
|
|
|
|
|
|
|
if record_id and 'product_id' in fields:
|
|
|
|
proxy = self.pool.get('product.product')
|
|
|
|
product_ids = proxy.search(cr, uid, [('id', '=', record_id)], context=context, limit=1)
|
|
|
|
if product_ids:
|
|
|
|
product_id = product_ids[0]
|
|
|
|
|
|
|
|
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
|
|
|
res['product_id'] = product.id
|
|
|
|
res['uom_id'] = product.uom_id.id
|
|
|
|
|
|
|
|
if 'warehouse_id' in fields:
|
|
|
|
warehouse_id = self.pool.get('stock.warehouse').search(cr, uid, [], context=context)
|
|
|
|
res['warehouse_id'] = warehouse_id[0] if warehouse_id else False
|
|
|
|
|
2010-03-09 06:39:45 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|