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.

24 lines
922 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([('type', '=', 'contract')])
  13. if contracts:
  14. _logger.info('Setting payment mode: %d contracts' %
  15. len(contracts))
  16. for contract in contracts:
  17. payment_mode = contract.partner_id.customer_payment_mode
  18. if payment_mode:
  19. contract.payment_mode_id = payment_mode.id
  20. _logger.info('Setting payment mode: Done')