# -*- coding: utf-8 -*-

from itertools import count
from odoo import fields, models, api

class EstatePropertyType(models.Model):

    # ------------------ Private attributes ---------------------- 

    _name = "estate.property.type"
    _description = "Types of properties"
    _order = "name asc"

    # ------------------ Fields ---------------------- 

    name = fields.Char(required=True)
    property_ids = fields.One2many(comodel_name="estate.property", inverse_name="property_type_id")
    offer_ids = fields.One2many(comodel_name="estate.property.offer", inverse_name="property_type_id")
    offer_count = fields.Integer(compute="_compute_offer_count")

    # ------------------ Computed fields ---------------------- 

    @api.depends('offer_ids')
    def _compute_offer_count(self):
        for record in self:
            record.offer_count = len(record.mapped('offer_ids'))
