diff --git a/quality_control/models/quality_control.py b/quality_control/models/quality_control.py index 90bf9e214..fb003b9ba 100644 --- a/quality_control/models/quality_control.py +++ b/quality_control/models/quality_control.py @@ -263,12 +263,9 @@ class QcTestTemplate(orm.Model): def _default_name(self, cr, uid, context=None): if context and context.get('reference_model', False): - templ_id = context.get('reference_id') - if not templ_id: - templ_id = context.get('active_id') - if templ_id: + if 'reference_id' in context: source = self.pool[context['reference_model']].browse( - cr, uid, id, context=context) + cr, uid, context.get('active_id'), context=context) if hasattr(source, 'name'): return source.name @@ -446,11 +443,13 @@ class QcTest(orm.Model): } def copy(self, cr, uid, copy_id, default=None, context=None): + if context is None: + context = {} if default is None: default = {} default['name'] = time.strftime('%Y-%m-%d %H:%M:%S') - return super(QcTest, self).copy( - cr, uid, copy_id, default, context=context) + return super(QcTest, self).copy(cr, uid, copy_id, default, + context=context) def create(self, cr, uid, datas, context=None): if context and context.get('reference_model', False): @@ -485,19 +484,18 @@ class QcTest(orm.Model): test_obj = self.pool['qc.test'] test_line_obj = self.pool['qc.test.line'] for test_id in ids: - test_obj.write(cr, uid, test_id, { - 'test_template_id': template_id - }, context) + test_obj.write(cr, uid, test_id, {'test_template_id': template_id}, + context) test = test_obj.browse(cr, uid, test_id, context=context) - if len(test.test_line_ids) > 0: test_line_obj.unlink(cr, uid, [x.id for x in test.test_line_ids], context=context) test_lines = self._prepare_test_lines( cr, uid, test, force_fill=force_fill, context=context) - test_obj.write(cr, uid, test_id, {'test_line_ids': test_lines}, - context=context) + if test_lines: + test_obj.write(cr, uid, id, {'test_line_ids': test_lines}, + context) def _prepare_test_lines(self, cr, uid, test, force_fill=False, context=None): diff --git a/quality_control/wizard/qc_test_wizard.py b/quality_control/wizard/qc_test_wizard.py index 3db93da64..6a8b03a21 100644 --- a/quality_control/wizard/qc_test_wizard.py +++ b/quality_control/wizard/qc_test_wizard.py @@ -40,10 +40,10 @@ class QcTestWizard(orm.TransientModel): _name = 'qc.test.set.template.wizard' def _default_test_template_id(self, cr, uid, context=None): - active_id = context.get('active_id', False) - test = self.pool['qc.test'].browse(cr, uid, active_id, context=context) - ids = self.pool['qc.test.template'].search(cr, uid, [('object_id', '=', - test.object_id)], + test = self.pool['qc.test'].browse( + cr, uid, context.get('active_id', False), context=context) + cond = [('object_id', '=', test.object_id.id)] + ids = self.pool['qc.test.template'].search(cr, uid, cond, context=context) return ids and ids[0] or False