From d1d631871afe3a3bcf24ed82fef168b09bf09c74 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 23 Dec 2021 10:39:28 +0000 Subject: [PATCH] [FIX] lunch: do not generate custom code counted by cloc Issue ----- The module lunch generate ir.cron and thus server action when lunch.supplier and lunch.alert are created. Those server action are counted as customization by cloc and thus customer should pays maintenance fee just for the installation of data_merge module Cron are deleted when supplier and alert are deleted but the server action remains. Solution -------- Avoid to count server action generated by lunch by adding a xml_id from lunch module to those SA Delete server actions as well closes odoo/odoo#82576 X-original-commit: cafd96dde8df79e7158b156b961657941b0265cb Signed-off-by: Julien Castiaux Signed-off-by: Thibault Francois --- addons/lunch/data/lunch_demo.xml | 7 +++++++ addons/lunch/models/lunch_alert.py | 10 ++++++++++ addons/lunch/models/lunch_supplier.py | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/addons/lunch/data/lunch_demo.xml b/addons/lunch/data/lunch_demo.xml index 799c212446f..4a37949894c 100644 --- a/addons/lunch/data/lunch_demo.xml +++ b/addons/lunch/data/lunch_demo.xml @@ -76,6 +76,13 @@ Office 3 + + Alert for Office 3 + Please order + + chat + + diff --git a/addons/lunch/models/lunch_alert.py b/addons/lunch/models/lunch_alert.py index 662b3cf95d6..0e5d88e6915 100644 --- a/addons/lunch/models/lunch_alert.py +++ b/addons/lunch/models/lunch_alert.py @@ -136,6 +136,14 @@ class LunchAlert(models.Model): } for _ in range(len(vals_list)) ]) + self.env['ir.model.data'].sudo().create([{ + 'name': f'lunch_alert_cron_sa_{cron.ir_actions_server_id.id}', + 'module': 'lunch', + 'res_id': cron.ir_actions_server_id.id, + 'model': 'ir.actions.server', + # noupdate is set to true to avoid to delete record at module update + 'noupdate': True, + } for cron in crons]) for vals, cron in zip(vals_list, crons): vals['cron_id'] = cron.id @@ -150,8 +158,10 @@ class LunchAlert(models.Model): def unlink(self): crons = self.cron_id.sudo() + server_actions = crons.ir_actions_server_id super().unlink() crons.unlink() + server_actions.unlink() def _notify_chat(self): # Called daily by cron diff --git a/addons/lunch/models/lunch_supplier.py b/addons/lunch/models/lunch_supplier.py index 7eabec19d5c..8e615f49a5e 100644 --- a/addons/lunch/models/lunch_supplier.py +++ b/addons/lunch/models/lunch_supplier.py @@ -168,6 +168,14 @@ class LunchSupplier(models.Model): } for _ in range(len(vals_list)) ]) + self.env['ir.model.data'].sudo().create([{ + 'name': f'lunch_supplier_cron_sa_{cron.ir_actions_server_id.id}', + 'module': 'lunch', + 'res_id': cron.ir_actions_server_id.id, + 'model': 'ir.actions.server', + # noupdate is set to true to avoid to delete record at module update + 'noupdate': True, + } for cron in crons]) for vals, cron in zip(vals_list, crons): vals['cron_id'] = cron.id @@ -192,8 +200,10 @@ class LunchSupplier(models.Model): def unlink(self): crons = self.cron_id.sudo() + server_actions = crons.ir_actions_server_id super().unlink() crons.unlink() + server_actions.unlink() def toggle_active(self): """ Archiving related lunch product """