Skip to content

Commit

Permalink
[ADD] installment: added installment app
Browse files Browse the repository at this point in the history
After this commit:
- implemented installment module
- added wizard button in subscription module
  • Loading branch information
niku-odoo committed Sep 16, 2024
1 parent 3ffb31d commit 76e2878
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 0 deletions.
2 changes: 2 additions & 0 deletions installement/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
14 changes: 14 additions & 0 deletions installement/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
'name': 'Installement App',
'version': '17.0',
'depends': ['base', 'sale'],
'license': 'LGPL-3',
'data': [
'security/ir.model.access.csv',
'wizard/add_emi_button_wizard_views.xml',
'views/add_emi_button_views.xml',
'views/res_config_settings_views.xml'
],
'installable': True,
'application': True,
}
1 change: 1 addition & 0 deletions installement/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
26 changes: 26 additions & 0 deletions installement/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import models, fields


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

max_duration = fields.Float(
string="Max Duration", config_parameter='installement.max_duration')
annual_rate_percentage = fields.Float(
string='Annual Rate Percentage', config_parameter='installement.annual_rate_percentage')
down_payment_percentage = fields.Float(
string="Down Payment Percentage", config_parameter='installement.down_payment_percentage')
administrative_expenses_percentage = fields.Float(
string='Administrative Expenses Percentage', config_parameter='installement.administrative_expenses_percentage')
delay_penalty_percentage = fields.Float(
string="Delay Penalty Percentage", config_parameter='installement.delay_penalty_percentage')
delay_penalty_process = fields.Float(
string='Delay Penalty Process', config_parameter='installement.delay_penalty_process')

nid = fields.Boolean("Nid")
salary_component = fields.Boolean('Salary Component')
bank_statement = fields.Boolean('Bank Statement')
bank_rate_letter = fields.Boolean('Bank Rate Letter')
rental_contract = fields.Boolean('Rental Contract')
ownership_contract = fields.Boolean('Ownership Contract')
2 changes: 2 additions & 0 deletions installement/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_add_emi_button_wizard,access_add_emi_button_wizard,model_add_emi_button_wizard,base.group_user,1,1,1,1
16 changes: 16 additions & 0 deletions installement/views/add_emi_button_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="add_emi_button_views_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='so_button_below_order_lines']" position='inside'>
<button name="%(installement.add_emi_button_wizard_action)d"
type="action"
string="Add Emi"
class="btn btn-primary" />
</xpath>
</field>
</record>
</odoo>
62 changes: 62 additions & 0 deletions installement/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.base.setup</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="0" />
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//block[@name='integration']" position="after">
<block title="Installement Process" name="installement_process">
<setting id="max_duration" help="Define max duration">
<field name="max_duration" />
<a>Years</a>
</setting>
<setting id="annual_rate_percentage" help="Define Annual Rate Percentage">
<field name="annual_rate_percentage" />
<a>% Per Year</a>
</setting>
<setting id="down_payment_percentage" help="Define Down Payment Percentage">
<field name="down_payment_percentage" />
<a>% From Product Price</a>
</setting>
<setting id="administrative_expenses_percentage"
help="Define Administrative Expenses Percentage">
<field name="administrative_expenses_percentage" />
<a>% From Amount After D.Payment</a>
</setting>
<setting id="delay_penalty_percentage" help="Define Delay Penalty Percentage">
<field name="delay_penalty_percentage" />
<a>% From Monthly Amount</a>
</setting>
<setting id="delay_penalty_process" help="Define Delay Penalty Process">
<field name="delay_penalty_process" />
<a>Days</a>
<br />
<help>Delay penalty percentage will be applied after exceed the delay
process period. </help>
</setting>
</block>
<block title="Needed Documents" name="needed_documents">
<setting id="nid">
<field name="nid" />
</setting>
<setting id="salary_component">
<field name="salary_component" />
</setting>
<setting id="bank_statement">
<field name="bank_statement" />
</setting>
<setting id="bank_rate_letter">
<field name="bank_rate_letter" />
</setting>
<setting id="rental_contract">
<field name="rental_contract" />
</setting>
<setting id="ownership_contract">
<field name="ownership_contract" />
</setting>
</block>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions installement/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import add_emi_button_wizard
56 changes: 56 additions & 0 deletions installement/wizard/add_emi_button_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from odoo import models, fields, api


class AddEmiButtonWizard(models.TransientModel):

_name = "add.emi.button.wizard"
_description = "Add Emi Button Wizard"

total_sale_amount = fields.Float(
string="Total sale Amount", readonly=True)
down_payment = fields.Float(compute="_compute_values")
remaining_amount = fields.Float(compute="_compute_values")
interest = fields.Float(compute='_compute_values')
number_of_monthly_installement = fields.Integer(compute='_compute_values')
installement_amount = fields.Float(readonly=True)
admin_expense = fields.Float(compute='_compute_values')
remaining_amount_2 = fields.Float(compute='_compute_values')

def default_get(self, fields_list):
defaults = super().default_get(fields_list)
defaults['total_sale_amount'] = self.env['sale.order'].browse(
self.env.context.get('active_id')).amount_total
return defaults

@api.depends("total_sale_amount")
def _compute_values(self):
for rec in self:
down_payment_percent = self.env['ir.config_parameter'].get_param(
'installement.down_payment_percentage')
x = float(rec.total_sale_amount) * float(down_payment_percent)
rec.down_payment = x / 100

# remaining amount
rec.remaining_amount = rec.total_sale_amount - rec.down_payment

# admin expense
administrative_expenses_percentage = self.env['ir.config_parameter'].get_param(
'installement.administrative_expenses_percentage')
y = float(rec.remaining_amount) * \
float(administrative_expenses_percentage)
rec.admin_expense = y / 100

# toal remaining amount
rec.remaining_amount_2 = rec.remaining_amount + rec.admin_expense

annual_rate_percentage = self.env['ir.config_parameter'].get_param(
'installement.annual_rate_percentage')
z = float(rec.remaining_amount_2) * float(annual_rate_percentage)
rec.interest = z / 100

max_dur = float(self.env['ir.config_parameter'].get_param(
'installement.max_duration'))
rec.number_of_monthly_installement = float(max_dur) * 12

rec.installement_amount = (
rec.remaining_amount_2 + rec.interest)/rec.number_of_monthly_installement
34 changes: 34 additions & 0 deletions installement/wizard/add_emi_button_wizard_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<odoo>
<record id="add_emi_button_wizard_views_form" model="ir.ui.view">
<field name="name">add.emi.button.wizard.form</field>
<field name="model">add.emi.button.wizard</field>
<field name="arch" type="xml">
<form string='Add Offer'>
<sheet>
<group>
<field name="total_sale_amount" />
<field name="down_payment" />
<field name="remaining_amount" />
<field name="interest" />
<field name="number_of_monthly_installement" />
<field name="installement_amount" />
</group>
<footer>
<button name="add_installement" type='object' string='Add Installement'
class='btn-primary' />
<button string='Cancel' class='btn-secondary' special='cancel' />
</footer>
</sheet>
</form>
</field>
</record>

<record id="add_emi_button_wizard_action" model="ir.actions.act_window">
<field name="name">Add Emi Button</field>
<field name="res_model">add.emi.button.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="installement.add_emi_button_wizard_views_form" />
<field name="target">new</field>
</record>
</odoo>

0 comments on commit 76e2878

Please sign in to comment.