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.

64 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from openerp.osv import orm
  4. from openerp import models, api
  5. _logger = logging.getLogger(__name__)
  6. class WizardMultiChartsAccounts(orm.TransientModel):
  7. """
  8. Execute wizard automatically without showing the wizard popup window
  9. """
  10. _inherit = 'wizard.multi.charts.accounts'
  11. def auto_execute(self, cr, uid, ids=False, context=None):
  12. if not context:
  13. context = {}
  14. context['lang'] = 'en_US'
  15. if not ids:
  16. ids = self.search(cr, uid, [], context=context)
  17. account_obj = self.pool.get('account.account')
  18. for wz in self.browse(cr, uid, ids, context=context):
  19. account_id = account_obj.search(
  20. cr,
  21. uid,
  22. [('company_id', '=', wz.company_id.id)],
  23. limit=1,
  24. context=context
  25. )
  26. if not account_id:
  27. # execute original wizard method
  28. _logger.info(
  29. 'Configure Accounting Data for Company: %s' %
  30. wz.company_id.name
  31. )
  32. self.execute(cr, uid, [wz.id], context=context)
  33. class AccountAccountTemplate(models.Model):
  34. _inherit = "account.account.template"
  35. @api.model
  36. def generate_account(
  37. self,
  38. chart_template_id,
  39. tax_template_ref,
  40. acc_template_ref,
  41. code_digits,
  42. company_id):
  43. res = super(AccountAccountTemplate, self).generate_account(
  44. chart_template_id,
  45. tax_template_ref,
  46. acc_template_ref,
  47. code_digits,
  48. company_id
  49. )
  50. main_company_id = self.env['ir.model.data'].xmlid_to_res_id(
  51. 'base.main_company'
  52. )
  53. if company_id == main_company_id:
  54. account_ids = []
  55. for template_account_id in res:
  56. account_ids.append(res[template_account_id])
  57. return res