diff --git a/odex25_realstate/property_management/models/rental_contract.py b/odex25_realstate/property_management/models/rental_contract.py index c9cbc78c8..ab89edadd 100644 --- a/odex25_realstate/property_management/models/rental_contract.py +++ b/odex25_realstate/property_management/models/rental_contract.py @@ -68,7 +68,6 @@ class RentalContract(models.Model): _inherit = ['mail.thread', 'mail.activity.mixin'] _order = "id desc" - @api.depends('date_to', 'state') def _compute_is_today_end_date(self): for record in self: @@ -109,10 +108,9 @@ class RentalContract(models.Model): else: if not self.property_id: self.property_id = False - active = fields.Boolean(default=True) - is_today_end_date = fields.Boolean(string="Is Today End Date", compute="_compute_is_today_end_date",) + is_today_end_date = fields.Boolean(string="Is Today End Date", compute="_compute_is_today_end_date", ) name = fields.Char(string="Name") date = fields.Date(string="Contract Date") seq = fields.Char(string="Sequence", default="/", index=True) @@ -195,7 +193,10 @@ class RentalContract(models.Model): ('user_type_id.id', '=', self.env.ref('account.data_account_type_receivable').id)], store=True) # Debit accrued_account_id = fields.Many2one('account.account', string="Accrued Account", domain=lambda self: [ - ('user_type_id.id', 'in', (self.env.ref('account.data_account_type_current_liabilities').id,self.env.ref('account.data_account_type_non_current_liabilities').id,self.env.ref('account.data_account_type_revenue').id,self.env.ref('account.data_account_type_other_income').id))], store=True) + ('user_type_id.id', 'in', (self.env.ref('account.data_account_type_current_liabilities').id, + self.env.ref('account.data_account_type_non_current_liabilities').id, + self.env.ref('account.data_account_type_revenue').id, + self.env.ref('account.data_account_type_other_income').id))], store=True) revenue_account_id = fields.Many2one('account.account', string="Revenue Account", domain=lambda self: [ ('user_type_id.id', 'in', (self.env.ref('account.data_account_type_revenue').id, self.env.ref('account.data_account_type_other_income').id))], store=True) @@ -347,7 +348,7 @@ class RentalContract(models.Model): def action_confirm(self): invoice_vals = self._prepare_invoice_values(self, self.insurance_amount) - if self.insurance_amount>0.00 or self.insurance_cost>0.00: + if self.insurance_amount > 0.00 or self.insurance_cost > 0.00: invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) # Get the ID of the second line line_id = invoice.invoice_line_ids[1].id @@ -372,7 +373,7 @@ class RentalContract(models.Model): def action_review(self): full = True - if self.property_id.state in ['reserve', 'rent'] and self.property_id.contract_counts>1: + if self.property_id.state in ['reserve', 'rent'] and self.property_id.contract_counts > 1: raise exceptions.ValidationError(_("Property is already reserved or rented")) # for units in self.property_id.unit_ids: @@ -426,6 +427,7 @@ class RentalContract(models.Model): self.insurance_amount = (self.insurance_cost / 100.0) * self.cal_rent_amount elif self.insurance and self.insurance == 'fixed': self.insurance_amount = self.insurance_cost + def action_draft(self): self.write({'state': 'draft'}) @@ -581,11 +583,12 @@ class RentalContract(models.Model): rent_amount_per_payment = self.cal_rent_amount / (rent_factor / months) water_amount_per_payment = self.water_cost / (rent_factor / service_months) services_amount_per_payment = self.service_amount / (rent_factor / service_months) - untaxed_amount = round(rent_amount_per_payment + water_amount_per_payment + services_amount_per_payment, 2) + untaxed_amount = round( + rent_amount_per_payment + water_amount_per_payment + services_amount_per_payment + self.electricity_cost + self.sanitation_cost, + 2) tax_amount = round(self.tax_id.amount / 100 * rent_amount_per_payment, 2) if self.tax_id else 0.0 total_amount = round(untaxed_amount + tax_amount, 2) - - + next_date = date_from service_next_date = date_from payment = 0 @@ -597,25 +600,25 @@ class RentalContract(models.Model): if raise_line: rent_amount_per_payment = raise_line.rent_amount_after_raise / (rent_factor / months) # Calculate the amounts - + self._cr.execute('INSERT INTO rent_payment \ (name, contract_id, due_date, property_id, amount, water_cost, service_cost, user_id, company_id, state, tax_id, untaxed_amount, tax_amount) \ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id', - ( - _('Payment %s') % (payment + 1), - self.id, - next_date.strftime('%Y-%m-%d'), - self.property_id.id, - rent_amount_per_payment, - water_amount_per_payment if payment < no_services_payment else 0.0, - services_amount_per_payment if payment < no_services_payment else 0.0, - self.user_id.id, - self.env.user.company_id.id, - 'draft', - self.tax_id.id if self.tax_id else None, # Handle None value for tax_id - untaxed_amount, - tax_amount - )) + ( + _('Payment %s') % (payment + 1), + self.id, + next_date.strftime('%Y-%m-%d'), + self.property_id.id, + rent_amount_per_payment, + water_amount_per_payment if payment < no_services_payment else 0.0, + services_amount_per_payment if payment < no_services_payment else 0.0, + self.user_id.id, + self.env.user.company_id.id, + 'draft', + self.tax_id.id if self.tax_id else None, # Handle None value for tax_id + untaxed_amount, + tax_amount + )) # Move to the next payment date next_date += relativedelta(months=months) payment += 1 diff --git a/odex25_realstate/property_management/views/rent_payment_view.xml b/odex25_realstate/property_management/views/rent_payment_view.xml index fad866427..0f1ad8d2d 100644 --- a/odex25_realstate/property_management/views/rent_payment_view.xml +++ b/odex25_realstate/property_management/views/rent_payment_view.xml @@ -35,11 +35,11 @@ + + - - diff --git a/odex25_realstate/property_management/views/rental_contract_views.xml b/odex25_realstate/property_management/views/rental_contract_views.xml index 513db40c7..58ecbea76 100644 --- a/odex25_realstate/property_management/views/rental_contract_views.xml +++ b/odex25_realstate/property_management/views/rental_contract_views.xml @@ -123,17 +123,16 @@ -