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.

25 lines
927 B

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