From ee0f4b130004d09224e2b96acf7536c13d891377 Mon Sep 17 00:00:00 2001 From: Patrick Hoste Date: Thu, 7 Apr 2022 12:09:17 +0000 Subject: [PATCH] [IMP] website_slides_survey: set slide name when setting survey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PURPOSE This commit slightly modifies both the slide's backend form view and the website form to use the certification (survey) title as default name for this slide if it does not have a name configured yet. We also removed dead onchange code as the survey_id field is not visible if slide_category is not set to certification. LINKS Task-2810395 closes odoo/odoo#87672 Signed-off-by: Warnon Aurélien (awa) --- addons/website_slides_survey/models/slide_slide.py | 12 +++++++----- .../static/src/js/slides_upload.js | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/website_slides_survey/models/slide_slide.py b/addons/website_slides_survey/models/slide_slide.py index 5036882c396..44f930a363c 100644 --- a/addons/website_slides_survey/models/slide_slide.py +++ b/addons/website_slides_survey/models/slide_slide.py @@ -30,6 +30,7 @@ class SlidePartnerRelation(models.Model): class Slide(models.Model): _inherit = 'slide.slide' + name = fields.Char(compute='_compute_name', readonly=False, store=True) slide_category = fields.Selection(selection_add=[ ('certification', 'Certification') ], ondelete={'certification': 'set default'}) @@ -46,17 +47,18 @@ class Slide(models.Model): ('check_certification_preview', "CHECK(slide_category != 'certification' OR is_preview = False)", "A slide of type certification cannot be previewed."), ] + @api.depends('survey_id') + def _compute_name(self): + for slide in self: + if not slide.name and slide.survey_id: + slide.name = slide.survey_id.title + @api.depends('slide_category') def _compute_is_preview(self): for slide in self: if slide.slide_category == 'certification' or not slide.is_preview: slide.is_preview = False - @api.onchange('survey_id') - def _on_change_survey_id(self): - if self.survey_id: - self.slide_category = 'certification' - @api.depends('slide_category', 'source_type') def _compute_slide_type(self): super(Slide, self)._compute_slide_type() diff --git a/addons/website_slides_survey/static/src/js/slides_upload.js b/addons/website_slides_survey/static/src/js/slides_upload.js index 2f1d57e50bc..d14fec1c254 100644 --- a/addons/website_slides_survey/static/src/js/slides_upload.js +++ b/addons/website_slides_survey/static/src/js/slides_upload.js @@ -22,8 +22,9 @@ SlidesUpload.SlideUploadDialog.include({ * Will automatically set the title of the slide to the title of the chosen certification */ _onChangeCertification: function (ev) { - if (ev.added && ev.added.text) { - this.$("input#name").val(ev.added.text); + const $inputElement = this.$("input#name"); + if (ev.added && ev.added.text && !$inputElement.val().trim()) { + $inputElement.val(ev.added.text); } },