RemiFr82
1 year ago
9 changed files with 244 additions and 113 deletions
-
147.gitignore
-
1event_question_sale/__init__.py
-
41event_question_sale/__manifest__.py
-
3event_question_sale/models/__init__.py
-
26event_question_sale/models/event_question.py
-
12event_question_sale/models/event_question_answer.py
-
66event_question_sale/models/event_question_answer_product.py
-
14event_question_sale/models/event_registration_answer.py
-
47event_question_sale/views/event_event.xml
@ -0,0 +1 @@ |
|||||
|
from . import models |
@ -0,0 +1,41 @@ |
|||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
{ |
||||
|
"name": "Event question sale", |
||||
|
"version": "1.0.0", |
||||
|
"summary": """ |
||||
|
Set booking order extra products on event question answers. |
||||
|
""", |
||||
|
"description": """ |
||||
|
This module extends the functionnalities of event questions and event tickets sale. |
||||
|
On the event questions you can check the box to be able to add on each answer, |
||||
|
zero, one or more extra products (giving price and qty) that will be added to the sale order. |
||||
|
For the questions asked once per registration, you can choose to add the extra products once or for each attendee. |
||||
|
""", |
||||
|
"author": "RemiFr82", |
||||
|
"contributors": "Hike2River", |
||||
|
"website": "https://remifr82.me", |
||||
|
"license": "LGPL-3", |
||||
|
"category": "Events", |
||||
|
# "price": 0, |
||||
|
# "currency": "EUR", |
||||
|
"application": False, |
||||
|
"installable": True, |
||||
|
"auto_install": False, |
||||
|
"pre_init_hook": "", |
||||
|
"post_init_hook": "", |
||||
|
"uninstall_hook": "", |
||||
|
"excludes": [], |
||||
|
"external_dependencies": [], |
||||
|
"depends": [ |
||||
|
"website_event_questions", |
||||
|
"website_event_sale", |
||||
|
], |
||||
|
"data": [], |
||||
|
"assets": {}, |
||||
|
"css": [], |
||||
|
"images": [], |
||||
|
"js": [], |
||||
|
"test": [], |
||||
|
"demo": [], |
||||
|
"maintainer": "RemiFr82", |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
from . import event_question_answer_product |
||||
|
from . import event_question_answer |
||||
|
from . import event_question |
@ -0,0 +1,26 @@ |
|||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
|
||||
|
class EventQuestion(models.Model): |
||||
|
_inherit = "event.question" |
||||
|
|
||||
|
add_products = fields.Boolean( |
||||
|
string="Add extra products on answers", |
||||
|
help="Checking this box allows", |
||||
|
) |
||||
|
qty_by_attendees = fields.Boolean( |
||||
|
string="Multiply quantity by attendees count", |
||||
|
help="For the questions asked only once per registration.\n" |
||||
|
"If checked, Odoo will add the extra product for each attendee.\n" |
||||
|
"Otherwise, Odoo will add the extra product only once.", |
||||
|
) |
||||
|
|
||||
|
@api.onchange("question_type") |
||||
|
def onchange_qtype(self): |
||||
|
if self.question_type != "simple_choice" and self.add_product: |
||||
|
self.add_product = False |
||||
|
|
||||
|
@api.onchange("once_per_order") |
||||
|
def onchange_qtype(self): |
||||
|
if not self.once_per_order and self.qty_by_attendees: |
||||
|
self.qty_by_attendees = False |
@ -0,0 +1,12 @@ |
|||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
|
||||
|
class EventQuestionAnswer(models.Model): |
||||
|
_inherit = "event.question.answer" |
||||
|
|
||||
|
extra_product_ids = fields.One2many( |
||||
|
comodel_name="event.question.answer.product", |
||||
|
inverse_name="answer_id", |
||||
|
string="Extra Products", |
||||
|
help="These producs will be added to the sale order of the booking with the given quantity and price.", |
||||
|
) |
@ -0,0 +1,66 @@ |
|||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
|
||||
|
class EventQuestionAnswerProduct(models.Model): |
||||
|
_name = "event.question.answer.product" |
||||
|
_rec_name = "product_id" |
||||
|
|
||||
|
answer_id = fields.Many2one( |
||||
|
comodel_name="event.question.answer", |
||||
|
string="Answer", |
||||
|
required=True, |
||||
|
ondelete="cascade", |
||||
|
) |
||||
|
product_id = fields.Many2one( |
||||
|
comodel_name="product.product", |
||||
|
string="Product variant", |
||||
|
) |
||||
|
price_unit = fields.Float( |
||||
|
string="Unit price", |
||||
|
digits="Product Price", |
||||
|
) |
||||
|
quantity = fields.Float( |
||||
|
string="Quantity", |
||||
|
digits="Product Unit of Measure", |
||||
|
) |
||||
|
uom_category_id = fields.Many2one( |
||||
|
related="product_id.uom_id.category_id", |
||||
|
depends=["product_id"], |
||||
|
) |
||||
|
uom_id = fields.Many2one( |
||||
|
comodel_name="uom.uom", |
||||
|
string="Unit of Measure", |
||||
|
compute="_compute_uom_id", |
||||
|
store=True, |
||||
|
readonly=False, |
||||
|
precompute=True, |
||||
|
ondelete="restrict", |
||||
|
domain="[('category_id', '=', uom_category_id)]", |
||||
|
) |
||||
|
|
||||
|
def name_get(self): |
||||
|
res = [] |
||||
|
for eqap in self: |
||||
|
res.append( |
||||
|
( |
||||
|
eqap.id, |
||||
|
_("{} x {} at {}").format( |
||||
|
eqap.quantity, |
||||
|
eqap.product_id.display_name, |
||||
|
eqap.answer_id.question_id.event_id.company_id.currency_id.format( |
||||
|
eqap.price_unit |
||||
|
), |
||||
|
), |
||||
|
) |
||||
|
) |
||||
|
return res |
||||
|
|
||||
|
@api.depends("product_id") |
||||
|
def _compute_uom_id(self): |
||||
|
for eqap in self: |
||||
|
product = eqap.product_id |
||||
|
uom = eqap.uom_id |
||||
|
if not product: |
||||
|
eqap.uom_id = False |
||||
|
elif not uom or (product.uom_id.id != uom.id): |
||||
|
eqap.uom_id = product.uom_id |
@ -0,0 +1,14 @@ |
|||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
|
||||
|
class EventRegistrationAnswer(models.Model): |
||||
|
_inherit = "event.registration.answer" |
||||
|
|
||||
|
extra_product_ids = fields.One2many(related="value_answer_id.extra_product_ids") |
||||
|
sale_order_line_ids = fields.Many2many( |
||||
|
comodel_name="sale.order.line", |
||||
|
column1="event_answer_id", |
||||
|
column2="sale_order_line_id", |
||||
|
relation="event_answer_sale_order_line_rel", |
||||
|
string="Related sale order lines", |
||||
|
) |
@ -0,0 +1,47 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
|
||||
|
<record id="event_event_view_form_inherit" model="ir.ui.view"> |
||||
|
<field name="name">event.event.view.form.inherit</field> |
||||
|
<field name="model">event.event</field> |
||||
|
<field name="inherit_id" ref="website_event_questions.event_event_view_form" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//field[@name='once_per_order']/.." position="attributes"> |
||||
|
<attribute name="class">o_label_nowrap</attribute> |
||||
|
</xpath> |
||||
|
<field name="once_per_order" position="after"> |
||||
|
<field name="add_products" /> |
||||
|
<field name="qty_by_attendees" /> |
||||
|
</field> |
||||
|
<xpath expr="//field[@name='question_ids']/form//tree" position="attributes"> |
||||
|
<attribute name="editable">0</attribute> |
||||
|
</xpath> |
||||
|
<xpath expr="//field[@name='question_ids']/form//tree" position="inside"> |
||||
|
<field name="extra_product_ids" widget="one2many" options="{'no_quick_create': 1}" |
||||
|
attrs="{'cdolumn_invisible':[('parent.add_products','!=',True)]}"> |
||||
|
<!-- <form> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="product_id" /> |
||||
|
<field name="price_unit" /> |
||||
|
</group> |
||||
|
<group> |
||||
|
<field name="quantity" /> |
||||
|
<field name="uom_id" /> |
||||
|
<field name="uom_category_id" invisible="1" /> |
||||
|
</group> |
||||
|
</group> |
||||
|
</form> --> |
||||
|
<tree editable="bottom"> |
||||
|
<field name="product_id" /> |
||||
|
<field name="price_unit" /> |
||||
|
<field name="quantity" /> |
||||
|
<field name="uom_id" /> |
||||
|
<field name="uom_category_id" invisible="1" /> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue