Skip to content

Commit 86bd61f

Browse files
KangOlaj-fuentes
andcommitted
[FIX] respect country filtering when auto installing modules
closes #123 Signed-off-by: Christophe Simonis (chs) <[email protected]> Co-authored-by: Alvaro Fuentes <[email protected]>
1 parent 5789538 commit 86bd61f

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/util/modules.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ def force_install_module(cr, module, if_installed=None):
530530
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
531531
dep_match = "AND d.auto_install_required = TRUE AND e.auto_install_required = TRUE"
532532

533+
country_match = country_join = ""
534+
if table_exists(cr, "module_country"):
535+
country_join = """
536+
LEFT JOIN module_country mc
537+
ON mc.module_id = on_me.id
538+
LEFT JOIN (
539+
SELECT c.id, p.country_id
540+
FROM res_company c
541+
JOIN res_partner p
542+
ON p.id = c.partner_id
543+
WHERE c.active
544+
) AS c
545+
ON c.country_id = mc.country_id
546+
"""
547+
country_match = """
548+
AND (
549+
count(mc) = 0 -- no country set
550+
OR count(c) > 0 -- or have active companies with a matching country
551+
)
552+
"""
553+
533554
cat_match = ""
534555
if NO_AUTOINSTALL:
535556
# even if we skip auto installs, we still need to auto install the real link-modules.
@@ -544,6 +565,7 @@ def force_install_module(cr, module, if_installed=None):
544565
JOIN ir_module_module on_me ON on_me.id = d.module_id
545566
JOIN ir_module_module_dependency e ON e.module_id = on_me.id
546567
JOIN ir_module_module its_deps ON its_deps.name = e.name
568+
{}
547569
WHERE d.name = ANY(%s)
548570
AND on_me.state = 'uninstalled'
549571
AND on_me.auto_install = TRUE
@@ -553,7 +575,9 @@ def force_install_module(cr, module, if_installed=None):
553575
HAVING
554576
-- are all dependencies (to be) installed?
555577
array_agg(its_deps.state)::text[] <@ %s
556-
""".format(dep_match, cat_match),
578+
{}
579+
580+
""".format(country_join, dep_match, cat_match, country_match),
557581
[toinstall, list(INSTALLED_MODULE_STATES)],
558582
)
559583
for (mod,) in cr.fetchall():
@@ -656,6 +680,27 @@ def trigger_auto_install(cr, module):
656680
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
657681
dep_match = "d.auto_install_required = true"
658682

683+
country_match = country_join = ""
684+
if table_exists(cr, "module_country"):
685+
country_join = """
686+
LEFT JOIN module_country mc
687+
ON mc.module_id = m.id
688+
LEFT JOIN (
689+
SELECT c.id, p.country_id
690+
FROM res_company c
691+
JOIN res_partner p
692+
ON p.id = c.partner_id
693+
WHERE c.active
694+
) AS c
695+
ON c.country_id = mc.country_id
696+
"""
697+
country_match = """
698+
AND (
699+
count(mc) = 0 -- no country set
700+
OR count(c) > 0 -- or have active companies with a matching country
701+
)
702+
"""
703+
659704
cat_match = "true"
660705
if NO_AUTOINSTALL:
661706
# even if we skip auto installs, we still need to auto install the real link-modules.
@@ -668,14 +713,16 @@ def trigger_auto_install(cr, module):
668713
FROM ir_module_module_dependency d
669714
JOIN ir_module_module m ON m.id = d.module_id
670715
JOIN ir_module_module md ON md.name = d.name
716+
{}
671717
WHERE m.name = %s
672718
AND m.state = 'uninstalled'
673719
AND m.auto_install = true
674720
AND {}
675721
AND {}
676722
GROUP BY m.id
677723
HAVING bool_and(md.state IN %s)
678-
""".format(dep_match, cat_match)
724+
{}
725+
""".format(country_join, dep_match, cat_match, country_match)
679726

680727
cr.execute(query, [module, INSTALLED_MODULE_STATES])
681728
if cr.rowcount:

0 commit comments

Comments
 (0)