diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py
index 5a641dc32fc..e05a9746fe0 100644
--- a/addons/mrp/mrp.py
+++ b/addons/mrp/mrp.py
@@ -880,85 +880,6 @@ class mrp_production(osv.osv):
def _get_auto_picking(self, cr, uid, production):
return True
- def _make_production_line_procurement(self, cr, uid, production_line, shipment_move_id, context=None):
- procurement_order = self.pool.get('procurement.order')
- production = production_line.production_id
- location_id = production.location_src_id.id
- date_planned = production.date_planned
- procurement_name = (production.origin or '').split(':')[0] + ':' + production.name
- procurement_id = procurement_order.create(cr, uid, {
- 'name': procurement_name,
- 'origin': procurement_name,
- 'date_planned': date_planned,
- 'product_id': production_line.product_id.id,
- 'product_qty': production_line.product_qty,
- 'product_uom': production_line.product_uom.id,
- 'product_uos_qty': production_line.product_uos and production_line.product_qty or False,
- 'product_uos': production_line.product_uos and production_line.product_uos.id or False,
- 'location_id': location_id,
- 'move_id': shipment_move_id,
- 'company_id': production.company_id.id,
- })
- self.signal_button_confirm(cr, uid, [procurement_id])
- return procurement_id
-
- def _make_production_internal_shipment_line(self, cr, uid, production_line, group_id, parent_move_id, destination_location_id=False, context=None):
- stock_move = self.pool.get('stock.move')
- production = production_line.production_id
- date_planned = production.date_planned
- # Internal shipment is created for Stockable and Consumer Products
- if production_line.product_id.type not in ('product', 'consu'):
- return False
- source_location_id = production.location_src_id.id
- if not destination_location_id:
- destination_location_id = source_location_id
- return stock_move.create(cr, uid, {
- 'name': production.name,
- 'group_id': group_id,
- 'product_id': production_line.product_id.id,
- 'product_qty': production_line.product_qty,
- 'product_uom': production_line.product_uom.id,
- 'product_uom_qty': production.product_qty,
- 'product_uos_qty': production_line.product_uos and production_line.product_uos_qty or False,
- 'product_uos': production_line.product_uos and production_line.product_uos.id or False,
- 'date': date_planned,
- 'move_dest_id': parent_move_id,
- 'location_id': source_location_id,
- 'location_dest_id': destination_location_id,
- 'state': 'waiting',
- 'company_id': production.company_id.id,
- })
-
-# def _make_production_internal_shipment(self, cr, uid, production, context=None):
-# ir_sequence = self.pool.get('ir.sequence')
-# stock_picking = self.pool.get('stock.picking')
-# routing_loc = None
-# pick_type = 'internal'
-# partner_id = False
-#
-# # Take routing address as a Shipment Address.
-# # If usage of routing location is a internal, make outgoing shipment otherwise internal shipment
-# if production.bom_id.routing_id and production.bom_id.routing_id.location_id:
-# routing_loc = production.bom_id.routing_id.location_id
-# if routing_loc.usage != 'internal':
-# pick_type = 'out'
-# partner_id = routing_loc.partner_id and routing_loc.partner_id.id or False
-#
-# # Take next Sequence number of shipment base on type
-# pick_name = ir_sequence.get(cr, uid, 'stock.picking.' + pick_type)
-#
-# picking_id = stock_picking.create(cr, uid, {
-# 'name': pick_name,
-# 'origin': (production.origin or '').split(':')[0] + ':' + production.name,
-# 'type': pick_type,
-# 'move_type': 'one',
-# 'state': 'auto',
-# 'partner_id': partner_id,
-# 'auto_picking': self._get_auto_picking(cr, uid, production),
-# 'company_id': production.company_id.id,
-# })
-# production.write({'picking_id': picking_id}, context=context)
-# return picking_id
def _make_production_produce_line(self, cr, uid, production, context=None):
stock_move = self.pool.get('stock.move')
@@ -1006,6 +927,7 @@ class mrp_production(osv.osv):
'move_dest_id': parent_move_id,
'state': 'waiting',
'company_id': production.company_id.id,
+ 'procure_method': 'make_to_order',
})
production.write({'move_lines': [(4, move_id)]}, context=context)
return move_id
@@ -1017,22 +939,17 @@ class mrp_production(osv.osv):
uncompute_ids = filter(lambda x:x, [not x.product_lines and x.id or False for x in self.browse(cr, uid, ids, context=context)])
self.action_compute(cr, uid, uncompute_ids, context=context)
for production in self.browse(cr, uid, ids, context=context):
- group_id = self.pool.get("procurement.group").create(cr, uid, {'name': production.name}, context=context)
- #shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)
produce_move_id = self._make_production_produce_line(cr, uid, production, context=context)
# Take routing location as a Source Location.
source_location_id = production.location_src_id.id
if production.bom_id.routing_id and production.bom_id.routing_id.location_id:
source_location_id = production.bom_id.routing_id.location_id.id
-
+
for line in production.product_lines:
- consume_move_id = self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context)
- shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, group_id, consume_move_id,\
- destination_location_id=source_location_id, context=context)
- self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context)
+ self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context)
production.write({'state':'confirmed'}, context=context)
- return group_id
+ return 0
def force_production(self, cr, uid, ids, *args):
""" Assigns products.
diff --git a/addons/purchase/purchase_data.xml b/addons/purchase/purchase_data.xml
index afd9560e350..621597ec522 100644
--- a/addons/purchase/purchase_data.xml
+++ b/addons/purchase/purchase_data.xml
@@ -66,5 +66,14 @@
purchase.order
+
+
+ Supplier > Output
+ buy
+
+
+ make_to_order
+
+
diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py
index f5557b21e00..389061ea7ab 100644
--- a/addons/stock/procurement.py
+++ b/addons/stock/procurement.py
@@ -81,6 +81,7 @@ class procurement_order(osv.osv):
'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,
'group_id': procurement.group_id and procurement.group_id.id or False,
+ 'picking_type': self.pool.get('stock.move').get_type_from_usage(cr, uid, procurement.rule_id.location_src_id, procurement.rule_id.location_id, context=context)
}
def _run(self, cr, uid, procurement, context=None):
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index c49fc6c978b..82fd668245c 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1949,6 +1949,17 @@ class stock_move(osv.osv):
return [move.id for move in complete]
+
+ def get_type_from_usage(self, cr, uid, location, location_dest, context=None):
+ '''
+ Returns the type to be chosen based on the usages of the locations
+ '''
+ if location.usage == 'internal' and location_dest.usage in ['supplier', 'customer']:
+ return 'out'
+ if location.usage in ['supplier', 'customer'] and location_dest.usage == 'internal' :
+ return 'in'
+ return 'internal'
+
class stock_inventory(osv.osv):
_name = "stock.inventory"
_description = "Inventory"
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index d5be55c9756..9e7e45a88f3 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -1569,7 +1569,7 @@
product.template.procurement
- product.template
+ product.product
diff --git a/addons/stock_location/__openerp__.py b/addons/stock_location/__openerp__.py
index ca1ebc30b0c..f65de1fbe3b 100644
--- a/addons/stock_location/__openerp__.py
+++ b/addons/stock_location/__openerp__.py
@@ -96,7 +96,10 @@ You can use the demo data as follow:
'author': 'OpenERP SA',
'images': ['images/pulled_flow.jpeg','images/pushed_flow.jpeg'],
'depends': ['procurement','stock'],
- 'data': ['stock_location_view.xml', 'security/stock_location_security.xml', 'security/ir.model.access.csv'],
+ 'data': ['stock_location_view.xml',
+ 'stock_location_data.xml',
+ 'security/stock_location_security.xml',
+ 'security/ir.model.access.csv'],
'demo': [
'stock_location_demo_cpu1.xml',
'stock_location_demo_cpu3.yml',
diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py
index a2ac62679f3..3cc057dc77d 100644
--- a/addons/stock_location/stock_location.py
+++ b/addons/stock_location/stock_location.py
@@ -72,12 +72,13 @@ class stock_location_path(osv.osv):
'delay': 1,
'invoice_state': 'none',
'picking_type': 'internal',
+ 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c)
}
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') + relativedelta(days=rule.delay or 0)).strftime('%Y-%m-%d')
if rule.auto=='transparent':
- self.write(cr, uid, [move.id], {
+ move_obj.write(cr, uid, [move.id], {
'date': newdate,
'location_dest_id': rule.location_dest_id.id
})
@@ -93,14 +94,16 @@ class stock_location_path(osv.osv):
move_id = move_obj.copy(cr, uid, move.id, {
'location_id': move.location_dest_id.id,
'location_dest_id': rule.location_dest_id.id,
- 'date': time.strftime('%Y-%m-%d'),
- 'company_id': rule.company_id.id,
+ 'date': datetime.now().strftime('%Y-%m-%d'),
+ 'company_id': rule.company_id and rule.company_id.id or False,
'date_expected': newdate,
+ 'picking_id': False,
+ 'picking_type': move_obj.get_type_from_usage(cr, uid, move.location_id, move.location_dest_id, context=context)
})
move_obj.write(cr, uid, [move.id], {
'move_dest_id': move_id,
})
- move_obj.action_confirm(self, cr, uid, [move_id], context=None)
+ move_obj.action_confirm(cr, uid, [move_id], context=None)
return move_id
@@ -206,25 +209,6 @@ class stock_move(osv.osv):
'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'),
}
-
-
- # 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:
-# #If move is MTO, then you should create a procurement
-# #Search for original rule
-# #Then change procurement to stock
-# for route in move.product_id.route_ids:
-# found = False
-# for rule in route.pull_ids:
-# if rule.location_id.id == move.location_dest_id.id and move.procure_method == "make_to_order":
-# self._create_procurement(cr, uid, rule, move, context=context)
-# found = True
-# break
-# if found: break
-# return True
def _push_apply(self, cr, uid, moves, context):
for move in moves:
@@ -241,10 +225,9 @@ class stock_move(osv.osv):
# Create the stock.move.putaway records
def _putaway_apply(self,cr, uid, ids, context=None):
for move in self.browse(cr, uid, ids, context=context):
- res = self.pool.get('stock.location').get_putaway_strategy(cr, uid, move.location_dest_id.id, move.product_id.id, context=context)
+ res = self.pool.get('stock.location').get_putaway_strategy(cr, uid, move.location_dest_id, move.product_id, context=context)
if res:
raise 'put away strategies not implemented yet!'
-
return True
def action_assign(self, cr, uid, ids, context=None):
@@ -266,7 +249,7 @@ class stock_location(osv.osv):
}
- def get_putaway_strategy(self, cr, uid, id, location, product, context=None):
+ def get_putaway_strategy(self, cr, uid, location, product, context=None):
pa = self.pool.get('product.putaway')
categ = product.categ_id
categs = [categ.id, False]
@@ -280,7 +263,7 @@ class stock_location(osv.osv):
], context=context)
if result:
return pa.browse(cr, uid, result[0], context=context)
- return super(stock_location, self).get_putaway_strategy(cr, uid, location, product, context=context)
+ #return super(stock_location, self).get_putaway_strategy(cr, uid, location, product, context=context)
def get_removal_strategy(self, cr, uid, location, product, context=None):
pr = self.pool.get('product.removal')
diff --git a/addons/stock_location/stock_location_view.xml b/addons/stock_location/stock_location_view.xml
index 978c69e1238..5b993683f85 100644
--- a/addons/stock_location/stock_location_view.xml
+++ b/addons/stock_location/stock_location_view.xml
@@ -66,8 +66,8 @@
stock.location.route
-
-
+
+
@@ -79,7 +79,7 @@