base,mrp: allow to run scheduler in ir.cron

bzr revid: ced-6103e462ba6458431e70d27d9d4fdda03fcf13b1
This commit is contained in:
ced 2007-07-26 08:32:34 +00:00
parent c6e01ad76c
commit 6507e6c29a
8 changed files with 131 additions and 37 deletions

View File

@ -4,7 +4,7 @@
"author" : "Tiny",
"website" : "http://tinyerp.com/module_mrp.html",
"category" : "Generic Modules/Production",
"depends" : ["stock", "hr", "purchase", "product"],
"depends" : ["stock", "hr", "purchase", "product", "base"],
"description": """
This is the base module to manage the manufacturing process in Tiny ERP.

View File

@ -895,6 +895,31 @@ class mrp_procurement(osv.osv):
for id in ids:
wf_service.trg_trigger(uid, 'mrp.procurement', id, cr)
return res
def run_scheduler(self, cr, uid, user_id=False, schedule_cycle=1.0, po_cycle=1.0, po_lead=1.0, security_lead=50.0, picking_lead=1.0, automatic=False, context=None):
if not context:
context={}
self.run_procure_confirm(cr, uid, schedule_cycle=schedule_cycle,\
po_cycle=po_cycle, po_lead=po_lead, security_lead=security_lead,\
picking_lead=picking_lead, user_id=user_id, context=context)
self.run_orderpoint_confirm(cr, uid, automatic=automatic, context=context)
def run_procure_confirm(self, cr, uid, user_id=False, schedule_cycle=1.0,\
po_cycle=1.0, po_lead=1.0, security_lead=50.0, picking_lead=1.0, \
context=None):
from wizard.schedulers import _procure_confirm
if not context:
context={}
_procure_confirm(self, cr.dbname, uid, schedule_cycle=schedule_cycle,\
po_cycle=po_cycle, po_lead=po_lead, security_lead=security_lead,\
picking_lead=picking_lead, user_id=user_id, context=context)
def run_orderpoint_confirm(self, cr, uid, automatic=False, context=None):
from wizard.schedulers import _procure_orderpoint_confirm
if not context:
context={}
_procure_orderpoint_confirm(self, cr.dbname, uid, automatic=automatic,\
context=context)
mrp_procurement()
#CHECKME: why the **** is this object defined here and not in stock???

View File

@ -31,6 +31,18 @@
<field name="number_increment">1</field>
</record>
<record model="ir.cron" id="ir_cron_scheduler_action" forcecreate="True">
<field name="name">Run mrp scheduler</field>
<field name="active" eval="False"/>
<field name="user_id" ref="base.user_admin"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'mrp.procurement'"/>
<field name="function" eval="'run_scheduler'"/>
<field name="args" eval="'(uid,)'"/>
</record>
</data>
</terp>

View File

@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
# Fabien Pinckaers <fp@tiny.Be>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import xmlrpclib
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/wizard')
wiz_id = sock.create('trunk', 3, 'admin', 'mrp.procurement.compute.all')
sock.execute('trunk', 3, 'admin', wiz_id, {'form': {'po_cycle': 1.0, 'po_lead': 1.0, 'user_id': 3, 'schedule_cycle': 1.0, 'picking_lead': 1.0, 'security_lead': 50.0, 'automatic': False}, 'ids': [], 'report_type': 'pdf', 'model': 'ir.ui.menu', 'id': False}, 'compute', {})

View File

@ -2,8 +2,6 @@
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id$
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
@ -33,9 +31,11 @@ from mx import DateTime
import netsvc
from osv import osv
def _procure_confirm(self, db_name, uid, data, context):
cr = pooler.get_db(db_name).cursor()
def _procure_confirm(self, db_name, uid, schedule_cycle=1.0, po_cycle=1.0, po_lead=1.0, security_lead=50.0, picking_lead=1.0, user_id=False, context=None):
if not context:
context={}
cr = pooler.get_db(db_name).cursor()
wf_service = netsvc.LocalService("workflow")
cr.execute('select id from mrp_procurement where state=%s order by date_planned', ('exception',))
@ -44,8 +44,8 @@ def _procure_confirm(self, db_name, uid, data, context):
wf_service.trg_validate(uid, 'mrp.procurement', id, 'button_restart', cr)
cr.commit()
po_time = (data['form']['po_cycle'] or 0.0) + (data['form']['po_lead'] or 0.0)
maxdate = DateTime.now() + DateTime.RelativeDateTime(days=(data['form']['schedule_cycle'] or 0.0) + (data['form']['security_lead'] or 0.0))
po_time = po_cycle + po_lead
maxdate = DateTime.now() + DateTime.RelativeDateTime(days=schedule_cycle + security_lead)
start_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss')
offset = 0
report = []
@ -78,7 +78,7 @@ def _procure_confirm(self, db_name, uid, data, context):
while len(ids):
ids = pooler.get_pool(cr.dbname).get('mrp.procurement').search(cr, uid, [('state','=','confirmed'),('procure_method','=','make_to_stock')], offset=offset)
for proc in pooler.get_pool(cr.dbname).get('mrp.procurement').browse(cr, uid, ids):
if (maxdate + DateTime.RelativeDateTime(days=data['form']['picking_lead'])).strftime('%Y-%m-%d') >= proc.date_planned:
if (maxdate + DateTime.RelativeDateTime(days=picking_lead)).strftime('%Y-%m-%d') >= proc.date_planned:
wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr)
cr.execute('select name,state from mrp_procurement where id=%d', (proc.id,))
name,state = cr.fetchone()
@ -91,7 +91,7 @@ def _procure_confirm(self, db_name, uid, data, context):
cr.commit()
offset += len(ids)
end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss')
if 'user_id' in data['form'] and data['form']['user_id']:
if user_id:
request = pooler.get_pool(cr.dbname).get('res.request')
summary = '''Here is the procurement scheduling report.
@ -107,15 +107,17 @@ Exceptions;
summary += '\n'.join(report)
request.create(cr, uid,
{'name' : "Procurement calculation report.",
'act_from' : data['form']['user_id'],
'act_to' : data['form']['user_id'],
'act_from' : user_id,
'act_to' : user_id,
'body': summary,
})
cr.commit()
cr.close()
return {}
def create_automatic_op(cr, uid, data, context):
def create_automatic_op(cr, uid, context=None):
if not context:
context={}
product_obj = pooler.get_pool(cr.dbname).get('product.product')
proc_obj = pooler.get_pool(cr.dbname).get('mrp.procurement')
warehouse_obj = pooler.get_pool(cr.dbname).get('stock.warehouse')
@ -155,13 +157,15 @@ def create_automatic_op(cr, uid, data, context):
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_check', cr)
def _procure_orderpoint_confirm(self, db_name, uid, data, context):
def _procure_orderpoint_confirm(self, db_name, uid, automatic=False, context=None):
if not context:
context={}
cr = pooler.get_db(db_name).cursor()
wf_service = netsvc.LocalService("workflow")
offset = 0
ids = [1]
if data['form']['automatic']:
create_automatic_op(cr, uid, data, context)
if automatic:
create_automatic_op(cr, uid, context=context)
while ids:
cr.execute('select id from stock_warehouse_orderpoint where active offset %d limit 100', (offset,))
ids = map(lambda x: x[0], cr.fetchall())

View File

@ -2,8 +2,6 @@
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id$
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
@ -34,27 +32,27 @@
import wizard
import threading
from schedulers import _procure_orderpoint_confirm
import pooler
parameter_form = '''<?xml version="1.0"?>
<form string="Parameters" colspan="4">
<separator string="Time (days)" colspan="4"/>
<field name="po_lead"/>
<field name="security_lead"/>
<field name="automatic" />
<separator string="Control" colspan="4"/>
<field name="user_id"/>
</form>'''
parameter_fields = {
'po_lead': {'string':'PO Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
'security_lead': {'string':'Security Days', 'type':'float', 'required':True, 'default': lambda *a: 5.0},
'automatic': {'string': 'Automatic orderpoint', 'type': 'boolean', 'help': 'If the stock of a product is under 0, it will act like an orderpoint', 'default': lambda *a: False},
'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid},
}
def _procure_calculation_orderpoint(self, db_name, uid, data, context):
db, pool = pooler.get_db_and_pool(db_name)
cr = db.cursor()
proc_obj = pool.get('mrp.procurement')
automatic = data['form']['automatic']
proc_obj.run_orderpoint_confirm(cr, uid, automatic=automatic, context=context)
return {}
def _procure_calculation(self, cr, uid, data, context):
threaded_calculation = threading.Thread(target=_procure_orderpoint_confirm, args=(self, cr.dbname, uid, data, context))
threaded_calculation = threading.Thread(target=_procure_calculation_orderpoint, args=(self, cr.dbname, uid, data, context))
threaded_calculation.start()
return {}

View File

@ -28,8 +28,8 @@
##############################################################################
import wizard
from schedulers import _procure_confirm
import threading
import pooler
parameter_form = '''<?xml version="1.0"?>
<form string="Parameters" colspan="4">
@ -52,10 +52,23 @@ parameter_fields = {
'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid},
}
def _procure_calculation_procure(self, db_name, uid, data, context):
db, pool = pooler.get_db_and_pool(db_name)
cr = db.cursor()
proc_obj = pool.get('mrp.procurement')
schedule_cycle = data['form']['schedule_cycle']
po_cycle = data['form']['po_cycle']
po_lead = data['form']['po_lead']
security_lead = data['form']['security_lead']
picking_lead = data['form']['picking_lead']
user_id = data['form']['user_id']
proc_obj.run_procure_confirm(cr, uid, user_id=user_id, schedule_cycle=schedule_cycle,\
po_cycle=po_cycle, po_lead=po_lead, security_lead=security_lead,\
picking_lead=picking_lead, context=context)
return {}
def _procure_calculation(self, cr, uid, data, context):
#CHECKME: I wonder if it would be a good idea to pass the cursor...
# in doubt, I didn't
threaded_calculation = threading.Thread(target=_procure_confirm, args=(self, cr.dbname, uid, data, context))
threaded_calculation = threading.Thread(target=_procure_calculation_procure, args=(self, cr.dbname, uid, data, context))
threaded_calculation.start()
return {}

View File

@ -2,8 +2,6 @@
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id$
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
@ -28,9 +26,8 @@
##############################################################################
import wizard
from schedulers import _procure_confirm
from schedulers import _procure_orderpoint_confirm
import threading
import pooler
parameter_form = '''<?xml version="1.0"?>
<form string="Scheduler Parameters" colspan="4">
@ -56,8 +53,19 @@ parameter_fields = {
}
def _procure_calculation_all(self, db_name, uid, data, context):
_procure_confirm(self, db_name, uid, data, context)
_procure_orderpoint_confirm(self, db_name, uid, data, context)
db, pool = pooler.get_db_and_pool(db_name)
cr = db.cursor()
proc_obj = pool.get('mrp.procurement')
schedule_cycle = data['form']['schedule_cycle']
po_cycle = data['form']['po_cycle']
po_lead = data['form']['po_lead']
security_lead = data['form']['security_lead']
picking_lead = data['form']['picking_lead']
user_id = data['form']['user_id']
automatic = data['form']['automatic']
proc_obj.run_scheduler(cr, uid, user_id=user_id, schedule_cycle=schedule_cycle,\
po_cycle=po_cycle, po_lead=po_lead, security_lead=security_lead,\
picking_lead=picking_lead, automatic=automatic, context=context)
return {}
def _procure_calculation(self, cr, uid, data, context):