forked from OCA/account-invoicing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
28 lines (19 loc) · 870 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
24
25
26
27
28
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from logging import getLogger
from odoo import SUPERUSER_ID, api
_logger = getLogger(__name__)
def post_init_hook(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
force_compute_original_partners(env)
def force_compute_original_partners(env):
"""Force compute original partners.
Since field `original_partner_ids` is not automatically computed upon
module installation, we need to compute it manually on existing records.
:param env: an Odoo Environment instance
"""
domain = [("move_type", "=", "out_invoice")]
invs = env["account.move"].search(domain)
_logger.info("Force-compute original partners on %s invoices" % len(invs))
invs._compute_original_partner_ids()