[FIX] spreadsheet_dashboard: fix external id not found issue in spreadsheet
If applied, this commit will solve the 'external id not found' issue while the user had deleted the 'Logistics' dashboard and then install or upgrade the spreadsheet modules. Steps to produce: - Open the 'Logistics' dashboard from Spreadsheet > Configuration > Dashboards. - Delete all 'Spreadsheet' from Logistics. - Now delete the 'Logistics' dashboard from the action. - Install or Upgrade modules that are using that dashboard like spreadsheet_dashboard_stock, spreadsheet_dashboard_purchase, etc. sentry - 4083977216 see - https://tinyurl.com/2az3tqtv closes odoo/odoo#120528 X-original-commit: 9b295f5e478fc7b9a888ca07de267f0537fb02ae Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Signed-off-by: Parth Solanki (paso) <paso@odoo.com>
This commit is contained in:
@@ -196,3 +196,10 @@ msgstr ""
|
||||
#: model:spreadsheet.dashboard.group,name:spreadsheet_dashboard.spreadsheet_dashboard_group_website
|
||||
msgid "Website"
|
||||
msgstr ""
|
||||
|
||||
#. module: spreadsheet_dashboard
|
||||
#. odoo-python
|
||||
#: code:addons/spreadsheet_dashboard/models/spreadsheet_dashboard_group.py:0
|
||||
#, python-format
|
||||
msgid "You cannot delete %s as it is used in another module."
|
||||
msgstr ""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from odoo import fields, models
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class SpreadsheetDashboardGroup(models.Model):
|
||||
@@ -9,3 +10,11 @@ class SpreadsheetDashboardGroup(models.Model):
|
||||
name = fields.Char(required=True, translate=True)
|
||||
dashboard_ids = fields.One2many('spreadsheet.dashboard', 'dashboard_group_id')
|
||||
sequence = fields.Integer()
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_spreadsheet_data(self):
|
||||
external_ids = self.get_external_id()
|
||||
for group in self:
|
||||
external_id = external_ids[group.id]
|
||||
if external_id and not external_id.startswith('__export__'):
|
||||
raise UserError(_("You cannot delete %s as it is used in another module.", group.name))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class TestSpreadsheetDashboard(TransactionCase):
|
||||
@@ -17,3 +18,16 @@ class TestSpreadsheetDashboard(TransactionCase):
|
||||
dashboard.spreadsheet_data,
|
||||
'{"version": 1, "sheets": [{"id": "sheet1", "name": "Sheet1"}]}',
|
||||
)
|
||||
|
||||
def test_unlink_prevent_spreadsheet_group(self):
|
||||
group = self.env["spreadsheet.dashboard.group"].create(
|
||||
{"name": "a_group"}
|
||||
)
|
||||
self.env['ir.model.data'].create({
|
||||
'name': group.name,
|
||||
'module': 'spreadsheet_dashboard',
|
||||
'model': group._name,
|
||||
'res_id': group.id,
|
||||
})
|
||||
with self.assertRaises(UserError, msg="You cannot delete a_group as it is used in another module"):
|
||||
group.unlink()
|
||||
|
||||
Reference in New Issue
Block a user