[MERGE] procurement: refactoring of OP procurement creation via scheduler, courtesy of Guewen Baconnier (Camptocamp)

bzr revid: odo@openerp.com-20111223152343-ff33fimz31lz3csc
This commit is contained in:
Olivier Dony 2011-12-23 16:23:43 +01:00
commit b174c95716
1 changed files with 35 additions and 25 deletions

View File

@ -24,6 +24,7 @@ from datetime import datetime
from dateutil.relativedelta import relativedelta
from osv import osv
from tools.translate import _
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
import tools
import netsvc
import pooler
@ -146,6 +147,17 @@ class procurement_order(osv.osv):
pass
return {}
def _prepare_automatic_op_procurement(self, cr, uid, product, warehouse, location_id, context=None):
return {'name': _('Automatic OP: %s') % (product.name,),
'origin': _('SCHEDULER'),
'date_planned': datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'product_id': product.id,
'product_qty': -product.virtual_available,
'product_uom': product.uom_id.id,
'location_id': location_id,
'company_id': warehouse.company_id.id,
'procure_method': 'make_to_order',}
def create_automatic_op(self, cr, uid, context=None):
"""
Create procurement of virtual stock < 0
@ -172,26 +184,34 @@ class procurement_order(osv.osv):
if product.virtual_available >= 0.0:
continue
newdate = datetime.today()
if product.supply_method == 'buy':
location_id = warehouse.lot_input_id.id
elif product.supply_method == 'produce':
location_id = warehouse.lot_stock_id.id
else:
continue
proc_id = proc_obj.create(cr, uid, {
'name': _('Automatic OP: %s') % (product.name,),
'origin': _('SCHEDULER'),
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
'product_id': product.id,
'product_qty': -product.virtual_available,
'product_uom': product.uom_id.id,
'location_id': location_id,
'company_id': warehouse.company_id.id,
'procure_method': 'make_to_order',
})
proc_id = proc_obj.create(cr, uid,
self._prepare_automatic_op_procurement(cr, uid, product, warehouse, location_id, context=context),
context=context)
wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_check', cr)
return True
def _get_orderpoint_date_planned(self, cr, uid, orderpoint, start_date, context=None):
date_planned = start_date + \
relativedelta(days=orderpoint.product_id.seller_delay or 0.0)
return date_planned.strftime(DEFAULT_SERVER_DATE_FORMAT)
def _prepare_orderpoint_procurement(self, cr, uid, orderpoint, product_qty, context=None):
return {'name': orderpoint.name,
'date_planned': self._get_orderpoint_date_planned(cr, uid, orderpoint, datetime.today(), context=context),
'product_id': orderpoint.product_id.id,
'product_qty': product_qty,
'company_id': orderpoint.company_id.id,
'product_uom': orderpoint.product_uom.id,
'location_id': orderpoint.location_id.id,
'procure_method': 'make_to_order',
'origin': orderpoint.name}
def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\
use_new_cursor=False, context=None, user_id=False):
@ -238,8 +258,6 @@ class procurement_order(osv.osv):
if reste > 0:
qty += op.qty_multiple - reste
newdate = datetime.today() + relativedelta(
days = int(op.product_id.seller_delay))
if qty <= 0:
continue
if op.product_id.type not in ('consu'):
@ -258,17 +276,9 @@ class procurement_order(osv.osv):
qty = to_generate
if qty:
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': qty,
'company_id': op.company_id.id,
'product_uom': op.product_uom.id,
'location_id': op.location_id.id,
'procure_method': 'make_to_order',
'origin': op.name
})
proc_id = procurement_obj.create(cr, uid,
self._prepare_orderpoint_procurement(cr, uid, op, qty, context=context),
context=context)
wf_service.trg_validate(uid, 'procurement.order', proc_id,
'button_confirm', cr)
wf_service.trg_validate(uid, 'procurement.order', proc_id,