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