[WIP] add route views and correct further in stock_location

bzr revid: jco@openerp.com-20130709120659-p13su939w0h95x21
This commit is contained in:
Josse Colpaert
2013-07-09 14:06:59 +02:00
parent 365d6a2796
commit 9bfe5c950c
4 changed files with 99 additions and 26 deletions
+3 -3
View File
@@ -150,9 +150,9 @@ class procurement_order(osv.osv):
def run(self, cr, uid, ids, context=None):
for procurement in self.browse(cr, uid, ids, context=context or {}):
if procurement.procure_method=='make_to_order':
rule = self._assign(cr, uid, procurement, context=context)
rule = self.pool.get("procurement.rule").browse(cr, uid, self._assign(cr, uid, procurement, context=context), context=context)
if rule:
self.write(cr, uid, [procurement.id], {'rule_id', rule.id}, context=context)
self.write(cr, uid, [procurement.id], {'rule_id': rule.id}, context=context)
procurement.refresh()
self._run(cr, uid, procurement, context=context or {})
result = True
@@ -170,7 +170,7 @@ class procurement_order(osv.osv):
def check(self, cr, uid, ids, context=None):
done = []
for procurement in self.browse(cr, uid, ids, context=context or {}):
result = self._check(cr, uid, procurement.id, context=context or {})
result = self._check(cr, uid, procurement, context=context or {})
if result:
self.write(cr, uid, [procurement.id], {'state': 'done'}, context=context)
done.append(procurement.id)
+3 -2
View File
@@ -66,6 +66,7 @@ class procurement_order(osv.osv):
'date': procurement.date_planned,
'product_qty': procurement.product_qty,
'product_uom': procurement.product_uom.id,
'product_uom_qty': procurement.product_qty,
'product_uos_qty': (procurement.product_uos and procurement.product_uos_qty)\
or procurement.product_qty,
'product_uos': (procurement.product_uos and procurement.product_uos.id)\
@@ -75,7 +76,7 @@ class procurement_order(osv.osv):
'location_id': procurement.rule_id.location_src_id.id,
'location_dest_id': procurement.rule_id.location_id.id,
'move_dest_id': procurement.move_dest_id and procurement.move_dest_id.id or False,
'cancel_cascade': procurement.rule_id and procurement.rule_id.cancel_cascade or False,
#'cancel_cascade': procurement.rule_id and procurement.rule_id.cancel_cascade or False,
'group_id': procurement.group_id and procurement.group_id.id or False,
}
@@ -88,7 +89,7 @@ class procurement_order(osv.osv):
move_obj = self.pool.get('stock.move')
move_dict = self._run_move_create(cr, uid, procurement, context=context)
move_id = move_obj.create(cr, uid, move_dict, context=context)
move_obj.button_confirm(cr,uid, [move_id], context=context)
move_obj.action_confirm(cr,uid, [move_id], context=context)
self.write(cr, uid, [procurement.id], {'move_id': move_id}, context=context)
return move_id
return super(procurement_order, self)._run(cr, uid, procurement, context)
+80 -21
View File
@@ -21,6 +21,8 @@
from openerp.osv import fields,osv
from datetime import *
from dateutil.relativedelta import relativedelta
from openerp.tools.translate import _
class stock_location_route(osv.osv):
_name = 'stock.location.route'
@@ -73,7 +75,7 @@ class stock_location_path(osv.osv):
}
def _apply(self, cr, uid, rule, move, context=None):
move_obj = self.pool.get('stock.move')
newdate = (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') + datetime.relativedelta(days=rule.delay or 0)).strftime('%Y-%m-%d')
newdate = (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') + relativedelta(days=rule.delay or 0)).strftime('%Y-%m-%d')
if rule.auto=='transparent':
self.write(cr, uid, [move.id], {
'date': newdate,
@@ -122,14 +124,69 @@ class procurement_rule(osv.osv):
'type_proc': 'move',
'invoice_state': 'none',
}
def _apply(self, cr, uid, rule, move, context=None):
"""
This will create a procurement order
"""
print "Will need to create procurement here"
#Do not forget to do super
#TODO Create procurement order
proc_obj = self.pool.get("procurement.order")
#move_obj = self.pool.get("stock.move")
procs = proc_obj.search(cr, uid, [('move_dest_id','=', move.id)], context=context)
if procs and procs[0]:
proc = procs[0]
origin = (proc.origin or proc.name or '').split(':')[0] +':'+rule.name
proc_id = proc_obj.create(cr, uid, {
'name': rule.name,
'origin': origin,
'note': _('Pulled procurement coming from original location %s, pull rule %s, via original Procurement %s (#%d)') % (proc.location_id.name, rule.name, proc.name, proc.id),
'company_id': rule.company_id and rule.company_id.id or False,
'date_planned': proc.date_planned,
'product_id': proc.product_id.id,
'product_qty': proc.product_qty,
'product_uom': proc.product_uom.id,
'product_uos_qty': (proc.product_uos and proc.product_uos_qty)\
or proc.product_qty,
'product_uos': (proc.product_uos and proc.product_uos.id)\
or proc.product_uom.id,
'location_id': rule.location_src_id.id,
'procure_method': rule.procure_method,
'move_id': move.id,
})
else:
proc_id = proc_obj.create(cr, uid, {
'name': rule.name,
'origin': 'From stock move',
'note': _('Pulled procurement coming from original location %s, pull rule %s, via rule %s (#%d)') % (rule.location_id.name, rule.name, rule.name, rule.id),
'company_id': move.company_id and move.company_id.id or False,
'date_planned': move.date,
'product_id': move.product_id.id,
'product_qty': move.product_qty,
'product_uom': move.product_uom.id,
'product_uos_qty': (move.product_uos and move.product_uos_qty)\
or move.product_qty,
'product_uos': (move.product_uos and move.product_uos.id)\
or move.product_uom.id,
'location_id': rule.location_src_id.id,
'procure_method': rule.procure_method,
'move_id': move.id,
})
proc_obj._assign(cr, uid, proc_obj.browse(cr, uid, proc_id, context=context), context=context)
class procurement_order(osv.osv):
_inherit = 'procurement.order'
def _run_move_create(self, cr, uid, procurement, move, context=None):
d = super(procurement_order, self)._run_move_create(cr, uid, procurement, move, context=context)
newdate = (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') - datetime.relativedelta(days=procurement.rule_id.delay or 0)).strftime('%Y-%m-%d %H:%M:%S')
def _run_move_create(self, cr, uid, procurement, context=None):
d = super(procurement_order, self)._run_move_create(cr, uid, procurement, context=context)
if procurement.move_dest_id:
date = procurement.move_dest_id.date
else:
date = procurement.date_planned
newdate = (datetime.strptime(date, '%Y-%m-%d %H:%M:%S') - relativedelta(days=procurement.rule_id.delay or 0)).strftime('%Y-%m-%d %H:%M:%S')
d.update({
'date_planned': newdate,
'procure_method': procurement.rule_id.procure_method,
@@ -144,10 +201,9 @@ class procurement_order(osv.osv):
res = rule_obj.search(cr, uid, [('location_id','=',procurement.location_id.id),('route_id', 'in', route_ids)], context=context)
if not res:
return False
return res[1]
return res[0]
return super(procurement_order, self)._assign(cr, uid, procurement, context=context)
class product_putaway_strategy(osv.osv):
_name = 'product.putaway'
_description = 'Put Away Strategy'
@@ -198,22 +254,25 @@ class stock_move(osv.osv):
_inherit = 'stock.move'
_columns = {
'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too'),
'putaway_ids': fields.one2many('stock.move.putaway', 'move_id', 'Put Away Suggestions')
'putaway_ids': fields.one2many('stock.move.putaway', 'move_id', 'Put Away Suggestions'),
'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')],
'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
}
# TODO: reimplement this
def _pull_apply(self, cr, uid, moves, context):
# Create a procurement is MTO on stock.move
# Call _assign on procurement
#for move in moves:
# for route in move.product_id.route_ids:
# found = False
# for rule in route.pull_ids:
# if rule.location_id.id == move.location_id.id:
# self.pool.get('procurement.rule')._apply(cr, uid, rule, move, context=context)
# found = True
# break
# if found: break
for move in moves:
#If move is MTO, then you should create a procurement
#Search for original procurement
for route in move.product_id.route_ids:
found = False
for rule in route.pull_ids:
if rule.location_id.id == move.location_id.id and rule.procure_method == "make_to_order":
self.pool.get('procurement.rule')._apply(cr, uid, rule, move, context=context)
found = True
break
if found: break
return True
def _push_apply(self, cr, uid, moves, context):
@@ -243,9 +302,9 @@ class stock_move(osv.osv):
def action_confirm(self, cr, uid, ids, context=None):
result = super(stock_move, self).action_confirm(cr, uid, ids, context)
#moves = self.browse(cr, uid, ids, context=context)
self._pull_apply(cr, uid, ids, context=context)
self._push_apply(cr, uid, ids, context=context)
moves = self.browse(cr, uid, ids, context=context)
self._pull_apply(cr, uid, moves, context=context)
self._push_apply(cr, uid, moves, context=context)
return result
class stock_location(osv.osv):
@@ -269,7 +328,7 @@ class stock_location(osv.osv):
result = pr.search(cr,uid, [
('location_id', '=', location.id),
('category_ids', 'in', categs)
('product_categ_id', 'in', categs)
], context=context)
if result:
return pr.browse(cr, uid, result[0], context=context)
@@ -46,6 +46,7 @@
</field>
</record>
<record id="product_category_form_view_inherit" model="ir.ui.view">
<field name="name">product.category.form</field>
@@ -61,5 +62,17 @@
</field>
</record>
<record id="stock_location_route_form_view" model="ir.ui.view">
<field name="name">stock.location.route.form</field>
<field name="model">stock.location.route</field>
<field eval="7" name="priority"/>
<field name="arch" type="xml">
<form string="Route">
<field name="name"/>
<field name="pull_ids"/>
<field name="push_ids"/>
</form>
</field>
</record>
</data>
</openerp>