diff --git a/addons/mrp/__init__.py b/addons/mrp/__init__.py
index 1f42fa8786f..0cca0e4c805 100644
--- a/addons/mrp/__init__.py
+++ b/addons/mrp/__init__.py
@@ -31,6 +31,5 @@
import mrp
import wizard
import report
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
+import company
+import schedulers
diff --git a/addons/mrp/__terp__.py b/addons/mrp/__terp__.py
index f3fe4989e05..0a5220eddaf 100644
--- a/addons/mrp/__terp__.py
+++ b/addons/mrp/__terp__.py
@@ -69,6 +69,7 @@
"mrp_view.xml",
"mrp_wizard.xml",
"mrp_report.xml",
+ "company_view.xml"
],
"active": False,
"installable": True
diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py
index e9877ce1349..e6365079726 100644
--- a/addons/mrp/mrp.py
+++ b/addons/mrp/mrp.py
@@ -868,10 +868,12 @@ class mrp_procurement(osv.osv):
def action_produce_assign_product(self, cr, uid, ids, context={}):
produce_id = False
+ company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
for procurement in self.browse(cr, uid, ids):
res_id = procurement.move_id.id
loc_id = procurement.location_id.id
newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.produce_delay or 0.0)
+ newdate = newdate - DateTime.RelativeDateTime(days=company.manufacturing_lead)
produce_id = self.pool.get('mrp.production').create(cr, uid, {
'origin': procurement.origin,
'product_id': procurement.product_id.id,
@@ -892,8 +894,9 @@ class mrp_procurement(osv.osv):
wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
return produce_id
- def action_po_assign(self, cr, uid, ids):
+ def action_po_assign(self, cr, uid, ids, context={}):
purchase_id = False
+ company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
for procurement in self.browse(cr, uid, ids):
res_id = procurement.move_id.id
partner = procurement.product_id.seller_ids[0].name
@@ -910,6 +913,7 @@ class mrp_procurement(osv.osv):
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, False, {'uom': uom_id})[pricelist_id]
newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.seller_delay or 0.0)
+ newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead)
line = {
'name': procurement.product_id.name,
'product_qty': qty,
@@ -969,45 +973,15 @@ 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, use_new_cursor=False, context=None):
+ def run_scheduler(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
'''
use_new_cursor: False or the dbname
'''
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,\
+ self._procure_confirm(cr, uid, use_new_cursor=use_new_cursor, context=context)
+ self._procure_orderpoint_confirm(cr, uid, automatic=automatic,\
use_new_cursor=use_new_cursor, context=context)
- self.run_orderpoint_confirm(cr, uid, automatic=automatic,\
- use_new_cursor=use_new_cursor, context=context, user_id=user_id)
-
- 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, \
- use_new_cursor=False, context=None):
- '''
- use_new_cursor: False or the dbname
- '''
- from wizard.schedulers import _procure_confirm
- if not context:
- context={}
- _procure_confirm(self, 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, use_new_cursor=use_new_cursor,\
- context=context)
-
- def run_orderpoint_confirm(self, cr, uid, automatic=False, use_new_cursor=False,\
- context=None, user_id=False):
- '''
- use_new_cursor: False or the dbname
- '''
- from wizard.schedulers import _procure_orderpoint_confirm
- if not context:
- context={}
- _procure_orderpoint_confirm(self, cr, uid, automatic=automatic,\
- use_new_cursor=use_new_cursor, context=context, user_id=user_id)
mrp_procurement()
diff --git a/addons/mrp/mrp_wizard.xml b/addons/mrp/mrp_wizard.xml
index 14a162c9551..6e02dbc55e6 100644
--- a/addons/mrp/mrp_wizard.xml
+++ b/addons/mrp/mrp_wizard.xml
@@ -2,19 +2,19 @@
- Compute all schedulers
+ Compute All Schedulers
mrp.procurement.compute.all
- Compute procurement
+ Compute Procurements Only
mrp.procurement.compute
- Compute stock minimum rules
+ Compute Stock Minimum Rules Only
mrp.procurement.orderpoint.compute
@@ -31,4 +31,4 @@
-
\ No newline at end of file
+
diff --git a/addons/mrp/wizard/schedulers.py b/addons/mrp/wizard/schedulers.py
index 98ff98111ea..0f88cbc8c01 100644
--- a/addons/mrp/wizard/schedulers.py
+++ b/addons/mrp/wizard/schedulers.py
@@ -34,231 +34,5 @@ from mx import DateTime
import netsvc
from osv import osv
-def _procure_confirm(self, cr, uid, schedule_cycle=1.0, po_cycle=1.0,\
- po_lead=1.0, security_lead=50.0, picking_lead=1.0, user_id=False,\
- use_new_cursor=False, context=None):
- '''
- use_new_cursor: False or the dbname
- '''
- if not context:
- context={}
-
- if use_new_cursor:
- cr = pooler.get_db(use_new_cursor).cursor()
- wf_service = netsvc.LocalService("workflow")
-
- procurement_obj = pooler.get_pool(cr.dbname).get('mrp.procurement')
- ids=procurement_obj.search(cr,uid,[], order="date_planned")
- for id in ids:
- wf_service.trg_validate(uid, 'mrp.procurement', id, 'button_restart', cr)
- if use_new_cursor:
- cr.commit()
-
- 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 = []
- report_total = 0
- report_except = 0
- report_later = 0
- ids = [1]
- while len(ids):
- cr.execute('select id from mrp_procurement where state=%s and procure_method=%s order by date_planned limit 500 offset %d', ('confirmed','make_to_order',offset))
- ids = map(lambda x:x[0], cr.fetchall())
- for proc in procurement_obj.browse(cr, uid, ids):
- if proc.product_id.supply_method=='produce':
- wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr)
- else:
- if (maxdate + DateTime.RelativeDateTime(days=(proc.product_id.seller_delay or 0 + po_time))).strftime('%Y-%m-%d')>=proc.date_planned:
- wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr)
- else:
- offset+=1
- report_later += 1
- for proc in procurement_obj.browse(cr, uid, ids):
- if proc.state == 'exception':
- report.append('PROC %d: on order - %3.2f %-5s - %s' % \
- (proc.id, proc.product_qty, proc.product_uom.name,
- proc.product_id.name))
- report_except += 1
- report_total += 1
- if use_new_cursor:
- cr.commit()
-
- offset = 0
- ids = [1]
- while len(ids):
- report_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 procurement_obj.browse(cr, uid, ids):
- 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)
- report_ids.append(proc.id)
- else:
- report_later +=1
- report_total +=1
- for proc in procurement_obj.browse(cr, uid, report_ids):
- if proc.state == 'exception':
- report.append('PROC %d: from stock - %3.2f %-5s - %s' % \
- (proc.id, proc.product_qty, proc.product_uom.name,
- proc.product_id.name,))
- report_except +=1
- if use_new_cursor:
- cr.commit()
- offset += len(ids)
- end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss')
- if user_id:
- request = pooler.get_pool(cr.dbname).get('res.request')
- summary = '''Here is the procurement scheduling report.
-
-Computation Started; %s
-Computation Finnished; %s
-
-Total procurement: %d
-Exception procurement: %d
-Not run now procurement: %d
-
-Exceptions;
-'''% (start_date,end_date,report_total, report_except,report_later)
- summary += '\n'.join(report)
- request.create(cr, uid,
- {'name' : "Procurement calculation report.",
- 'act_from' : user_id,
- 'act_to' : user_id,
- 'body': summary,
- })
- if use_new_cursor:
- cr.commit()
- cr.close()
- return {}
-
-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')
- wf_service = netsvc.LocalService("workflow")
-
- cr.execute('select id from stock_warehouse')
- warehouses = [x for x, in cr.fetchall()]
- cr.execute('select id from product_product')
- products_id = [x for x, in cr.fetchall()]
- products = dict(zip(products_id, product_obj.browse(cr, uid, products_id, context)))
- for warehouse in warehouses:
- v_stock = product_obj._product_virtual_available(cr, uid, products_id, None, {'warehouse': warehouse})
- cr.execute("select lot_stock_id from stock_warehouse")
- location_ids_str = ','.join([str(id) for id, in cr.fetchall()])
- stock_locations = warehouse_obj.read(cr, uid, [warehouse], ['lot_input_id', 'lot_stock_id'])[0]
- for prod_id, available in v_stock.items():
- if available >= 0:
- continue
- newdate = DateTime.now() + DateTime.RelativeDateTime(days=products[prod_id].seller_delay)
- if products[prod_id].supply_method == 'buy':
- location_id = stock_locations['lot_input_id'][0]
- elif products[prod_id].supply_method == 'produce':
- location_id = stock_locations['lot_stock_id'][0]
- else:
- continue
- proc_id = proc_obj.create(cr, uid, {
- 'name': 'PROC:Automatic OP for product:%s' % products[prod_id].name,
- 'origin': 'SCHEDULER',
- 'date_planned': newdate.strftime('%Y-%m-%d'),
- 'product_id': prod_id,
- 'product_qty': -available,
- 'product_uom': products[prod_id].uom_id.id,
- 'location_id': location_id,
- 'procure_method': 'make_to_order',
- })
- wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
- wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_check', cr)
-
-
-def _procure_orderpoint_confirm(self, cr, uid, automatic=False,\
- use_new_cursor=False, context=None, user_id=False):
- '''
- use_new_cursor: False or the dbname
- '''
- if not context:
- context={}
- if use_new_cursor:
- cr = pooler.get_db(use_new_cursor).cursor()
- pool = pooler.get_pool(cr.dbname)
- orderpoint_obj = pool.get('stock.warehouse.orderpoint')
- location_obj = pool.get('stock.location')
- procurement_obj = pool.get('mrp.procurement')
- request_obj = pool.get('res.request')
- wf_service = netsvc.LocalService("workflow")
- report = []
- offset = 0
- ids = [1]
- if automatic:
- 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):
- #if op.procurement_id and op.procurement_id.purchase_id:
- # if (op.procurement_id.purchase_id.state=='confirmed'):
- # #
- # # TODO: Should write a request with this warning
- # #
- # continue
- # elif op.procurement_id.purchase_id.state=='draft':
- # wf_service = netsvc.LocalService("workflow")
- # wf_service.trg_validate(uid, 'purchase.order',
- # op.procurement_id.purchase_id.id, 'purchase_cancel', cr)
- try:
- prods = location_obj._product_virtual_get(cr, uid,
- op.warehouse_id.lot_stock_id.id, [op.product_id.id],
- {'uom': op.product_uom.id})[op.product_id.id]
- if prods < op.product_min_qty:
- # order the quantity necessary to get to max(min_qty, max_qty)
- qty = max(op.product_min_qty, op.product_max_qty)-prods
- reste = qty % op.qty_multiple
- if reste>0:
- qty += op.qty_multiple-reste
- newdate = DateTime.now() + DateTime.RelativeDateTime(
- days=op.product_id.seller_delay)
- if op.product_id.supply_method == 'buy':
- location_id = op.warehouse_id.lot_input_id
- elif op.product_id.supply_method == 'produce':
- location_id = op.warehouse_id.lot_stock_id
- else:
- continue
- proc_id = procurement_obj.create(cr, uid, {
- 'name': 'OP:'+str(op.id),
- 'date_planned': newdate.strftime('%Y-%m-%d'),
- 'product_id': op.product_id.id,
- 'product_qty': qty,
- 'product_uom': op.product_uom.id,
- 'location_id': op.warehouse_id.lot_input_id.id,
- 'procure_method': 'make_to_order',
- 'origin': op.name
- })
- wf_service.trg_validate(uid, 'mrp.procurement', proc_id,
- 'button_confirm', cr)
- wf_service.trg_validate(uid, 'mrp.procurement', proc_id,
- 'button_check', cr)
- orderpoint_obj.write(cr, uid, [op.id],
- {'procurement_id': proc_id})
- except Exception, e:
- report.append('OP %d:\n%s\n' % (op.id, str(e)))
- offset += len(ids)
- if use_new_cursor:
- cr.commit()
- if user_id and report:
- request_obj.create(cr, uid, {
- 'name': 'Orderpoint report.',
- 'act_from': user_id,
- 'act_to': user_id,
- 'body': '\n'.join(report)
- })
- if use_new_cursor:
- cr.commit()
- cr.close()
- return {}
-
-
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mrp/wizard/wizard_orderpoint_procurement.py b/addons/mrp/wizard/wizard_orderpoint_procurement.py
index ef64c2c070b..956b5ed111c 100644
--- a/addons/mrp/wizard/wizard_orderpoint_procurement.py
+++ b/addons/mrp/wizard/wizard_orderpoint_procurement.py
@@ -51,8 +51,8 @@ def _procure_calculation_orderpoint(self, db_name, uid, data, context):
cr = db.cursor()
proc_obj = pool.get('mrp.procurement')
automatic = data['form']['automatic']
- proc_obj.run_orderpoint_confirm(cr, uid, automatic=automatic,\
- use_new_cursor=cr.dbname, context=context, user_id=uid)
+ proc_obj._procure_orderpoint_confirm(cr, uid, automatic=automatic,\
+ use_new_cursor=cr.dbname, context=context)
return {}
def _procure_calculation(self, cr, uid, data, context):
diff --git a/addons/mrp/wizard/wizard_procurement.py b/addons/mrp/wizard/wizard_procurement.py
index afa5795cdb8..09dde8071aa 100644
--- a/addons/mrp/wizard/wizard_procurement.py
+++ b/addons/mrp/wizard/wizard_procurement.py
@@ -34,38 +34,17 @@ import pooler
parameter_form = '''
'''
parameter_fields = {
- 'schedule_cycle': {'string':'Scheduler Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
- 'po_cycle': {'string':'PO Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
- '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},
- 'picking_lead': {'string':'Packing Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
- '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, use_new_cursor=cr.dbname, context=context)
+ proc_obj._procure_confirm(cr, uid, use_new_cursor=cr.dbname, context=context)
return {}
def _procure_calculation(self, cr, uid, data, context):
diff --git a/addons/mrp/wizard/wizard_schedulers_all.py b/addons/mrp/wizard/wizard_schedulers_all.py
index b9a909210c8..19b4a6168b3 100644
--- a/addons/mrp/wizard/wizard_schedulers_all.py
+++ b/addons/mrp/wizard/wizard_schedulers_all.py
@@ -34,41 +34,19 @@ import pooler
parameter_form = '''
'''
parameter_fields = {
- 'schedule_cycle': {'string':'Scheduler Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
- 'po_cycle': {'string':'PO Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
- '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: 50.0},
- 'picking_lead': {'string':'Packing Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0},
'automatic': {'string': 'Automatic orderpoint', 'type': 'boolean', 'help': 'Triggers an automatic procurement for all products that have a virtual stock under 0.', 'default': lambda *a: False},
- 'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid},
}
def _procure_calculation_all(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, use_new_cursor=cr.dbname,\
+ proc_obj.run_scheduler(cr, uid, automatic=automatic, use_new_cursor=cr.dbname,\
context=context)
return {}
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 232470f71d5..66991379b1a 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -165,7 +165,6 @@ class sale_order(osv.osv):
def _invoiced_search(self, cursor, user, obj, name, args):
if not len(args):
return []
-
clause = ''
no_invoiced = False
for arg in args:
@@ -175,7 +174,6 @@ class sale_order(osv.osv):
else:
clause += 'AND inv.state <> \'paid\''
no_invoiced = True
-
cursor.execute('SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel, account_invoice AS inv ' \
'WHERE rel.invoice_id = inv.id ' + clause)
@@ -474,12 +472,14 @@ class sale_order(osv.osv):
def action_ship_create(self, cr, uid, ids, *args):
picking_id=False
+ company = self.pool.get('res.users').browse(cr, uid, uid).company_id
for order in self.browse(cr, uid, ids, context={}):
output_id = order.shop_id.warehouse_id.lot_output_id.id
picking_id = False
for line in order.order_line:
proc_id=False
- date_planned = (DateTime.now() + DateTime.RelativeDateTime(days=line.delay or 0.0)).strftime('%Y-%m-%d')
+ date_planned = DateTime.now() + DateTime.RelativeDateTime(days=line.delay or 0.0)
+ date_planned = (date_planned - DateTime.RelativeDateTime(days=company.security_lead)).strftime('%Y-%m-%d')
if line.state == 'done':
continue
if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'):
diff --git a/addons/stock/wizard/wizard_partial_picking.py b/addons/stock/wizard/wizard_partial_picking.py
index e39981dd859..2984c5a084b 100644
--- a/addons/stock/wizard/wizard_partial_picking.py
+++ b/addons/stock/wizard/wizard_partial_picking.py
@@ -110,6 +110,7 @@ def _do_split(self, cr, uid, data, context):
new_moves = []
complete, too_many, too_few = [], [], []
+ pool = pooler.get_pool(cr.dbname)
for move in move_obj.browse(cr, uid, data['form'].get('moves',[])):
if move.product_qty == data['form']['move%s' % move.id]:
complete.append(move)
@@ -120,10 +121,10 @@ def _do_split(self, cr, uid, data, context):
# Average price computation
if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
- product_obj = pooler.get_pool(cr.dbname).get('product.product')
- currency_obj = pooler.get_pool(cr.dbname).get('res.currency')
- users_obj = pooler.get_pool(cr.dbname).get('res.users')
- uom_obj = pooler.get_pool(cr.dbname).get('product.uom')
+ product_obj = pool.get('product.product')
+ currency_obj = pool.get('res.currency')
+ users_obj = pool.get('res.users')
+ uom_obj = pool.get('product.uom')
product = product_obj.browse(cr, uid, [move.product_id.id])[0]
user = users_obj.browse(cr, uid, [uid])[0]
@@ -151,6 +152,7 @@ def _do_split(self, cr, uid, data, context):
if not new_picking:
new_picking = pick_obj.copy(cr, uid, pick.id,
{
+ 'name': pool.get('ir.sequence').get(cr, uid, 'stock.picking'),
'move_lines' : [],
'state':'draft',
})