mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] Copy partner payment mode to contracts when installing
This commit is contained in:
@@ -34,6 +34,7 @@ Contributors
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Ángel Moya <angel.moya@domatix.com>
|
* Ángel Moya <angel.moya@domatix.com>
|
||||||
|
* Antonio Espinosa <antonioea@antiun.com>
|
||||||
|
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
from .hooks import post_init_hook
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
'views/contract_view.xml',
|
'views/contract_view.xml',
|
||||||
],
|
],
|
||||||
'test': ['test/contract_payment_mode.yml'],
|
'test': ['test/contract_payment_mode.yml'],
|
||||||
|
'post_init_hook': 'post_init_hook',
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': True,
|
'auto_install': True,
|
||||||
}
|
}
|
||||||
|
|||||||
24
contract_payment_mode/hooks.py
Normal file
24
contract_payment_mode/hooks.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from openerp import api, SUPERUSER_ID
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_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['account.analytic.account']
|
||||||
|
contracts = m_contract.search([('type', '=', 'contract')])
|
||||||
|
if contracts:
|
||||||
|
_logger.info('Setting payment mode: %d contracts' %
|
||||||
|
len(contracts))
|
||||||
|
for contract in contracts:
|
||||||
|
payment_mode = contract.partner_id.customer_payment_mode
|
||||||
|
if payment_mode:
|
||||||
|
contract.payment_mode_id = payment_mode.id
|
||||||
|
_logger.info('Setting payment mode: Done')
|
||||||
Reference in New Issue
Block a user