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.

27 lines
990 B

  1. # -*- coding: utf-8 -*-
  2. # © 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. ('type', '=', 'contract'),
  14. ('payment_mode_id', '=', False),
  15. ])
  16. if contracts:
  17. _logger.info('Setting payment mode: %d contracts' %
  18. len(contracts))
  19. for contract in contracts:
  20. payment_mode = contract.partner_id.customer_payment_mode
  21. if payment_mode:
  22. contract.payment_mode_id = payment_mode.id
  23. _logger.info('Setting payment mode: Done')