|
| 1 | +# Copyright 2025 Akretion (https://www.akretion.com). |
| 2 | +# @author Kévin Roche <kevin.roche@akretion.com> |
| 3 | + |
| 4 | +from odoo import fields, models |
| 5 | + |
| 6 | +MAPPING_KIND_MODELS = { |
| 7 | + "Article": [ |
| 8 | + "product.product", |
| 9 | + "product.template", |
| 10 | + "product.categorie", |
| 11 | + "product.attribute", |
| 12 | + "product.attribute.value", |
| 13 | + "uom.uom", |
| 14 | + "hs.code", |
| 15 | + "product.packaging.type", |
| 16 | + "product.packaging", |
| 17 | + ], |
| 18 | + "Vente": [ |
| 19 | + "sale.order", |
| 20 | + "product.pricelist", |
| 21 | + "product.pricelist.item", |
| 22 | + "crm.team", |
| 23 | + "delivery.carrier", |
| 24 | + ], |
| 25 | + "Achat": [ |
| 26 | + "purchase.order", |
| 27 | + "product.supplierinfo", |
| 28 | + ], |
| 29 | + "Logistique": [ |
| 30 | + "stock.picking", |
| 31 | + "stock.picking.type", |
| 32 | + "stock.quant", |
| 33 | + "stock.location", |
| 34 | + "stock.warehouse", |
| 35 | + "stock.lot", |
| 36 | + "stock.route", |
| 37 | + "stock.warehouse.orderpoint", |
| 38 | + "stock.putaway.rule", |
| 39 | + "stock.inventory", |
| 40 | + "stock.inventory.line", |
| 41 | + ], |
| 42 | + "Production": [ |
| 43 | + "mrp.bom", |
| 44 | + "mrp.production", |
| 45 | + "mrp.workorder", |
| 46 | + ], |
| 47 | + "Comptabilité": [ |
| 48 | + "account.account", |
| 49 | + "account.tax", |
| 50 | + "account.journal", |
| 51 | + "account.product.fiscal.classification", |
| 52 | + "account.fiscal.position", |
| 53 | + ], |
| 54 | + "Immobilisation": [ |
| 55 | + "account.asset", |
| 56 | + "account.asset.profile", |
| 57 | + "account.asset.category", |
| 58 | + ], |
| 59 | + "Facturation": [ |
| 60 | + "account.move", |
| 61 | + "account.payment", |
| 62 | + "account.account.type", |
| 63 | + "account.payment.term", |
| 64 | + "account.incoterms", |
| 65 | + ], |
| 66 | + "Banque": [ |
| 67 | + "account.reconcile.model", |
| 68 | + "account.bank.statement", |
| 69 | + "res.partner.bank", |
| 70 | + "res.bank", |
| 71 | + "online.bank.statement.provider", |
| 72 | + ], |
| 73 | + "Projet": [ |
| 74 | + "project.project", |
| 75 | + "project.task", |
| 76 | + ], |
| 77 | + "Contact": [ |
| 78 | + "res.partner", |
| 79 | + "res.country", |
| 80 | + "res.company", |
| 81 | + ], |
| 82 | + "Calendrier": [ |
| 83 | + "calendar.event", |
| 84 | + "resource.calendar", |
| 85 | + ], |
| 86 | + "Support": [ |
| 87 | + "helpdesk.ticket", |
| 88 | + ], |
| 89 | + "Utilisateur": [ |
| 90 | + "res.users", |
| 91 | + ], |
| 92 | + "Sécurité": [ |
| 93 | + "ir.model.access", |
| 94 | + "ir.rule", |
| 95 | + "res.groups", |
| 96 | + "res.users.role", |
| 97 | + ], |
| 98 | + "CRM": [ |
| 99 | + "crm.lead", |
| 100 | + "crm.stage", |
| 101 | + ], |
| 102 | + "Employé": [ |
| 103 | + "hr.employee", |
| 104 | + "hr.contract", |
| 105 | + "hr.leave", |
| 106 | + ], |
| 107 | + "Point de vente": [ |
| 108 | + "pos.order", |
| 109 | + "pos.session", |
| 110 | + "pos.config", |
| 111 | + ], |
| 112 | + "File d'attente des travaux": [ |
| 113 | + "queue.job", |
| 114 | + "attachment.queue", |
| 115 | + "queue.job.channel", |
| 116 | + ], |
| 117 | + "Technique": [ |
| 118 | + "ir.module.module", |
| 119 | + ], |
| 120 | + "documents": [ |
| 121 | + "dms.file", |
| 122 | + "dms.directory", |
| 123 | + ], |
| 124 | + "Maintenance": [ |
| 125 | + "maintenance.equipment", |
| 126 | + "maintenance.equipment.network", |
| 127 | + "maintenance.team", |
| 128 | + ], |
| 129 | +} |
| 130 | + |
| 131 | + |
| 132 | +class IrModel(models.Model): |
| 133 | + _inherit = "ir.model" |
| 134 | + |
| 135 | + model_for_role_descr = fields.Boolean( |
| 136 | + string="Model for Role Description", |
| 137 | + compute="_compute_for_role_descr", |
| 138 | + store=True, |
| 139 | + ) |
| 140 | + |
| 141 | + def get_mapping_kind_models(self): |
| 142 | + return MAPPING_KIND_MODELS |
| 143 | + |
| 144 | + def get_kinds_for_role_descr(self): |
| 145 | + return [ |
| 146 | + (kind, kind.capitalize()) for kind in self.get_mapping_kind_models().keys() |
| 147 | + ] + [("other", "Other")] |
| 148 | + |
| 149 | + kind_for_role_descr = fields.Selection( |
| 150 | + selection=get_kinds_for_role_descr, |
| 151 | + string="Kind for Role Description", |
| 152 | + compute="_compute_for_role_descr", |
| 153 | + store=True, |
| 154 | + ) |
| 155 | + |
| 156 | + def _compute_for_role_descr(self): |
| 157 | + mapping = self.get_mapping_kind_models() |
| 158 | + for rec in self: |
| 159 | + rec.kind_for_role_descr = "other" |
| 160 | + for kind, models in mapping.items(): |
| 161 | + if rec.model in models: |
| 162 | + rec.kind_for_role_descr = kind |
| 163 | + rec.model_for_role_descr = True |
| 164 | + break |
| 165 | + |
| 166 | + def _cron_update_model_for_role_descr(self): |
| 167 | + self.search([])._compute_for_role_descr() |
0 commit comments