Skip to content

Commit

Permalink
[ADD] compute pos_order_count in pre_init_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-champonnois authored and robinkeunen committed Nov 14, 2022
1 parent cb2d442 commit 5d27263
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pos_order_count_store/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import models

from .pre_init_hook import pre_compute_pos_order_count
1 change: 1 addition & 0 deletions pos_order_count_store/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"author": "Coop IT Easy SC",
"license": "AGPL-3",
"depends": ["point_of_sale"],
"pre_init_hook": "pre_compute_pos_order_count",
"data": [],
}
28 changes: 28 additions & 0 deletions pos_order_count_store/pre_init_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def pre_compute_pos_order_count(cr):
# compute pos_order_count with SQL for faster installation
query = """
ALTER TABLE
res_partner
ADD COLUMN IF NOT EXISTS
pos_order_count INTEGER;
"""
cr.execute(query)
query = """
UPDATE
res_partner
SET
pos_order_count = count
FROM
(
SELECT
partner_id,
count(*)
FROM
pos_order
GROUP by
partner_id
) pos_order_partner
WHERE
res_partner.id = pos_order_partner.partner_id;
"""
cr.execute(query)

0 comments on commit 5d27263

Please sign in to comment.