From 092aaf475924e3a1cd7806a7cdc118ea189f245e Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Wed, 22 Sep 2021 18:35:53 +0200 Subject: [PATCH] [IMP] pms: added link to room_type from the product --- pms/models/product_product.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pms/models/product_product.py b/pms/models/product_product.py index 2990f6ecd..bafb7fbcf 100644 --- a/pms/models/product_product.py +++ b/pms/models/product_product.py @@ -1,4 +1,5 @@ -from odoo import api, fields, models +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError class ProductProduct(models.Model): @@ -11,6 +12,12 @@ class ProductProduct(models.Model): compute="_compute_board_price", ) + room_type_id = fields.Many2one( + string="Room Type", + comodel_name="pms.room.type", + compute="_compute_room_type_id", + ) + @api.depends_context("consumption_date") def _compute_product_price(self): super(ProductProduct, self)._compute_product_price() @@ -35,6 +42,20 @@ class ProductProduct(models.Model): else: record.board_price = False + def _compute_room_type_id(self): + for rec in self: + room_type = self.env["pms.room.type"].search( + [ + ("product_id", "=", rec.id), + ] + ) + if room_type: + if len(room_type) > 1: + raise ValidationError( + _("More than one room found for the same product") + ) + rec.room_type_id = room_type + def price_compute(self, price_type, uom=False, currency=False, company=None): if self._context.get("board_service"): price_type = "board_price"