From 933d098e7d321c5aca3680178b9cc3fdd8c12823 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 24 Sep 2014 14:34:14 +0200 Subject: [PATCH 1/4] [IMP] stock: do not generate empty backorders If every line of a partial delivery is at zero, do not generate empty backorders (opw 608680) --- addons/stock/stock.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 14d60c2b56e..4535b51dd8f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1297,11 +1297,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, @@ -1367,6 +1368,8 @@ class stock_picking(osv.osv): wf_service.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) wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_done', cr) From 126ba0a9a8a1aaaf959a1c2c0f235640e766a9de Mon Sep 17 00:00:00 2001 From: Ravi Gohil Date: Mon, 9 Jun 2014 14:58:30 +0530 Subject: [PATCH 2/4] [FIX] crm: correct open lead or opportunity view from calls When opening a lead/opportunity from the phonecalls view, we did not open the correct view (always the lead). This will use the type of the crm.lead to determine which view should be used, opw 608493. --- addons/crm/crm_lead.py | 5 +++++ addons/crm/crm_phonecall_view.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 6c4ef607c0d..b04eae9e31f 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -165,6 +165,11 @@ class crm_lead(base_stage, 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 21e18d8affc..4737065be6e 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -110,7 +110,7 @@ domain="[('object_id.model', '=', 'crm.phonecall')]"/> - + From b5c8ced8ecd7cf6a270565ee70d88ff6f53dcd54 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 16 Sep 2014 15:21:07 +0200 Subject: [PATCH 3/4] [IMP] stock: Optimize stock_move.setlast_tracking() When setlast_tracking is called on a large number of moves in a picking (e.g. when splitting moves in a picking), the time to complete grows exponentially. The reason is that it loops over all the moves of a picking, even if it keeps only the last tracking. The method now uses a search() with a limit so it doesn't need to browse all the moves. Added test to check the behaviour of setlast_tracking Fixes #2448 --- addons/stock/__openerp__.py | 1 + addons/stock/stock.py | 26 +++++++++------ addons/stock/test/setlast_tracking.yml | 44 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 addons/stock/test/setlast_tracking.yml 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 4535b51dd8f..f117bdbc27d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2214,16 +2214,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" From 1933e926ff7457b6f116296190ec55eb908de9b3 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 24 Sep 2014 17:00:24 +0200 Subject: [PATCH 4/4] [INP] portal_sale: remove buggy context Even if this should never be used in normal portal environment, if a user with enough access rights tries to create an invoice, this would crash. We don't need context here (opw 612591). --- addons/portal_sale/portal_sale_view.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/portal_sale/portal_sale_view.xml b/addons/portal_sale/portal_sale_view.xml index ac56cc9ddfc..2bdc41c09f9 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.