@@ -530,6 +530,27 @@ def force_install_module(cr, module, if_installed=None):
530
530
if column_exists (cr , "ir_module_module_dependency" , "auto_install_required" ):
531
531
dep_match = "AND d.auto_install_required = TRUE AND e.auto_install_required = TRUE"
532
532
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
+
533
554
cat_match = ""
534
555
if NO_AUTOINSTALL :
535
556
# 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):
544
565
JOIN ir_module_module on_me ON on_me.id = d.module_id
545
566
JOIN ir_module_module_dependency e ON e.module_id = on_me.id
546
567
JOIN ir_module_module its_deps ON its_deps.name = e.name
568
+ {}
547
569
WHERE d.name = ANY(%s)
548
570
AND on_me.state = 'uninstalled'
549
571
AND on_me.auto_install = TRUE
@@ -553,7 +575,9 @@ def force_install_module(cr, module, if_installed=None):
553
575
HAVING
554
576
-- are all dependencies (to be) installed?
555
577
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 ),
557
581
[toinstall , list (INSTALLED_MODULE_STATES )],
558
582
)
559
583
for (mod ,) in cr .fetchall ():
@@ -656,6 +680,27 @@ def trigger_auto_install(cr, module):
656
680
if column_exists (cr , "ir_module_module_dependency" , "auto_install_required" ):
657
681
dep_match = "d.auto_install_required = true"
658
682
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
+
659
704
cat_match = "true"
660
705
if NO_AUTOINSTALL :
661
706
# 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):
668
713
FROM ir_module_module_dependency d
669
714
JOIN ir_module_module m ON m.id = d.module_id
670
715
JOIN ir_module_module md ON md.name = d.name
716
+ {}
671
717
WHERE m.name = %s
672
718
AND m.state = 'uninstalled'
673
719
AND m.auto_install = true
674
720
AND {}
675
721
AND {}
676
722
GROUP BY m.id
677
723
HAVING bool_and(md.state IN %s)
678
- """ .format (dep_match , cat_match )
724
+ {}
725
+ """ .format (country_join , dep_match , cat_match , country_match )
679
726
680
727
cr .execute (query , [module , INSTALLED_MODULE_STATES ])
681
728
if cr .rowcount :
0 commit comments