fix bug in planned num, update insurance paid

This commit is contained in:
esraa 2024-07-18 14:35:58 +03:00
parent 4b2653ed45
commit 5b4b2375ee
4 changed files with 19 additions and 35 deletions

View File

@ -9,7 +9,6 @@ from dateutil.relativedelta import relativedelta
from odoo.tools import exception_to_unicode
from odoo import models, fields, api, exceptions, tools, _
_logger = logging.getLogger(__name__)
@ -25,7 +24,6 @@ class Property(models.Model):
action_type = fields.Selection(selection_add=[('rent', 'Rent')])
class ResUnit(models.Model):
_inherit = "re.unit"
@ -91,7 +89,7 @@ class RentalContract(models.Model):
active = fields.Boolean(default=True)
name = fields.Char(string="Name")
date = fields.Date(string="Contract Date")
seq = fields.Char(string="Sequence", default="/",index=True)
seq = fields.Char(string="Sequence", default="/", index=True)
state = fields.Selection([('draft', 'Draft'),
('submit', 'Submit'),
('review', 'Review'),
@ -103,13 +101,15 @@ class RentalContract(models.Model):
residential_purpose_id = fields.Many2one('residential.purpose', string="Residential Purpose")
rent_method = fields.Selection([('property', 'Property'),
('unit', 'Unit')], string="Rent Method")
property_id = fields.Many2one('internal.property', string="Property",tracking=True)
unit_ids = fields.Many2many('re.unit', string="Units",tracking=True)
property_id = fields.Many2one('internal.property', string="Property", tracking=True)
unit_ids = fields.Many2many('re.unit', string="Units", tracking=True)
partner_id = fields.Many2one('res.partner', string="Renter")
identification_type = fields.Selection(related="partner_id.identification_type", string='Identification Type')
identification_number = fields.Char(related="partner_id.identification_number", string='Identification NUmber')
identification_issue_date = fields.Date(related="partner_id.identification_issue_date", string='Identification Issue Date')
identification_expiry_date = fields.Date(related="partner_id.identification_expiry_date", string='Identification Expiry Date')
identification_issue_date = fields.Date(related="partner_id.identification_issue_date",
string='Identification Issue Date')
identification_expiry_date = fields.Date(related="partner_id.identification_expiry_date",
string='Identification Expiry Date')
user_id = fields.Many2one('res.users', string="Responsible", default=lambda self: self.env.user.id)
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id)
@ -134,14 +134,14 @@ class RentalContract(models.Model):
street = fields.Char(string="Street Name", related="property_id.street")
check_insurance = fields.Boolean(string='Insurance?', default=False)
meter_price = fields.Float(string='Price Per Meter', compute="unit_property_meter_price", store=True)
cal_rent_amount = fields.Float(string='Calculated Rent Amount',compute="get_rent_amount", store=True)
cal_rent_amount = fields.Float(string='Calculated Rent Amount', compute="get_rent_amount", store=True)
rent_amount = fields.Float(string='Rent Amount')
original_rent_amount = fields.Float(string='Rent Amount')
insurance = fields.Selection([('fixed', 'Fixed'),
('percentage', 'Percentage')], string="Insurance", default="fixed")
insurance_cost = fields.Float(string="Insurance cost")
insurance_amount = fields.Float(string="Insurance Amount", compute="compute_insurance", store=True)
insurance_paid = fields.Float(string="Insurance Paid",compute="get_insurance_Paid", store=True)
insurance_paid = fields.Float(string="Insurance Paid", compute="get_insurance_paid")
is_services = fields.Boolean(string='Services Exist?', copy=False)
water_meter_no = fields.Char(string='Water Meter No.')
electricity_meter_no = fields.Char(string='Electricity Meter No.')
@ -149,7 +149,7 @@ class RentalContract(models.Model):
closed = fields.Boolean(string='Closed')
annual_raise_ids = fields.One2many('annual.raise', 'contract_id', string='Annual Raise', copy=False)
rent_payment_ids = fields.One2many('rent.payment', 'contract_id', string="Rent Payment")
insurance_invoice_id = fields.Many2one('account.move',string="Insurance Invoice")
insurance_invoice_id = fields.Many2one('account.move', string="Insurance Invoice")
external_broker = fields.Boolean(string="External Broker")
external_broker_id = fields.Many2one('res.partner', string="External Broker")
external_percent = fields.Float(string="External Broker Percent")
@ -182,7 +182,7 @@ class RentalContract(models.Model):
renew_done = fields.Boolean(string='Renew Completed', default=False)
renewed = fields.Boolean(string='Renewed Contract', default=False)
previous_contract_id = fields.Many2one('rental.contract', string='Previous Contract')
log_rental_contract_ids = fields.One2many('log.rental.contract','contract_id', string='Contract')
log_rental_contract_ids = fields.One2many('log.rental.contract', 'contract_id', string='Contract')
annual_raise_on_type = fields.Selection([('meter', _('Meter')), ('rent_amount', _('Rent amount'))],
_('الزيادة علي'), default='rent_amount')
@ -232,7 +232,6 @@ class RentalContract(models.Model):
'state': 'renewed'
})
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
self.ensure_one()
@ -244,7 +243,6 @@ class RentalContract(models.Model):
self.new_price = 0.0
self.rent_amount = 0.0
@api.depends('company_profit', 'company_profit_amount')
def _compute_company_profit_val(self):
for record in self:
@ -255,8 +253,6 @@ class RentalContract(models.Model):
else:
record.company_profit_val = 0.0
@api.constrains('unit_id')
def check_unit_state(self):
for unit in self.unit_ids:
@ -270,15 +266,15 @@ class RentalContract(models.Model):
def onchange_template(self):
self.template = self.template_id.template
@api.depends('insurance_invoice_id','insurance_invoice_id.amount_residual', 'insurance_amount')
@api.depends('insurance_invoice_id', 'insurance_invoice_id.amount_residual', 'insurance_amount')
def get_insurance_paid(self):
if self.insurance_invoice_id:
residual = self.insurance_invoice_id.amount_residual
self.insurance_paid = residual if residual != 0.0 else self.insurance_amount
residual = self.insurance_invoice_id.amount_total - self.insurance_invoice_id.amount_residual
self.insurance_paid = residual if residual != 0.0 else 0.0
def _prepare_invoice_values(self, contract, amount):
invoice_vals = {
'ref': _("Insurance payment for ")+contract.name,
'ref': _("Insurance payment for ") + contract.name,
'move_type': 'out_invoice',
'invoice_origin': contract.seq,
'invoice_user_id': contract.user_id.id,
@ -288,7 +284,7 @@ class RentalContract(models.Model):
'name': contract.name + ' - ' + contract.seq + ' - ' + str(contract.date),
'price_unit': amount,
'quantity': 1.0,
'account_id':contract.journal_id.default_account_id.id
'account_id': contract.journal_id.default_account_id.id
})],
}
@ -336,7 +332,7 @@ class RentalContract(models.Model):
if total_service != service_payment:
raise exceptions.ValidationError(
_("Service payment %s is not equal the rent total service amount %s ") % (
service_payment, total_service))
service_payment, total_service))
if total_water != water_payment:
raise exceptions.ValidationError(
_("Water cost to pay %s is not equal the rent total water cost %s ") % (water_payment, total_water))
@ -419,8 +415,6 @@ class RentalContract(models.Model):
rent_total = (self.space * rent_price / 365) / 24
self.cal_rent_amount = rent_total if self.rent_amount == 0.0 else self.rent_amount
@api.depends('rent_method', 'property_id.meter_price', 'property_id', 'unit_ids')
def unit_property_meter_price(self):
"""
@ -451,7 +445,6 @@ class RentalContract(models.Model):
total_space += unit.space
self.space = total_space
@api.depends('date_from', 'rent_duration', 'rent_kind')
def get_to_date(self):
if self.date_from and self.rent_duration and self.rent_kind:
@ -559,7 +552,7 @@ class RentalContract(models.Model):
str(self.user_id.id),
str(self.env.user.company_id.id),
str('draft'),
))
))
if self.rent_kind in ['month', 'year']:
next_date += relativedelta(months=months)
if date_to > next_date:
@ -593,7 +586,6 @@ class ResPartner(models.Model):
is_renter = fields.Boolean(string="Renter")
class LogRentalContract(models.Model):
_name = 'log.rental.contract'

View File

@ -212,11 +212,6 @@ msgstr "عدد الحمامات"
#. module: real_estate
#: model:ir.model.fields,field_description:real_estate.field_internal_property__block_no
msgid "Block Number"
msgstr "رقم المخطط"
#. module: real_estate
#: model:ir.model.fields,field_description:real_estate.field_internal_property__blok_no
msgid "Blok Number"
msgstr "رقم البلوك"
#. module: real_estate

View File

@ -81,7 +81,6 @@ class Property(models.Model):
property_face_ids = fields.Many2many('property.faces', string="Property Face")
user_id = fields.Many2one('res.users', string="Responsible", default=lambda self: self.env.user)
block_no = fields.Char(string="Block Number")
blok_no = fields.Char(string="Blok Number")
licence_no = fields.Char(string="Licence Number")
plate_no = fields.Char(string="Plate Number")
plot_no = fields.Char(string="Plot Number")

View File

@ -125,9 +125,7 @@
<field name="marketer_id" attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>
<field name="block_no" required="1"
attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>
<field name="blok_no" required="1"
attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>
<field name="licence_no" required="1"
<field name="licence_no" required="1"
attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>
<field name="plate_no"
attrs="{'readonly':[('state','!=','draft'),('unlock','=',True)]}"/>