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 + + + + + + + +