33
33
_name = 'procurement.order'
34
34
_inherit = 'procurement.order'
36
def run_automatic_supply(self, cr, uid, use_new_cursor=False, batch_id=False, context=None):
36
def run_automatic_supply(self, cr, uid, use_new_cursor=False, context={}):
38
38
Create procurement on fixed date
45
45
proc_obj = self.pool.get('procurement.order')
46
46
freq_obj = self.pool.get('stock.frequence')
48
start_date = time.strftime('%Y-%m-%d %H:%M:%S')
49
auto_sup_ids = auto_sup_obj.search(cr, uid, [('next_date', '<=', datetime.now())])
48
start_date = datetime.now()
49
auto_sup_ids = auto_sup_obj.search(cr, uid, [('next_date', '<=', start_date.strftime('%Y-%m-%d'))])
65
65
location_id = auto_sup.location_id.id
67
for line in auto_sup.line_ids:
68
proc_id = self.create_proc_order(cr, uid, auto_sup, line.product_id,
69
line.product_uom_id.id, line.product_qty,
70
location_id, cache=cache, context=context)
67
if auto_sup.product_id:
68
proc_id = self.create_proc_order(cr, uid, auto_sup, auto_sup.product_id, auto_sup.product_uom_id.id,
69
auto_sup.product_qty, location_id, cache=cache, context=context)
72
71
created_proc.append(proc_id)
74
for line in auto_sup.line_ids:
75
proc_id = self.create_proc_order(cr, uid, auto_sup, line.product_id,
76
line.product_uom_id.id, line.product_qty,
77
location_id, cache=cache, context=context)
79
created_proc.append(proc_id)
74
81
if auto_sup.frequence_id:
75
82
freq_obj.write(cr, uid, auto_sup.frequence_id.id, {'last_run': start_date.strftime('%Y-%m-%d')})
77
created_doc = '''################################
78
Created documents : \n'''
80
85
for proc in proc_obj.browse(cr, uid, created_proc):
81
86
if proc.state == 'exception':
83
88
(proc.id, proc.product_qty, proc.product_uom.name,
84
89
proc.product_id.name,))
86
elif proc.purchase_id:
87
created_doc += " * %s => %s \n" % (proc.name, proc.purchase_id.name)
89
end_date = time.strftime('%Y-%m-%d %H:%M:%S')
92
end_date = datetime.now()
91
94
summary = '''Here is the procurement scheduling report for Automatic Supplies
95
98
Total Procurements processed: %d
96
99
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 '')
100
\n'''% (start_date, end_date, len(created_proc), report_except)
100
101
summary += '\n'.join(report)
102
self.pool.get('procurement.batch.cron').write(cr, uid, batch_id, {'last_run_on': time.strftime('%Y-%m-%d %H:%M:%S')})
103
old_request = request_obj.search(cr, uid, [('batch_id', '=', batch_id), ('name', '=', 'Procurement Processing Report (Automatic supplies).')])
104
request_obj.write(cr, uid, old_request, {'batch_id': False})
105
102
req_id = request_obj.create(cr, uid,
106
{'name': "Procurement Processing Report (Automatic supplies).",
103
{'name': "Procurement Processing Report.",
109
'batch_id': batch_id,
112
# UF-952 : Requests should be in consistent state
114
# request_obj.request_send(cr, uid, [req_id])
109
request_obj.request_send(cr, uid, [req_id])
116
111
if use_new_cursor:
122
def create_proc_order(self, cr, uid, auto_sup, product_id, product_uom, qty, location_id, cache=None, context=None):
117
def create_proc_order(self, cr, uid, auto_sup, product_id, product_uom, qty, location_id, cache={}, context={}):
124
119
Creates a procurement order for a product and a location