[IMP]: schedular wizard improvement

bzr revid: ksa@tinyerp.co.in-20101202124133-fbs2je1udm074051
This commit is contained in:
ksa (Open ERP)
2010-12-02 18:11:33 +05:30
parent e31898c662
commit d6dad104bc
2 changed files with 74 additions and 15 deletions
+1
View File
@@ -500,6 +500,7 @@ class stock_warehouse_orderpoint(osv.osv):
result[data.id] = procurement_id
procurement_ids = procurement_obj.search(cr, uid , [('state','=','draft'),('product_id','=',data.product_id.id),('location_id','=',data.location_id.id)])
procurement_ids.sort()
result[data.id] = procurement_ids
return result
+73 -15
View File
@@ -34,14 +34,14 @@ class procurement_order(osv.osv):
def _procure_confirm(self, cr, uid, ids=None, use_new_cursor=False, context=None):
'''
Call the scheduler to check the procurement order
@param self: The object pointer
@param cr: The current row, from the database cursor,
@param uid: The current user ID for security checks
@param ids: List of selected IDs
@param use_new_cursor: False or the dbname
@param context: A standard dictionary for contextual values
@return: Dictionary of values
@return: Dictionary of values
'''
if not context:
context = {}
@@ -50,7 +50,7 @@ class procurement_order(osv.osv):
if use_new_cursor:
cr = pooler.get_db(use_new_cursor).cursor()
wf_service = netsvc.LocalService("workflow")
procurement_obj = self.pool.get('procurement.order')
if not ids:
ids = procurement_obj.search(cr, uid, [], order="date_planned")
@@ -112,13 +112,13 @@ class procurement_order(osv.osv):
if uid:
request = self.pool.get('res.request')
summary = '''Here is the procurement scheduling report.
Start Time: %s
End Time: %s
Total Procurements processed: %d
Procurements with exceptions: %d
Skipped Procurements (scheduled date outside of scheduler range) %d
Exceptions:\n'''% (start_date, end_date, report_total, report_except, report_later)
summary += '\n'.join(report)
request.create(cr, uid,
@@ -141,7 +141,7 @@ class procurement_order(osv.osv):
def create_automatic_op(self, cr, uid, context=None):
"""
Create procurement of virtual stock < 0
@param self: The object pointer
@param cr: The current row, from the database cursor,
@param uid: The current user ID for security checks
@@ -191,14 +191,14 @@ class procurement_order(osv.osv):
'''
Create procurement based on Orderpoint
use_new_cursor: False or the dbname
@param self: The object pointer
@param cr: The current row, from the database cursor,
@param user_id: The current user ID for security checks
@param context: A standard dictionary for contextual values
@param param: False or the dbname
@return: Dictionary of values
"""
"""
'''
if not context:
context = {}
@@ -212,24 +212,81 @@ class procurement_order(osv.osv):
report = []
offset = 0
ids = [1]
newdate = datetime.today()
if automatic:
self.create_automatic_op(cr, uid, context=context)
while ids:
ids = orderpoint_obj.search(cr, uid, [], offset=offset, limit=100)
for op in orderpoint_obj.browse(cr, uid, ids):
# for op in orderpoint_obj.browse(cr, uid, ids, context=context):
# for pro_data in op.procurement_data_id:
# pro_qty.append(pro_data.product_qty)
# pro_qty.sort()
for op in orderpoint_obj.browse(cr, uid, ids, context=context):
pro_qty = {}
for pro_data in op.procurement_data_id:
pro_qty.update({pro_data.product_qty: pro_data.id })
procure_list = pro_qty.keys()
procure_list.sort()
procure_list.reverse()
if op.procurement_id.state != 'exception':
if op.procurement_id and op.procurement_id.purchase_id and op.procurement_id.purchase_id.state in ('draft', 'confirmed'):
continue
prods = location_obj._product_virtual_get(cr, uid,
op.location_id.id, [op.product_id.id],
{'uom': op.product_uom.id})[op.product_id.id]
prods = location_obj._product_virtual_get(cr, uid,
op.location_id.id, [op.product_id.id],
{'uom': op.product_uom.id})[op.product_id.id]
if prods < op.product_min_qty:
qty = max(op.product_min_qty, op.product_max_qty)-prods
def check_qty(procure_list, qty):
new_qty = 0.0
newdate = datetime.today()
for proc in procure_list:
if qty >= proc:
#generate ORDER
new_qty = qty - proc
reste = qty % op.qty_multiple
if reste > 0:
qty += op.qty_multiple - reste
newdate += relativedelta(
days = int(op.product_id.seller_delay))
if op.product_id.type not in ('consu'):
proc_id = procurement_obj.create(cr, uid, {
'name': op.name,
'date_planned': newdate.strftime('%Y-%m-%d'),
'product_id': op.product_id.id,
'product_qty': new_qty,
'product_uom': op.product_uom.id,
'location_id': op.location_id.id,
'procure_method': 'make_to_order',
'origin': op.name
})
# wf_service.trg_validate(uid, 'procurement.order', proc_id,
# 'button_confirm', cr)
# wf_service.trg_validate(uid, 'procurement.order', proc_id,
# 'button_check', cr)
orderpoint_obj.write(cr, uid, [op.id],
{'procurement_id': proc_id}, context=context)
wf_service.trg_validate(uid, 'procurement.order', pro_qty[proc],
'button_confirm', cr)
else:
print 'GENERATE NEW ORDER'
return new_qty
while qty!=0:
qty = check_qty(procure_list, qty)
reste = qty % op.qty_multiple
if reste > 0:
qty += op.qty_multiple - reste
newdate = datetime.today() + relativedelta(
days = int(op.product_id.seller_delay))
newdate = datetime.today() + relativedelta(
days = int(op.product_id.seller_delay))
if qty <= 0:
continue
if op.product_id.type not in ('consu'):
@@ -248,7 +305,8 @@ class procurement_order(osv.osv):
wf_service.trg_validate(uid, 'procurement.order', proc_id,
'button_check', cr)
orderpoint_obj.write(cr, uid, [op.id],
{'procurement_id': proc_id})
{'procurement_id': proc_id}, context=context)
offset += len(ids)
if use_new_cursor:
cr.commit()