1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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 tools.translate import _
29
class procurement_order(osv.osv):
30
_name = 'procurement.order'
31
_inherit = 'procurement.order'
33
def run_threshold_value(self, cr, uid, use_new_cursor=False, batch_id=False, context=None):
35
Creates procurement for products where real stock is under threshold value
42
cr = pooler.get_db(use_new_cursor).cursor()
44
request_obj = self.pool.get('res.request')
45
threshold_obj = self.pool.get('threshold.value')
46
proc_obj = self.pool.get('procurement.order')
48
threshold_ids = threshold_obj.search(cr, uid, [], context=context)
53
start_date = time.strftime('%Y-%m-%d %H:%M:%S')
55
wf_service = netsvc.LocalService("workflow")
57
for threshold in threshold_obj.browse(cr, uid, threshold_ids, context=context):
59
c.update({'location': threshold.location_id.id, 'compute_child': True})
60
line_ids = self.pool.get('threshold.value.line').search(cr, uid, [('threshold_value_id', '=', threshold.id)], context=c)
61
for line in self.pool.get('threshold.value.line').browse(cr, uid, line_ids, context=c):
62
if line.threshold_value >= line.product_id.virtual_available and line.product_qty > 0.00:
63
proc_id = proc_obj.create(cr, uid, {
64
'name': _('Threshold value: %s') % (threshold.name,),
65
'origin': threshold.name,
66
'date_planned': time.strftime('%Y-%m-%d %H:%M:%S'),
67
'product_id': line.product_id.id,
68
'product_qty': line.product_qty,
69
'product_uom': line.product_id.uom_id.id,
70
'location_id': threshold.location_id.id,
71
'procure_method': 'make_to_order',
73
wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
74
wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_check', cr)
76
created_proc.append(proc_id)
78
created_doc = '''################################
79
Created documents : \n'''
81
for proc in proc_obj.browse(cr, uid, created_proc):
82
if proc.state == 'exception':
83
report.append('PROC %d: from stock - %3.2f %-5s - %s' % \
84
(proc.id, proc.product_qty, proc.product_uom.name,
85
proc.product_id.name,))
87
elif proc.purchase_id:
88
created_doc += " * %s => %s \n" % (proc.name, proc.purchase_id.name)
90
end_date = time.strftime('%Y-%m-%d %H:%M:%S')
92
summary = '''Here is the procurement scheduling report for Threshold values
96
Total Procurements processed: %d
97
Procurements with exceptions: %d
98
\n %s \n Exceptions: \n'''% (start_date, end_date, len(created_proc), report_except, len(created_proc) > 0 and created_doc or '')
99
summary += '\n'.join(report)
101
self.pool.get('procurement.batch.cron').write(cr, uid, batch_id, {'last_run_on': time.strftime('%Y-%m-%d %H:%M:%S')})
102
old_request = request_obj.search(cr, uid, [('batch_id', '=', batch_id), ('name', '=', 'Procurement Processing Report (Threshold values).')])
103
request_obj.write(cr, uid, old_request, {'batch_id': False})
104
req_id = request_obj.create(cr, uid,
105
{'name': "Procurement Processing Report (Threshold values).",
108
'batch_id': batch_id,
111
# UF-952 : Requests should be in consistent state
113
# request_obj.request_send(cr, uid, [req_id])
123
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: