Merge pull request #1690 from expsa/odex25_realstate_dev

[Add] electricity service in rental contract
This commit is contained in:
esraa8mostafa 2024-11-05 12:17:49 +02:00 committed by GitHub
commit 2bb29266fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 31 deletions

View File

@ -68,7 +68,6 @@ class RentalContract(models.Model):
_inherit = ['mail.thread', 'mail.activity.mixin'] _inherit = ['mail.thread', 'mail.activity.mixin']
_order = "id desc" _order = "id desc"
@api.depends('date_to', 'state') @api.depends('date_to', 'state')
def _compute_is_today_end_date(self): def _compute_is_today_end_date(self):
for record in self: for record in self:
@ -110,9 +109,8 @@ class RentalContract(models.Model):
if not self.property_id: if not self.property_id:
self.property_id = False self.property_id = False
active = fields.Boolean(default=True) 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") name = fields.Char(string="Name")
date = fields.Date(string="Contract Date") date = fields.Date(string="Contract Date")
seq = fields.Char(string="Sequence", default="/", index=True) 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) ('user_type_id.id', '=', self.env.ref('account.data_account_type_receivable').id)], store=True)
# Debit # Debit
accrued_account_id = fields.Many2one('account.account', string="Accrued Account", domain=lambda self: [ 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: [ 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, ('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) self.env.ref('account.data_account_type_other_income').id))], store=True)
@ -347,7 +348,7 @@ class RentalContract(models.Model):
def action_confirm(self): def action_confirm(self):
invoice_vals = self._prepare_invoice_values(self, self.insurance_amount) 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) invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid)
# Get the ID of the second line # Get the ID of the second line
line_id = invoice.invoice_line_ids[1].id line_id = invoice.invoice_line_ids[1].id
@ -372,7 +373,7 @@ class RentalContract(models.Model):
def action_review(self): def action_review(self):
full = True 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")) raise exceptions.ValidationError(_("Property is already reserved or rented"))
# #
for units in self.property_id.unit_ids: 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 self.insurance_amount = (self.insurance_cost / 100.0) * self.cal_rent_amount
elif self.insurance and self.insurance == 'fixed': elif self.insurance and self.insurance == 'fixed':
self.insurance_amount = self.insurance_cost self.insurance_amount = self.insurance_cost
def action_draft(self): def action_draft(self):
self.write({'state': 'draft'}) self.write({'state': 'draft'})
@ -581,11 +583,12 @@ class RentalContract(models.Model):
rent_amount_per_payment = self.cal_rent_amount / (rent_factor / months) rent_amount_per_payment = self.cal_rent_amount / (rent_factor / months)
water_amount_per_payment = self.water_cost / (rent_factor / service_months) water_amount_per_payment = self.water_cost / (rent_factor / service_months)
services_amount_per_payment = self.service_amount / (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 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) total_amount = round(untaxed_amount + tax_amount, 2)
next_date = date_from next_date = date_from
service_next_date = date_from service_next_date = date_from
payment = 0 payment = 0
@ -601,21 +604,21 @@ class RentalContract(models.Model):
self._cr.execute('INSERT INTO rent_payment \ 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) \ (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', VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id',
( (
_('Payment %s') % (payment + 1), _('Payment %s') % (payment + 1),
self.id, self.id,
next_date.strftime('%Y-%m-%d'), next_date.strftime('%Y-%m-%d'),
self.property_id.id, self.property_id.id,
rent_amount_per_payment, rent_amount_per_payment,
water_amount_per_payment if payment < no_services_payment else 0.0, water_amount_per_payment if payment < no_services_payment else 0.0,
services_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.user_id.id,
self.env.user.company_id.id, self.env.user.company_id.id,
'draft', 'draft',
self.tax_id.id if self.tax_id else None, # Handle None value for tax_id self.tax_id.id if self.tax_id else None, # Handle None value for tax_id
untaxed_amount, untaxed_amount,
tax_amount tax_amount
)) ))
# Move to the next payment date # Move to the next payment date
next_date += relativedelta(months=months) next_date += relativedelta(months=months)
payment += 1 payment += 1

View File

@ -35,11 +35,11 @@
<group string="Payment Details"> <group string="Payment Details">
<field name="name" readonly="1"/> <field name="name" readonly="1"/>
<field name="amount" readonly="1"/> <field name="amount" readonly="1"/>
<field name="electricity_cost" readonly="1"/>
<field name="sanitation_cost" readonly="1"/>
<field name="water_cost" readonly="1"/> <field name="water_cost" readonly="1"/>
<field name="service_cost" readonly="1"/> <field name="service_cost" readonly="1"/>
<field name="service_note" readonly="1"/> <field name="service_note" readonly="1"/>
<field name="electricity_cost" readonly="1"/>
<field name="sanitation_cost" readonly="1"/>
<field name="profit" invisible="1"/> <field name="profit" invisible="1"/>
<field name="untaxed_amount" readonly="1" invisible="0"/> <field name="untaxed_amount" readonly="1" invisible="0"/>
<field name="tax_id" readonly="1"/> <field name="tax_id" readonly="1"/>

View File

@ -123,17 +123,16 @@
<group> <group>
<group string="Contract Service"> <group string="Contract Service">
<!-- <field name="separate_service"/>--> <!-- <field name="separate_service"/>-->
<label for="service"/>
<field name="electricity_cost" <field name="electricity_cost"
attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/> attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/>
<field name="sanitation_cost" <field name="sanitation_cost"
attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/> attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/>
<field name="water_cost"/>
<field name="service" attrs="{'readonly':[('state','!=','draft')]}"/> <field name="service" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="service_cost" <field name="service_cost"
attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/> attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/>
<field name="service_note"/> <field name="service_note"/>
<field name="service_amount" readonly="1"/> <field name="service_amount" readonly="1"/>
<field name="water_cost"/>
<field name="tax_id"/> <field name="tax_id"/>
<div attrs="{'invisible': [('management_type', '!=', 'included')]}"> <div attrs="{'invisible': [('management_type', '!=', 'included')]}">
<field name="company_profit" <field name="company_profit"
@ -194,11 +193,11 @@
<field name="name" readonly="1"/> <field name="name" readonly="1"/>
<field name="due_date" readonly="1"/> <field name="due_date" readonly="1"/>
<field name="amount" sum="Rent Amount" readonly="1"/> <field name="amount" sum="Rent Amount" readonly="1"/>
<field name="electricity_cost" sum="Electricity Cost" readonly="1"/>
<field name="sanitation_cost" sum="Sanitation Cost" readonly="1"/>
<field name="water_cost" sum="Water Amount" readonly="1"/> <field name="water_cost" sum="Water Amount" readonly="1"/>
<field name="service_cost" sum="Service Amount" readonly="1"/> <field name="service_cost" sum="Service Amount" readonly="1"/>
<field name="service_note" readonly="1"/> <field name="service_note" readonly="1"/>
<field name="sanitation_cost" sum="Sanitation Cost" readonly="1"/>
<field name="electricity_cost" sum="Electricity Cost" readonly="1"/>
<field name="tax_id" required="1"/> <field name="tax_id" required="1"/>
<field name="untaxed_amount" sum="Untaxed Amount" readonly="1"/> <field name="untaxed_amount" sum="Untaxed Amount" readonly="1"/>
<field name="tax_amount" sum="Tax Amount" readonly="1"/> <field name="tax_amount" sum="Tax Amount" readonly="1"/>