Skip to content

Commit

Permalink
Merge PR #111 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Oct 11, 2024
2 parents 6b9d5c6 + 52c2948 commit 0f5ad75
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 3 deletions.
7 changes: 6 additions & 1 deletion survey_sale_generation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Survey sale generation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:96b9d8aa2790d244ff109d73c61d51c69072f4b9d911d81ba8ad1bfee5f961c8
!! source digest: sha256:b766d3b51165f326a1a01b5a1742c4178b53af2c4ea6d0a4aacfb85f14e8ed7f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -77,6 +77,11 @@ If you want to use a quotation template you can choose it from the options: *Sal
You can also configure the survey to send the quotation to the customer by mail. When doing
so, you can choose a mail template or use the default one.

If you want to fill sale fields from the answers:

#. In the *Options* tab of the questions go to the *Sales* section.
#. Set *Sale the sale field* you want to fill with the given answer.

Usage
=====

Expand Down
21 changes: 21 additions & 0 deletions survey_sale_generation/demo/survey_sale_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,25 @@
eval="[Command.link(ref('survey_sale_generation.mail_management'))]"
/>
</record>
<record model="survey.question" id="survey_support_q4">
<field name="survey_id" ref="survey_hire_support" />
<field name="sequence">6</field>
<field name="title">Referenced by</field>
<field name="question_type">simple_choice</field>
<field name="comments_allowed" eval="True" />
<field name="comment_count_as_answer" eval="True" />
<field name="comments_message">Other:</field>
<field name="sale_order_field" ref="sale.field_sale_order__origin" />
<field name="constr_mandatory" eval="True" />
</record>
<record model="survey.question.answer" id="survey_support_q4_sug1">
<field name="question_id" ref="survey_support_q4" />
<field name="sequence">1</field>
<field name="value">TV</field>
</record>
<record model="survey.question.answer" id="survey_support_q4_sug2">
<field name="question_id" ref="survey_support_q4" />
<field name="sequence">2</field>
<field name="value">Internet</field>
</record>
</odoo>
32 changes: 32 additions & 0 deletions survey_sale_generation/models/survey_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ class SurveyQuestion(models.Model):
"want to multiply members by memberships in our sale line.",
)
show_in_sale_order_comment = fields.Boolean()
# Save into model fields
allowed_sale_order_field_ids = fields.Many2many(
comodel_name="ir.model.fields",
compute="_compute_allowed_sale_order_field_ids",
)
sale_order_field = fields.Many2one(
comodel_name="ir.model.fields",
domain="[('id', 'in', allowed_sale_order_field_ids)]",
)

@api.depends("question_type")
def _compute_allowed_sale_order_field_ids(self):
type_mapping = {
"char_box": ["char", "text"],
"text_box": ["html", "text"],
"numerical_box": ["integer", "float", "html", "char"],
"date": ["date", "text", "char"],
"datetime": ["datetime", "html", "char"],
"simple_choice": ["html", "char"],
"multiple_choice": ["html", "char"],
}
for record in self:
record.allowed_sale_order_field_ids = (
self.env["ir.model.fields"]
.search(
[
("model", "=", "sale.order"),
("ttype", "in", type_mapping.get(record.question_type, [])),
]
)
.ids
)


class SurveyLabel(models.Model):
Expand Down
26 changes: 25 additions & 1 deletion survey_sale_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SurveyUserInput(models.Model):
sale_order_id = fields.Many2one(comodel_name="sale.order")

def _prepare_quotation(self):
return {
vals = {
"partner_id": self.partner_id.id or self.create_uid.partner_id.id,
"origin": self.survey_id.title,
"survey_user_input_id": self.id,
Expand All @@ -20,6 +20,30 @@ def _prepare_quotation(self):
self.survey_id.crm_team_id.user_id.id or self.survey_id.user_id.id
),
}
# Fill sale.order fields from answers
elegible_inputs = self.user_input_line_ids.filtered(
lambda x: x.question_id.sale_order_field and not x.skipped
)
basic_inputs = elegible_inputs.filtered(
lambda x: x.answer_type not in {"suggestion"}
)
vals.update(
{
line.question_id.sale_order_field.name: line[
f"value_{line.answer_type}"
]
for line in basic_inputs
}
)
for line in elegible_inputs - basic_inputs:
field_name = line.question_id.sale_order_field.name
value = (
line.suggested_answer_id.value
if line.answer_type == "suggestion"
else line[f"value_{line.answer_type}"]
)
vals[field_name] = value
return vals

def _prepare_quotation_line(self, input_line, product):
if input_line.question_id.question_type == "numerical_box":
Expand Down
5 changes: 5 additions & 0 deletions survey_sale_generation/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ If you want to use a quotation template you can choose it from the options: *Sal

You can also configure the survey to send the quotation to the customer by mail. When doing
so, you can choose a mail template or use the default one.

If you want to fill sale fields from the answers:

#. In the *Options* tab of the questions go to the *Sales* section.
#. Set *Sale the sale field* you want to fill with the given answer.
7 changes: 6 additions & 1 deletion survey_sale_generation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Survey sale generation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:96b9d8aa2790d244ff109d73c61d51c69072f4b9d911d81ba8ad1bfee5f961c8
!! source digest: sha256:b766d3b51165f326a1a01b5a1742c4178b53af2c4ea6d0a4aacfb85f14e8ed7f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/survey/tree/15.0/survey_sale_generation"><img alt="OCA/survey" src="https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/survey-15-0/survey-15-0-survey_sale_generation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/survey&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to generate quotations from surveys submits.</p>
Expand Down Expand Up @@ -423,6 +423,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>If you want to use a quotation template you can choose it from the options: <em>Sale Order Template</em>.</p>
<p>You can also configure the survey to send the quotation to the customer by mail. When doing
so, you can choose a mail template or use the default one.</p>
<p>If you want to fill sale fields from the answers:</p>
<ol class="arabic simple">
<li>In the <em>Options</em> tab of the questions go to the <em>Sales</em> section.</li>
<li>Set <em>Sale the sale field</em> you want to fill with the given answer.</li>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand Down
10 changes: 10 additions & 0 deletions survey_sale_generation/static/tests/survey_sale_generation_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ odoo.define("survey.tour_test_survey_sale_generation", function (require) {
trigger:
"div.js_question-wrapper:contains('Choose your extras') span:contains('Mail Management')",
},
{
content: "Referenced by",
trigger:
"div.js_question-wrapper:contains('Referenced by') span:contains('Other:')",
},
{
content: "Referenced by: other",
trigger: "div.o_survey_comment_container textarea",
run: "text Mr. Odoo",
},
{
content: "Click Submit",
trigger: "button[value='finish']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ def test_sale_generation(self):
info_message, *_ = self.generated_sale.message_ids
# Some other survey inputs can be annotated in the quotation chatter
self.assertTrue("[email protected]" in info_message.body)
self.assertEqual("Mr. Odoo", self.generated_sale.origin)
2 changes: 2 additions & 0 deletions survey_sale_generation/views/survey_question_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
name="show_in_sale_order_comment"
attrs="{'invisible': [('question_type', 'in', ['matrix', 'simple_choice', 'multiple_choice'])]}"
/>
<field name="sale_order_field" widget="selection" />
<field name="allowed_sale_order_field_ids" invisible="1" />
</group>
</xpath>
</field>
Expand Down

0 comments on commit 0f5ad75

Please sign in to comment.