From c5b466898cfa76b710ce64840edcd354ae898fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20FRAN=C3=87OIS?= Date: Tue, 31 Mar 2020 12:06:40 +0200 Subject: [PATCH] [ADD] missing action in survey_partner_input --- survey_partner_input/__manifest__.py | 1 + survey_partner_input/models/res_partner.py | 34 ++++++++++++++++++- survey_partner_input/views/res_partner.xml | 4 +-- .../views/survey_user_input.xml | 16 +++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 survey_partner_input/views/survey_user_input.xml diff --git a/survey_partner_input/__manifest__.py b/survey_partner_input/__manifest__.py index dbb9e17..a9d9adf 100644 --- a/survey_partner_input/__manifest__.py +++ b/survey_partner_input/__manifest__.py @@ -16,6 +16,7 @@ ], 'data': [ 'views/res_partner.xml', + 'views/survey_user_input.xml', ], 'demo': [], 'auto_install': False, diff --git a/survey_partner_input/models/res_partner.py b/survey_partner_input/models/res_partner.py index c34c836..323b76b 100644 --- a/survey_partner_input/models/res_partner.py +++ b/survey_partner_input/models/res_partner.py @@ -1,4 +1,5 @@ -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.osv.expression import normalize_domain, AND class ResPartner(models.Model): @@ -48,7 +49,38 @@ class ResPartner(models.Model): else: survey.sent_comp_ratio = int(round(100 * survey.tot_sent_comp_survey / survey.tot_sent_survey, 0)) + # ACTIONS + + @api.multi + def action_survey_user_input(self): + self.ensure_one() + action = self.env.ref('survey.action_survey_user_input').read()[0] + action['display_name'] += _(" from {}").format(self.display_name) + # manage context + ctx = dict(self.env.context) + link_only = ctx.pop('link_only', False) + action['context'] = ctx + # manage domain + domain = action.get('domain') or [] + if isinstance(domain, str): + domain = eval(domain) + if len(domain) > 1: + domain = AND([['|', ('partner_id', '=', self.id), ('email', 'ilike', self.email)], normalize_domain(domain)]) + else: + domain = ['|', ('partner_id', '=', self.id), ('email', 'ilike', self.email)] + if link_only: + if len(domain) > 1: + domain = AND([[('type', '=', 'link')], normalize_domain(domain)]) + else: + domain = [('type', '=', 'link')] + action['domain'] = domain + # return updated action + return action + + # ONCHANGES + @api.onchange('email') def onchange_email(self): + self.ensure_one() if isinstance(self._origin.id, int): self._count_survey_input() diff --git a/survey_partner_input/views/res_partner.xml b/survey_partner_input/views/res_partner.xml index 7c82622..7161295 100644 --- a/survey_partner_input/views/res_partner.xml +++ b/survey_partner_input/views/res_partner.xml @@ -9,12 +9,12 @@ diff --git a/survey_partner_input/views/survey_user_input.xml b/survey_partner_input/views/survey_user_input.xml new file mode 100644 index 0000000..f783fbc --- /dev/null +++ b/survey_partner_input/views/survey_user_input.xml @@ -0,0 +1,16 @@ + + + + + survey_select_input survey.user_input search + survey.user_input + + 26 + + + + + + + +