|
|
self.env['ir.module.module'].flush_model(['auto_install', 'country_ids', 'dependencies_id'])
self.env['ir.module.module.dependency'].flush_model()
self.env.cr.execute("""
SELECT country.id,
ARRAY_AGG(module.id)
FROM ir_module_module module,
res_country country
WHERE module.auto_install
AND state NOT IN %(install_states)s
AND NOT EXISTS (
SELECT 1
FROM ir_module_module_dependency d
JOIN ir_module_module mdep ON (d.name = mdep.name)
WHERE d.module_id = module.id
AND d.auto_install_required
AND mdep.state NOT IN %(install_states)s
)
AND EXISTS (
SELECT 1
FROM module_country mc
WHERE mc.module_id = module.id
AND mc.country_id = country.id
)
AND country.id = ANY(%(country_ids)s)
GROUP BY country.id
""", {
'country_ids': self.country_id.ids,
'install_states': ('installed', 'to install', 'to upgrade'),
})
mapping = dict(self.env.cr.fetchall())
for company in self:
company.uninstalled_l10n_module_ids = self.env['ir.module.module'].browse(mapping.get(company.country_id.id))
|
|