diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index dcb1287fd3b..a5315ab3a52 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -153,6 +153,11 @@ class crm_lead(format_address, osv.osv):
return result, fold
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+ if view_type == 'form' and context and context.get('opportunity_id'):
+ # TODO: replace by get_formview_action call
+ lead_type = self.browse(cr, user, context['opportunity_id'], context=context).type
+ view_lead_xml_id = 'crm_case_form_view_oppor' if lead_type == 'opportunity' else 'crm_case_form_view_leads'
+ _, view_id = self.pool['ir.model.data'].get_object_reference(cr, user, 'crm', view_lead_xml_id)
res = super(crm_lead, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
res['arch'] = self.fields_view_get_address(cr, user, res['arch'], context=context)
diff --git a/addons/crm/crm_phonecall_view.xml b/addons/crm/crm_phonecall_view.xml
index b71eee4220b..176572b9f8c 100644
--- a/addons/crm/crm_phonecall_view.xml
+++ b/addons/crm/crm_phonecall_view.xml
@@ -99,7 +99,7 @@
domain="[('object_id.model', '=', 'crm.phonecall')]"/>
-
+
diff --git a/addons/portal_sale/portal_sale_view.xml b/addons/portal_sale/portal_sale_view.xml
index 772e01af100..020286a5702 100644
--- a/addons/portal_sale/portal_sale_view.xml
+++ b/addons/portal_sale/portal_sale_view.xml
@@ -64,7 +64,6 @@
account.invoice
tree,form
[('type','in',['out_invoice','out_refund'])]
- {'type':['out_invoice','out_refund'], 'journal_type': 'sale'}
We haven't sent you any invoice.
diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py
index dd2a996f6dd..12f42a4c2e2 100644
--- a/addons/stock/__openerp__.py
+++ b/addons/stock/__openerp__.py
@@ -95,6 +95,7 @@ Dashboard / Reports for Warehouse Management will include:
'test/opening_stock.yml',
'test/shipment.yml',
'test/stock_report.yml',
+ 'test/setlast_tracking.yml',
],
'installable': True,
'application': True,
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 5492b60158d..cf8bcefe050 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1290,11 +1290,12 @@ class stock_picking(osv.osv):
product_avail[product.id] += qty
-
+ # every line of the picking is empty, do not generate anything
+ empty_picking = not any(q for q in move_product_qty.values() if q > 0)
for move in too_few:
product_qty = move_product_qty[move.id]
- if not new_picking:
+ if not new_picking and not empty_picking:
new_picking_name = pick.name
self.write(cr, uid, [pick.id],
{'name': sequence_obj.get(cr, uid,
@@ -1360,6 +1361,8 @@ class stock_picking(osv.osv):
workflow.trg_write(uid, 'stock.picking', pick.id, cr)
delivered_pack_id = new_picking
self.message_post(cr, uid, new_picking, body=_("Back order %s has been created.") % (pick.name), context=context)
+ elif empty_picking:
+ delivered_pack_id = pick.id
else:
self.action_move(cr, uid, [pick.id], context=context)
self.signal_button_done(cr, uid, [pick.id])
@@ -2198,16 +2201,24 @@ class stock_move(osv.osv):
return count
def setlast_tracking(self, cr, uid, ids, context=None):
- tracking_obj = self.pool.get('stock.tracking')
- picking = self.browse(cr, uid, ids, context=context)[0].picking_id
- if picking:
- last_track = [line.tracking_id.id for line in picking.move_lines if line.tracking_id]
- if not last_track:
- last_track = tracking_obj.create(cr, uid, {}, context=context)
+ assert len(ids) == 1, "1 ID expected, got %s" % (ids, )
+ tracking_obj = self.pool['stock.tracking']
+ move = self.browse(cr, uid, ids[0], context=context)
+ picking_id = move.picking_id.id
+ if picking_id:
+ move_ids = self.search(cr, uid, [
+ ('picking_id', '=', picking_id),
+ ('tracking_id', '!=', False)
+ ], limit=1, order='tracking_id DESC', context=context)
+ if move_ids:
+ tracking_move = self.browse(cr, uid, move_ids[0],
+ context=context)
+ tracking_id = tracking_move.tracking_id.id
else:
- last_track.sort()
- last_track = last_track[-1]
- self.write(cr, uid, ids, {'tracking_id': last_track})
+ tracking_id = tracking_obj.create(cr, uid, {}, context=context)
+ self.write(cr, uid, move.id,
+ {'tracking_id': tracking_id},
+ context=context)
return True
#
diff --git a/addons/stock/test/setlast_tracking.yml b/addons/stock/test/setlast_tracking.yml
new file mode 100644
index 00000000000..eae25b05ec4
--- /dev/null
+++ b/addons/stock/test/setlast_tracking.yml
@@ -0,0 +1,44 @@
+-
+ In order to check if the last tracking is set on moves, I create a picking
+-
+ !record {model: stock.picking, id: shipment_tracking}:
+ type: out
+ location_dest_id: stock_location_output
+-
+ !record {model: stock.move, id: shipment_tracking_move1}:
+ picking_id: shipment_tracking
+ product_id: product_product_6
+ product_uom: product.product_uom_unit
+ product_qty: 10.0
+ location_id: location_monitor
+ location_dest_id: stock_location_output
+-
+ !record {model: stock.move, id: shipment_tracking_move2}:
+ picking_id: shipment_tracking
+ product_id: product_product_6
+ product_uom: product.product_uom_unit
+ product_qty: 10.0
+ location_id: location_monitor
+ location_dest_id: stock_location_output
+-
+ Then I call setlast_tracking on the moves and check if the tracking is correct
+-
+ !python {model: stock.move}: |
+ move_id = ref('shipment_tracking_move1')
+ move = self.browse(cr, uid, move_id)
+ assert not move.tracking_id, "Move1 must not have a tracking at this point"
+ tracking_ids = self.pool['stock.tracking'].search(cr, uid, [])
+ self.setlast_tracking(cr, uid, [move_id])
+ move.refresh()
+ tracking_id = move.tracking_id.id
+ assert tracking_id, "The move must have a tracking_id"
+ assert tracking_id not in tracking_ids, "The tracking must be a new one"
+
+ move2_id = ref('shipment_tracking_move2')
+ move2 = self.browse(cr, uid, move2_id)
+ assert not move2.tracking_id, "Move2 must not have a tracking at this point"
+ self.setlast_tracking(cr, uid, [move2_id])
+ move2.refresh()
+ tracking2_id = move2.tracking_id.id
+ assert tracking2_id, "Move2 must have a tracking_id"
+ assert tracking2_id == tracking_id, "The second move must have the same tracking than the previous one"