-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] compute pos_order_count in pre_init_hook
- Loading branch information
1 parent
cb2d442
commit 5d27263
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |