[FIX] property_management: contract_type and tax_id should be computed and stored

This commit is contained in:
Samir Ladoui 2025-02-05 14:23:03 +01:00
parent de0cc68860
commit f22c0c47b2
1 changed files with 16 additions and 4 deletions

View File

@ -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