From f22c0c47b29b5d8aa52e75cfacd7882310333a0a Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Wed, 5 Feb 2025 14:23:03 +0100 Subject: [PATCH] [FIX] property_management: contract_type and tax_id should be computed and stored --- .../models/rental_contract.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/odex25_realstate/property_management/models/rental_contract.py b/odex25_realstate/property_management/models/rental_contract.py index 341c6ae3b..c00144cdc 100644 --- a/odex25_realstate/property_management/models/rental_contract.py +++ b/odex25_realstate/property_management/models/rental_contract.py @@ -129,7 +129,9 @@ class RentalContract(models.Model): unit_ids = fields.Many2many('re.unit', string="Units", tracking=True) contract_type = fields.Selection( [('residential', 'Residential'), ('commercial', 'Commercial'), ('lands', 'Lands')], - default=lambda self: self._get_default_contract_type() + compute="_compute_default_values", + readonly=False, + store=True ) partner_id = fields.Many2one('res.partner', string="Renter", domain=[('is_tenant', '=', True)]) identification_type = fields.Selection(related="partner_id.identification_type", string='Identification Type') @@ -229,8 +231,9 @@ class RentalContract(models.Model): 'account.tax', string="Tax", domain=[('type_tax_use', '=', 'sale')], - # compute='compute_tax_id' - default=lambda self: self._get_default_tax_id() + compute='_compute_default_values', + readonly=False, + store=True ) tax_amount = fields.Float(compute="_compute_amounts") total_amount_with_tax = fields.Float(compute="_compute_amounts") @@ -247,7 +250,16 @@ class RentalContract(models.Model): def _get_default_tax_id(self): self.tax_id = self.unit_ids[0].tax_id if self.unit_ids else False - + + @api.depends('unit_ids') + def _compute_default_values(self): + for rec in self: + if rec.unit_ids: + rec.contract_type = rec.unit_ids[0].unit_category + rec.tax_id = rec.unit_ids[0].tax_id + else: + rec.contract_type = rec.tax_id = False + # @api.onchange('unit_ids') # def compute_tax_id(self): # self.tax_id = self.unit_ids[0].tax_id if self.unit_ids else False