Browse Source

Store partner_ref_unique to allow triggering the error updating res.company

Add pre_init_hook to speed up module installation
14.0
Akim Juillerat 5 years ago
committed by Pedro M. Baeza
parent
commit
049b1a1d0e
  1. 1
      partner_ref_unique/__init__.py
  2. 1
      partner_ref_unique/__manifest__.py
  3. 27
      partner_ref_unique/hooks.py
  4. 2
      partner_ref_unique/models/res_partner.py

1
partner_ref_unique/__init__.py

@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from .hooks import pre_init_hook

1
partner_ref_unique/__manifest__.py

@ -13,6 +13,7 @@
"license": "AGPL-3",
"application": False,
"installable": True,
"pre_init_hook": "pre_init_hook",
"depends": [
"base",
],

27
partner_ref_unique/hooks.py

@ -0,0 +1,27 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import logging
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
"""Create column using SQL to avoid auto-init updating the table row by row
:param odoo.sql_db.Cursor cr:
Database cursor.
"""
_logger.info(
"Creating res.partner.partner_ref_unique column with value from "
"res.company"
)
cr.execute("ALTER TABLE res_partner ADD partner_ref_unique varchar NULL;")
cr.execute(
"COMMENT ON COLUMN res_partner.partner_ref_unique "
"IS 'Unique partner reference for';"
)
cr.execute(
"UPDATE res_partner rp "
"SET partner_ref_unique = rc.partner_ref_unique "
"FROM res_company rc "
"WHERE rc.id = rp.company_id;"
)

2
partner_ref_unique/models/res_partner.py

@ -11,7 +11,7 @@ class ResPartner(models.Model):
# This related is needed in order to trigger the check when changing the
# value on res.company
partner_ref_unique = fields.Selection(
related='company_id.partner_ref_unique',
related='company_id.partner_ref_unique', store=True,
)
@api.multi

Loading…
Cancel
Save