Skip to content

Commit

Permalink
[IMP] survey_sale_generation: multiple choice multiplier
Browse files Browse the repository at this point in the history
TT40983
  • Loading branch information
chienandalu committed Aug 3, 2023
1 parent e432662 commit 2daf2a3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
9 changes: 5 additions & 4 deletions survey_sale_generation/demo/survey_sale_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,27 @@
</record>
<record model="survey.question" id="survey_support_q0">
<field name="survey_id" ref="survey_hire_support" />
<field name="sequence">0</field>
<field name="sequence">1</field>
<field name="title">E-mail address</field>
<field name="question_type">text_box</field>
<field name="show_in_sale_order_comment" eval="True" />
<field name="constr_mandatory" eval="True" />
</record>
<record model="survey.question" id="survey_support_q1">
<field name="survey_id" ref="survey_hire_support" />
<field name="sequence">1</field>
<field name="sequence">2</field>
<field name="title">How many hours will you hire monthly?</field>
<field name="question_type">numerical_box</field>
<field name="product_id" ref="support_hours" />
<field name="constr_mandatory" eval="True" />
</record>
<record model="survey.question" id="survey_support_q2">
<field name="survey_id" ref="survey_hire_support" />
<field name="sequence">2</field>
<field name="sequence">3</field>
<field name="title">Choose your subscription level</field>
<field name="question_type">simple_choice</field>
<field name="constr_mandatory" eval="True" />
<field name="product_uom_qty_question_id" ref="survey_support_q1" />
</record>
<record model="survey.question.answer" id="survey_support_q2_sug1">
<field name="question_id" ref="survey_support_q2" />
Expand All @@ -92,7 +93,7 @@
</record>
<record model="survey.question" id="survey_support_q3">
<field name="survey_id" ref="survey_hire_support" />
<field name="sequence">2</field>
<field name="sequence">5</field>
<field name="title">Choose your extras</field>
<field name="question_type">multiple_choice</field>
<field name="constr_mandatory" eval="False" />
Expand Down
7 changes: 7 additions & 0 deletions survey_sale_generation/models/survey_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class SurveyQuestion(models.Model):
_inherit = "survey.question"

product_id = fields.Many2one(comodel_name="product.product")
product_uom_qty_question_id = fields.Many2one(
comodel_name="survey.question",
help="For multiple answer questions we might want to consider how much of that "
"product we want to order. For example, one question could be: 'How many "
"members in your team?' and other could be 'Choose the membership type'. We'll "
"want to multiply members by memberships in our sale line.",
)
show_in_sale_order_comment = fields.Boolean()


Expand Down
9 changes: 7 additions & 2 deletions survey_sale_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SurveyUserInput(models.Model):

def _prepare_quotation(self):
return {
"partner_id": self.create_uid.partner_id.id,
"partner_id": self.partner_id.id or self.create_uid.partner_id.id,
"origin": self.survey_id.title,
"survey_user_input_id": self.id,
"company_id": self.create_uid.company_id.id,
Expand All @@ -24,7 +24,12 @@ def _prepare_quotation_line(self, input_line):
qty = input_line.value_numerical_box
else:
product_id = input_line.suggested_answer_id.product_id
qty = 1
# We can set a related question that will be the qty multiplier
qty_question = self.user_input_line_ids.filtered(
lambda x: x.question_id
== input_line.question_id.product_uom_qty_question_id
).value_numerical_box
qty = qty_question is not False and qty_question or 1
return {
"product_id": product_id.id,
"product_uom_qty": qty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_sale_generation(self):
"""
expected_lines = {
self.support_hours: 3,
self.gold_service: 1,
self.gold_service: 3,
self.advanced_backup: 1,
self.mail_management: 1,
}
Expand Down
9 changes: 9 additions & 0 deletions survey_sale_generation/views/survey_question_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
>
<field name="product_id" />
</group>
<group
name="Linked product"
attrs="{'invisible': [('question_type', 'not in', ['simple_choice', 'multiple_choice'])]}"
>
<field
name="product_uom_qty_question_id"
domain="[('survey_id', '=', survey_id), ('question_type', '=', 'numerical_box')]"
/>
</group>
</xpath>
<xpath expr="//field[@name='value']" position="after">
<field
Expand Down

0 comments on commit 2daf2a3

Please sign in to comment.