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.

26 lines
961 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, SUPERUSER_ID
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. def post_init_hook(cr, registry):
  8. """Copy payment mode from partner to the new field at contract."""
  9. with api.Environment.manage():
  10. env = api.Environment(cr, SUPERUSER_ID, {})
  11. m_contract = env['account.analytic.account']
  12. contracts = m_contract.search([
  13. ('payment_mode_id', '=', False),
  14. ])
  15. if contracts:
  16. _logger.info('Setting payment mode: %d contracts' %
  17. len(contracts))
  18. for contract in contracts:
  19. payment_mode = contract.partner_id.customer_payment_mode_id
  20. if payment_mode:
  21. contract.payment_mode_id = payment_mode.id
  22. _logger.info('Setting payment mode: Done')