Odoo modules related to events management
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

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