From 17616e08ef2c7eed912d80e6f2bc26d6bb9de0bd Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 27 Jan 2014 11:19:57 +0100 Subject: [PATCH] [IMP] product: simplify further product_product.copy() bzr revid: rco@openerp.com-20140127101957-1ywu40m081uo79nl --- addons/product/product.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 96fa4c6caa4..83e57e36489 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -833,28 +833,19 @@ class product_product(osv.osv): return res def copy(self, cr, uid, id, default=None, context=None): - if context is None: - context = {} - - if not default: - default = {} + context = context or {} + default = dict(default or {}) # Craft our own ` (copy)` in en_US (self.copy_translation() # will do the other languages). - context_wo_lang = dict(context) + context_wo_lang = dict(context or {}) context_wo_lang.pop('lang', None) - product = self.read(cr, uid, id, ['name', 'variants', 'product_tmpl_id'], context=context_wo_lang) - default = dict(default) - if product['variants'] or context.get('variant'): + product = self.browse(cr, uid, id, context_wo_lang) + if context.get('variant'): # if we copy a variant or create one, we keep the same template - name = default.pop('name', None) - variant = product['variants'] or name or product['name'] - default.update({ - 'variants': _("%s (copy)") % (variant,), - 'product_tmpl_id': product['product_tmpl_id'][0], - }) + default['product_tmpl_id'] = product.product_tmpl_id.id elif 'name' not in default: - default['name'] = _("%s (copy)") % (product['name'],) + default['name'] = _("%s (copy)") % (product.name,) return super(product_product, self).copy(cr, uid, id, default=default, context=context)