[ADD]ADD new tax for rent_payment and contract
This commit is contained in:
parent
b51a8756be
commit
1aed0baccf
|
|
@ -9,7 +9,7 @@ from dateutil.relativedelta import relativedelta
|
|||
from odoo.tools import exception_to_unicode
|
||||
from odoo import models, fields, api, exceptions, tools, _
|
||||
from odoo.addons.property_management.models import amount_to_text_ar
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class RentPayment(models.Model):
|
||||
_name = "rent.payment"
|
||||
|
|
@ -107,6 +107,7 @@ class RentPayment(models.Model):
|
|||
'price_unit': self.amount,
|
||||
'quantity': 1.0,
|
||||
'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.water_cost>0.00:
|
||||
line_invoice.append((0, 0, {
|
||||
|
|
@ -114,6 +115,7 @@ class RentPayment(models.Model):
|
|||
'price_unit':self.water_cost,
|
||||
'quantity': 1.0,
|
||||
'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.service_cost>0.00:
|
||||
line_invoice.append((0, 0, {
|
||||
|
|
@ -121,6 +123,7 @@ class RentPayment(models.Model):
|
|||
'price_unit': self.service_cost,
|
||||
'quantity': 1.0,
|
||||
'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:
|
||||
line_invoice.append((0, 0, {
|
||||
|
|
@ -128,6 +131,7 @@ class RentPayment(models.Model):
|
|||
'price_unit':self.total_amount,
|
||||
'quantity': 1.0,
|
||||
'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
|
||||
}))
|
||||
|
||||
# line_journal.append((0, 0, {
|
||||
|
|
@ -293,12 +297,12 @@ class RentPayment(models.Model):
|
|||
# tax_value = rec.tax_id.amount / 100
|
||||
# rec.tax_amount = rec.untaxed_amount * tax_value
|
||||
|
||||
@api.depends('amount', 'water_cost', 'service_cost')
|
||||
@api.depends('amount', 'water_cost', 'service_cost','tax_id')
|
||||
def get_untaxed_amount(self):
|
||||
for rec in self:
|
||||
rec.untaxed_amount = rec.amount + rec.water_cost + rec.service_cost
|
||||
|
||||
rec.untaxed_amount = round(rec.amount + rec.water_cost + rec.service_cost,2)
|
||||
rec.tax_amount = round(rec.tax_id.amount/100*rec.amount,2)
|
||||
@api.depends('amount', 'water_cost', 'service_cost')
|
||||
def get_total_amount(self):
|
||||
for rec in self:
|
||||
rec.total_amount = rec.amount + rec.water_cost + rec.service_cost
|
||||
rec.total_amount = round(rec.untaxed_amount + rec.tax_amount,2)
|
||||
|
|
@ -194,6 +194,19 @@ class RentalContract(models.Model):
|
|||
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')
|
||||
# Add Sales Tax Field
|
||||
tax_id = fields.Many2one('account.tax', string="Tax", domain=[('type_tax_use', '=', 'sale')])
|
||||
|
||||
@api.onchange('sales_tax_id')
|
||||
def _onchange_sales_tax_id(self):
|
||||
"""
|
||||
Apply the selected sales tax to all rent payments when a new tax is selected.
|
||||
"""
|
||||
for payment in self.rent_payment_ids:
|
||||
payment.tax_id = self.tax_id
|
||||
payment.get_untaxed_amount() # Recalculate amounts with the new tax
|
||||
payment.get_total_amount()
|
||||
|
||||
|
||||
def action_renew(self):
|
||||
"""
|
||||
|
|
@ -566,6 +579,7 @@ class RentalContract(models.Model):
|
|||
self.user_id.id,
|
||||
self.env.user.company_id.id,
|
||||
'draft',
|
||||
self.tax_id.id, # Include sales tax
|
||||
))
|
||||
|
||||
# Move to the next payment date
|
||||
|
|
|
|||
|
|
@ -38,8 +38,9 @@
|
|||
<field name="water_cost" readonly="1"/>
|
||||
<field name="service_cost" readonly="1"/>
|
||||
<field name="profit" invisible="1"/>
|
||||
<field name="untaxed_amount" readonly="1" invisible="1"/>
|
||||
<!-- <field name="tax_amount" readonly="1"/>-->
|
||||
<field name="untaxed_amount" readonly="1" invisible="0"/>
|
||||
<field name="tax_id" readonly="1"/>
|
||||
<field name="tax_amount" readonly="1"/>
|
||||
<field name="total_amount" readonly="1"/>
|
||||
<field name="amount_in_word" readonly="1"/>
|
||||
</group>
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@
|
|||
class="oe_inline"/>
|
||||
</div>
|
||||
<field name="water_cost"/>
|
||||
<field name="tax_id"/>
|
||||
<div attrs="{'invisible': [('management_type', '!=', 'included')]}">
|
||||
<field name="company_profit"
|
||||
attrs="{'readonly':[('state','not in',['draft','register'])],'required': [('management_type', 'in',('included'))]}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue