From 1daeaed37646208f5f1f94afe900c6f78edd621d Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Feb 2014 13:32:11 +0100 Subject: [PATCH 1/2] [FIX] use copy_data rather than doing a write after that the moves are created lp bug: https://launchpad.net/bugs/1281558 fixed bzr revid: guewen.baconnier@camptocamp.com-20140218123211-3l3bvi3at1s91lfi --- addons/stock/stock.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 02fd28611e6..53f43f73083 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -727,10 +727,6 @@ class stock_picking(osv.osv): if 'invoice_state' not in default and picking_obj.invoice_state == 'invoiced': default['invoice_state'] = '2binvoiced' res = super(stock_picking, self).copy(cr, uid, id, default, context) - if res: - picking_obj = self.browse(cr, uid, res, context=context) - for move in picking_obj.move_lines: - move_obj.write(cr, uid, [move.id], {'tracking_id': False, 'prodlot_id': False, 'move_history_ids2': [(6, 0, [])], 'move_history_ids': [(6, 0, [])]}) return res def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False): @@ -1806,12 +1802,17 @@ class stock_move(osv.osv): _('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).')) return super(stock_move, self).write(cr, uid, ids, vals, context=context) - def copy(self, cr, uid, id, default=None, context=None): + def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} default = default.copy() - default.update({'move_history_ids2': [], 'move_history_ids': []}) - return super(stock_move, self).copy(cr, uid, id, default, context=context) + default.update({ + 'tracking_id': False, + 'prodlot_id': False, + 'move_history_ids2': [], + 'move_history_ids': [] + }) + return super(stock_move, self).copy_data(cr, uid, id, default, context=context) def _auto_init(self, cursor, context=None): res = super(stock_move, self)._auto_init(cursor, context=context) From 0ff86218f617f210495832b5145c40009f8fc3f0 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 24 Feb 2014 10:03:54 +0100 Subject: [PATCH 2/2] Use setdefault to allow a copy with one of this field with a value bzr revid: guewen.baconnier@camptocamp.com-20140224090354-wcsnd4wzs91w553e --- addons/stock/stock.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 53f43f73083..1e6291b739c 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1806,12 +1806,10 @@ class stock_move(osv.osv): if default is None: default = {} default = default.copy() - default.update({ - 'tracking_id': False, - 'prodlot_id': False, - 'move_history_ids2': [], - 'move_history_ids': [] - }) + default.setdefault('tracking_id', False) + default.setdefault('prodlot_id', False) + default.setdefault('move_history_ids', []) + default.setdefault('move_history_ids2', []) return super(stock_move, self).copy_data(cr, uid, id, default, context=context) def _auto_init(self, cursor, context=None):