You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.9 KiB

  1. # -*- encoding: utf-8 -*-
  2. ###########################################################################
  3. # Module Writen to OpenERP, Open Source Management Solution
  4. #
  5. # Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
  6. # All Rights Reserved.
  7. # info Vauxoo (info@vauxoo.com)
  8. ############################################################################
  9. # Coded by: Luis Torres (luis_t@vauxoo.com)
  10. ############################################################################
  11. #
  12. # This program is free software: you can redistribute it and/or modify
  13. # it under the terms of the GNU Affero General Public License as
  14. # published by the Free Software Foundation, either version 3 of the
  15. # License, or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU Affero General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU Affero General Public License
  23. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. ##############################################################################
  26. from openerp.osv import osv, fields
  27. from openerp import SUPERUSER_ID
  28. class wizard_merge_partner_by_partner(osv.osv_memory):
  29. _name = 'wizard.merge.partner.by.partner'
  30. def default_get(self, cr, uid, fields, context=None):
  31. partner_obj = self.pool.get('res.partner')
  32. partner = partner_obj.browse(cr, uid, context.get('active_id'),\
  33. context=context)
  34. res = {'partner_id' : partner.id , 'partner_ids' : [partner.id]}
  35. return res
  36. _columns = {
  37. 'partner_id' : fields.many2one('res.partner', 'Partner', readonly=True,
  38. required=True, help='Correct partner to complete data'),
  39. 'partner_ids': fields.many2many('res.partner', 'partners_to_merge',
  40. 'partner_id', 'wizard_id', 'Partner to merge', help='Partners to '\
  41. 'merge'),
  42. }
  43. def merge_cb(self, cr, uid, ids, context=None):
  44. base_partner_obj = self.pool.get('base.partner.merge.automatic.wizard')
  45. partner_obj = self.pool.get('res.partner')
  46. for data in self.browse(cr, uid, ids, context=context):
  47. dst_partner = data.partner_id
  48. partner_ids = set(map(int, data.partner_ids))
  49. if len(partner_ids) >= 2:
  50. base_partner_obj.merge_pbp(cr, SUPERUSER_ID, partner_ids,\
  51. dst_partner, context=context)
  52. list_partners = data.partner_ids
  53. if dst_partner in data.partner_ids:
  54. list_partners.remove(dst_partner)
  55. partner_mergeds = []
  56. for x in list_partners:
  57. partner_mergeds.append(x.id)
  58. partner_obj.write(cr, uid, dst_partner.id, {'partner_merged_ids' : [(6, 0, partner_mergeds)]}, context=context)
  59. return True