Merge pull request #1685 from expsa/odex25_realstate_dev

[Add] electricity service in rental contract
This commit is contained in:
esraa8mostafa 2024-11-04 13:47:21 +02:00 committed by GitHub
commit 7eec114a88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 162 additions and 81 deletions

View File

@ -633,11 +633,24 @@ msgstr "رقم سند سداد الكهرباء"
msgid "Electric Read" msgid "Electric Read"
msgstr "قراءة العداد" msgstr "قراءة العداد"
#. module: property_management
#: code:addons/property_management/models/rent_payment.py:0
#: model:ir.model.fields,field_description:property_management.field_rent_payment__electricity_cost
#: model_terms:ir.ui.view,arch_db:property_management.rental_contract_form_view
#, python-format
msgid "Electricity Cost"
msgstr "قيمة خدمة الكهرباء"
#. module: property_management #. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rental_contract__electricity_meter_no #: model:ir.model.fields,field_description:property_management.field_rental_contract__electricity_meter_no
msgid "Electricity Meter No." msgid "Electricity Meter No."
msgstr "رقم عداد الكهرباء" msgstr "رقم عداد الكهرباء"
#. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rental_contract__electricity_cost
msgid "Electricity cost"
msgstr "قيمة خدمة الكهرباء"
#. module: property_management #. module: property_management
#: model:ir.model.fields,field_description:property_management.field_end_rent_line__end_rent_id #: model:ir.model.fields,field_description:property_management.field_end_rent_line__end_rent_id
msgid "End Contract" msgid "End Contract"
@ -1893,6 +1906,15 @@ msgstr "مراجعة"
msgid "SMS Delivery error" msgid "SMS Delivery error"
msgstr "خطأ في تسليم الرسائل القصيرة" msgstr "خطأ في تسليم الرسائل القصيرة"
#. module: property_management
#: code:addons/property_management/models/rent_payment.py:0
#: model:ir.model.fields,field_description:property_management.field_rent_payment__sanitation_cost
#: model:ir.model.fields,field_description:property_management.field_rental_contract__sanitation_cost
#: model_terms:ir.ui.view,arch_db:property_management.rental_contract_form_view
#, python-format
msgid "Sanitation Cost"
msgstr "قيمة خدمة الصرف الصحي"
#. module: property_management #. module: property_management
#: model_terms:ir.ui.view,arch_db:property_management.property_maintenance_filter_view #: model_terms:ir.ui.view,arch_db:property_management.property_maintenance_filter_view
#: model_terms:ir.ui.view,arch_db:property_management.rent_end__filter_view #: model_terms:ir.ui.view,arch_db:property_management.rent_end__filter_view
@ -1917,7 +1939,7 @@ msgstr "متسلسل"
#. module: property_management #. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rental_contract__service #: model:ir.model.fields,field_description:property_management.field_rental_contract__service
msgid "Service" msgid "Service"
msgstr "خدمة" msgstr "خدمات أخرى"
#. module: property_management #. module: property_management
#: model:ir.model.fields,field_description:property_management.field_end_of_rent__service_amount #: model:ir.model.fields,field_description:property_management.field_end_of_rent__service_amount
@ -1930,11 +1952,21 @@ msgstr "قيمة الخدمات"
msgid "Service Cost" msgid "Service Cost"
msgstr "قيمة الخدمات" msgstr "قيمة الخدمات"
#. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rent_payment__service_note
msgid "Service Note"
msgstr "وصف الخدمة"
#. module: property_management #. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rental_contract__is_services #: model:ir.model.fields,field_description:property_management.field_rental_contract__is_services
msgid "Services Exist?" msgid "Services Exist?"
msgstr "توجد خدمات؟" msgstr "توجد خدمات؟"
#. module: property_management
#: model:ir.model.fields,field_description:property_management.field_rental_contract__service_note
msgid "Services Notes"
msgstr "وصف الخدمة"
#. module: property_management #. module: property_management
#: code:addons/property_management/models/rent_payment.py:0 #: code:addons/property_management/models/rent_payment.py:0
#, python-format #, python-format

View File

@ -12,6 +12,7 @@ from odoo.addons.property_management.models import amount_to_text_ar
from odoo.exceptions import UserError from odoo.exceptions import UserError
from datetime import datetime, timedelta from datetime import datetime, timedelta
class RentPayment(models.Model): class RentPayment(models.Model):
_name = "rent.payment" _name = "rent.payment"
_description = "Rental Contract Payment" _description = "Rental Contract Payment"
@ -40,6 +41,10 @@ class RentPayment(models.Model):
amount = fields.Float(string="Amount") amount = fields.Float(string="Amount")
water_cost = fields.Float(string="Water Cost") water_cost = fields.Float(string="Water Cost")
service_cost = fields.Float(string="Service Cost") service_cost = fields.Float(string="Service Cost")
service_note = fields.Char(string="Service Note", related='contract_id.service_note')
electricity_cost = fields.Float(string="Electricity Cost", related='contract_id.electricity_cost')
sanitation_cost = fields.Float('Sanitation Cost', related='contract_id.sanitation_cost')
profit = fields.Float(string="Profit") profit = fields.Float(string="Profit")
tax_id = fields.Many2one('account.tax', string="Tax") tax_id = fields.Many2one('account.tax', string="Tax")
untaxed_amount = fields.Float(string="Untaxed Amount", compute="get_untaxed_amount", store=True) untaxed_amount = fields.Float(string="Untaxed Amount", compute="get_untaxed_amount", store=True)
@ -60,8 +65,10 @@ class RentPayment(models.Model):
@api.depends('total_amount') @api.depends('total_amount')
def _compute_commission_amount(self): def _compute_commission_amount(self):
for record in self: for record in self:
commission_percentage = self.env['ir.config_parameter'].sudo().get_param('property_management.commission_percentage') commission_percentage = self.env['ir.config_parameter'].sudo().get_param(
record.commission_amount = record.total_amount * (commission_percentage / 100) if commission_percentage else 0 'property_management.commission_percentage')
record.commission_amount = record.total_amount * (
commission_percentage / 100) if commission_percentage else 0
@api.depends('contract_id') @api.depends('contract_id')
def _compute_renter(self): def _compute_renter(self):
@ -90,7 +97,6 @@ class RentPayment(models.Model):
rec.paid_date = payment_obj.date rec.paid_date = payment_obj.date
return res return res
@api.depends('invoice_id', 'invoice_id.state', 'invoice_id.payment_state', 'invoice_id.amount_residual') @api.depends('invoice_id', 'invoice_id.state', 'invoice_id.payment_state', 'invoice_id.amount_residual')
def get_invoice_state(self): def get_invoice_state(self):
self.paid = False self.paid = False
@ -103,7 +109,6 @@ class RentPayment(models.Model):
payment_obj = self.env['account.payment'].search([('ref', '=', rec.invoice_id.name)], limit=1) payment_obj = self.env['account.payment'].search([('ref', '=', rec.invoice_id.name)], limit=1)
rec.paid_date = payment_obj.date rec.paid_date = payment_obj.date
def _prepare_invoice_values(self, payment, amount): def _prepare_invoice_values(self, payment, amount):
self.renter_id.property_account_receivable_id = payment.contract_id.debit_account_id.id self.renter_id.property_account_receivable_id = payment.contract_id.debit_account_id.id
@ -113,7 +118,9 @@ class RentPayment(models.Model):
if payment.amount > 0.00: if payment.amount > 0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name':_('Reant Amount ') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'name': _('Reant Amount ') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'quantity': 1.0, 'quantity': 1.0,
'price_unit': self.amount, 'price_unit': self.amount,
'account_id': payment.contract_id.revenue_account_id.id, 'account_id': payment.contract_id.revenue_account_id.id,
@ -122,7 +129,9 @@ class RentPayment(models.Model):
})) }))
if payment.water_cost > 0.00: if payment.water_cost > 0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name': _('Water Cost ')+ ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'name': _('Water Cost ') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'price_unit': self.water_cost, 'price_unit': self.water_cost,
'quantity': 1.0, 'quantity': 1.0,
'account_id': payment.contract_id.revenue_account_id.id, 'account_id': payment.contract_id.revenue_account_id.id,
@ -131,16 +140,42 @@ class RentPayment(models.Model):
}), ) }), )
if payment.service_cost > 0.00: if payment.service_cost > 0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name': _('Serviecs Cost') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'name': _('Serviecs Cost') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'price_unit': self.service_cost, 'price_unit': self.service_cost,
'quantity': 1.0, 'quantity': 1.0,
'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False,
'account_id': payment.contract_id.revenue_account_id.id, 'account_id': payment.contract_id.revenue_account_id.id,
'tax_ids': [(6, 0, [payment.tax_id.id])] if payment.tax_id else False, # Assigning tax_id to tax_ids 'tax_ids': [(6, 0, [payment.tax_id.id])] if payment.tax_id else False, # Assigning tax_id to tax_ids
})) }))
if payment.electricity_cost > 0.00:
line_invoice.append((0, 0, {
'name': _('Electricity Cost') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'price_unit': self.electricity_cost,
'quantity': 1.0,
'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False,
'account_id': payment.contract_id.revenue_account_id.id,
'tax_ids': [(6, 0, [payment.tax_id.id])] if payment.tax_id else False, # Assigning tax_id to tax_ids
}))
if payment.sanitation_cost > 0.00:
line_invoice.append((0, 0, {
'name': _('Sanitation Cost') + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'price_unit': self.sanitation_cost,
'quantity': 1.0,
'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False,
'account_id': payment.contract_id.revenue_account_id.id,
'tax_ids': [(6, 0, [payment.tax_id.id])] if payment.tax_id else False, # Assigning tax_id to tax_ids
}))
if payment.amount == 0.00 and payment.service_cost == 0.00 and payment.water_cost == 0.00: if payment.amount == 0.00 and payment.service_cost == 0.00 and payment.water_cost == 0.00:
line_invoice.append((0, 0, { line_invoice.append((0, 0, {
'name': self.name + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'name': self.name + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(
self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(
payment.code or '') + ' - ' + str(payment.due_date or ''),
'price_unit': self.total_amount, 'price_unit': self.total_amount,
'quantity': 1.0, 'quantity': 1.0,
'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False,
@ -171,15 +206,14 @@ class RentPayment(models.Model):
'partner_id': payment.contract_id.partner_id.id, 'partner_id': payment.contract_id.partner_id.id,
'invoice_line_ids': line_invoice, 'invoice_line_ids': line_invoice,
# 'tax_ids': [(6, 0, [payment.tax_id.id])], # 'tax_ids': [(6, 0, [payment.tax_id.id])],
} }
return invoice_vals return invoice_vals
def action_invoice(self): def action_invoice(self):
if not self.contract_id.accrued_account_id: if not self.contract_id.accrued_account_id:
raise exceptions.ValidationError(_("Kindly, Contact Your Account Manager to set Income Account in contract account page")) raise exceptions.ValidationError(
_("Kindly, Contact Your Account Manager to set Income Account in contract account page"))
invoice_vals = self._prepare_invoice_values(self, self.total_amount) invoice_vals = self._prepare_invoice_values(self, self.total_amount)
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
@ -248,6 +282,7 @@ class RentPayment(models.Model):
record.write({"state": 'due'}) record.write({"state": 'due'})
else: else:
raise exceptions.ValidationError(_("You Must Confirm Contract First")) raise exceptions.ValidationError(_("You Must Confirm Contract First"))
def _check_due_payments(self): def _check_due_payments(self):
payments = self.search([('state', '=', 'draft'), ('due_date', '<=', fields.Date.today())]) payments = self.search([('state', '=', 'draft'), ('due_date', '<=', fields.Date.today())])
for payment in payments: for payment in payments:
@ -256,6 +291,7 @@ class RentPayment(models.Model):
if payment.code == '/' or not payment.code: if payment.code == '/' or not payment.code:
code = self.env['ir.sequence'].next_by_code('rent.payment') or '/' code = self.env['ir.sequence'].next_by_code('rent.payment') or '/'
payment.write({'code': code}) payment.write({'code': code})
def _send_payment_notifications(self): def _send_payment_notifications(self):
today = fields.Date.today() today = fields.Date.today()
next_week = today + timedelta(days=7) next_week = today + timedelta(days=7)
@ -274,7 +310,8 @@ class RentPayment(models.Model):
email_to = ','.join(email_list) email_to = ','.join(email_list)
payment.message_post_with_template(template_today.id) payment.message_post_with_template(template_today.id)
if template_today: if template_today:
template_today.send_mail(payment.id, force_send=True,raise_exception=True,email_values={'email_to': email_to}) template_today.send_mail(payment.id, force_send=True, raise_exception=True,
email_values={'email_to': email_to})
payment.sudo().activity_schedule( payment.sudo().activity_schedule(
'mail.mail_activity_data_todo', date_deadline, 'mail.mail_activity_data_todo', date_deadline,
note=note, note=note,
@ -297,7 +334,8 @@ class RentPayment(models.Model):
email_to = ','.join(email_list) email_to = ','.join(email_list)
payment.message_post_with_template(template_next_week.id) payment.message_post_with_template(template_next_week.id)
if template_next_week: if template_next_week:
template_next_week.send_mail(payment.id, force_send=True,raise_exception=True,email_values={'email_to':email_to}) template_next_week.send_mail(payment.id, force_send=True, raise_exception=True,
email_values={'email_to': email_to})
payment.sudo().activity_schedule( payment.sudo().activity_schedule(
'mail.mail_activity_data_todo', date_deadline, 'mail.mail_activity_data_todo', date_deadline,
note=note, note=note,
@ -314,7 +352,6 @@ class RentPayment(models.Model):
) )
return True return True
def action_validate(self): def action_validate(self):
for record in self: for record in self:
if record.contract_id.state == 'confirm': if record.contract_id.state == 'confirm':
@ -334,7 +371,6 @@ class RentPayment(models.Model):
else: else:
raise exceptions.ValidationError(_("You Must Confirm Contract First")) raise exceptions.ValidationError(_("You Must Confirm Contract First"))
# @api.depends('untaxed_amount', 'tax_id', 'tax_id.amount') # @api.depends('untaxed_amount', 'tax_id', 'tax_id.amount')
# def get_tax_amount(self): # def get_tax_amount(self):
# for rec in self: # for rec in self:
@ -344,11 +380,14 @@ class RentPayment(models.Model):
@api.depends('amount', 'water_cost', 'service_cost', 'tax_id') @api.depends('amount', 'water_cost', 'service_cost', 'tax_id')
def get_untaxed_amount(self): def get_untaxed_amount(self):
for rec in self: for rec in self:
rec.untaxed_amount = round(rec.amount + rec.water_cost + rec.service_cost,2) rec.untaxed_amount = round(
rec.amount + rec.water_cost + rec.service_cost + rec.electricity_cost + rec.sanitation_cost, 2)
rec.tax_amount = round(rec.tax_id.amount / 100 * rec.amount, 2) rec.tax_amount = round(rec.tax_id.amount / 100 * rec.amount, 2)
@api.depends('amount', 'water_cost', 'service_cost', 'tax_id') @api.depends('amount', 'water_cost', 'service_cost', 'tax_id')
def get_total_amount(self): def get_total_amount(self):
for rec in self: for rec in self:
rec.total_amount = round(rec.untaxed_amount + rec.tax_amount, 2) rec.total_amount = round(rec.untaxed_amount + rec.tax_amount, 2)
commission_percentage = float(self.env['ir.config_parameter'].sudo().get_param('property_management.commission_percentage')) commission_percentage = float(
self.env['ir.config_parameter'].sudo().get_param('property_management.commission_percentage'))
rec.commission_amount = rec.total_amount * (commission_percentage) if commission_percentage else 0 rec.commission_amount = rec.total_amount * (commission_percentage) if commission_percentage else 0

View File

@ -149,8 +149,11 @@ class RentalContract(models.Model):
rent_type = fields.Many2one('rent.type', string="Rent Type") rent_type = fields.Many2one('rent.type', string="Rent Type")
space = fields.Float(string="Space", compute="get_property_unit_space", store=True) space = fields.Float(string="Space", compute="get_property_unit_space", store=True)
service = fields.Selection([('fixed', 'Fixed'), ('percentage', 'Percentage')], string="Service") service = fields.Selection([('fixed', 'Fixed'), ('percentage', 'Percentage')], string="Service")
service_note = fields.Char('Services Notes')
service_cost = fields.Float(string="service cost") service_cost = fields.Float(string="service cost")
service_amount = fields.Float(string="service amount", compute="compute_service_amount", store=True) service_amount = fields.Float(string="service amount", compute="compute_service_amount", store=True)
electricity_cost = fields.Float('Electricity cost')
sanitation_cost = fields.Float('Sanitation Cost')
management_type = fields.Selection(related="property_id.management_type", string="Management Type") management_type = fields.Selection(related="property_id.management_type", string="Management Type")
property_state_id = fields.Many2one('re.property.state', related="property_id.property_state_id") property_state_id = fields.Many2one('re.property.state', related="property_id.property_state_id")
property_type_id = fields.Many2one('internal.property.type', related="property_id.property_type_id", string="Type") property_type_id = fields.Many2one('internal.property.type', related="property_id.property_type_id", string="Type")

View File

@ -37,6 +37,9 @@
<field name="amount" readonly="1"/> <field name="amount" 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="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"/>
@ -84,6 +87,7 @@
<field name="commission_amount" sum="Total Commission"/> <field name="commission_amount" sum="Total Commission"/>
<field name="water_cost" sum="Total Water Cost"/> <field name="water_cost" sum="Total Water Cost"/>
<field name="service_cost" sum="Total Service Cost"/> <field name="service_cost" sum="Total Service Cost"/>
<field name="service_note"/>
<field name="state"/> <field name="state"/>
</tree> </tree>
</field> </field>

View File

@ -124,15 +124,15 @@
<group string="Contract Service"> <group string="Contract Service">
<!-- <field name="separate_service"/>--> <!-- <field name="separate_service"/>-->
<label for="service"/> <label for="service"/>
<div> <field name="electricity_cost"
<field name="service" attrs="{'readonly':[('state','!=','draft')]}" attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/>
class="oe_inline"/>| <field name="sanitation_cost"
attrs="{'readonly':[('state', '!=', 'draft')], 'required':[('service','!=',False)]}"/>
<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)]}"/>
style="width:70px !important;" class="oe_inline"/>| <field name="service_note"/>
<field name="service_amount" readonly="1" <field name="service_amount" readonly="1"/>
class="oe_inline"/>
</div>
<field name="water_cost"/> <field name="water_cost"/>
<field name="tax_id"/> <field name="tax_id"/>
<div attrs="{'invisible': [('management_type', '!=', 'included')]}"> <div attrs="{'invisible': [('management_type', '!=', 'included')]}">
@ -196,6 +196,9 @@
<field name="amount" sum="Rent Amount" readonly="1"/> <field name="amount" sum="Rent Amount" 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="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"/>