From d42ea76feffb800d99afeb4dc16ed16110ff599a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 5 Dec 2008 13:26:41 +0100 Subject: [PATCH] Allow to use a list of id for copy method --- sale.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/sale.py b/sale.py index df209f91a5..1f3a02ce2b 100644 --- a/sale.py +++ b/sale.py @@ -125,21 +125,29 @@ class SaleLine(OSV): selection_obj.delete(cursor, user, selection_ids, context=context) return res - def copy(self, cursor, user, line_id, default=None, context=None): + def copy(self, cursor, user, ids, default=None, context=None): selection_obj = self.pool.get('analytic_account.account.selection') - if default is None: - default = {} - default = default.copy() - line = self.browse(cursor, user, line_id, context=context) - selection_id = False - if line.analytic_accounts: - selection_id = selection_obj.copy(cursor, user, - line.analytic_accounts.id, context=context) - default['analytic_accounts'] = selection_id - return super(SaleLine, self).copy(cursor, user, line_id, + new_ids = super(SaleLine, self).copy(cursor, user, ids, default=default, context=context) + int_id = False + if isinstance(new_ids, (int, long)): + int_id = True + new_ids = [new_ids] + + for line in self.browse(cursor, user, new_ids, context=context): + if line.analytic_accounts: + selection_id = selection_obj.copy(cursor, user, + line.analytic_accounts.id, context=context) + self.write(cursor, user, line.id, { + 'analytic_accounts': selection_id, + }, context=context) + + if int_id: + return new_ids[0] + return new_ids + def get_invoice_line(self, cursor, user, line, context=None): account_selection_obj = self.pool.get('analytic_account.account.selection')