Skip to content

Commit

Permalink
[ADD] installment: created new module and add features
Browse files Browse the repository at this point in the history
- Add setting section for installment
- Add wizard for Add EMI
- Add Button for document module redirect
  • Loading branch information
amya-odoo committed Sep 17, 2024
1 parent a688159 commit bb55acf
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 0 deletions.
2 changes: 2 additions & 0 deletions installment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
18 changes: 18 additions & 0 deletions installment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Installment",
"description": "Installment app",
"version": "0.1",
"category": "Sales/Sales",
"depends": ["base", "sale_subscription"],
"data": [
"security/ir.model.access.csv",
"wizard/add_emi_wizard.xml",
"views/installment_views.xml",
"views/res_config_settings_views.xml",
"views/installment_menuitem.xml",
"data/product_data.xml",
],
"application": True,
"installable": True,
"license": "LGPL-3",
}
12 changes: 12 additions & 0 deletions installment/data/product_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<data noupdate="1">
<record id="product_installment" model="product.product">
<field name="name">Installment</field>
<field name="detailed_type">service</field>
</record>
<record id="product_monthly" model="product.product">
<field name="name">Monthly</field>
<field name="detailed_type">service</field>
</record>
</data>
</odoo>
3 changes: 3 additions & 0 deletions installment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import installment_installment
from . import res_config_setting
from . import sale_order
5 changes: 5 additions & 0 deletions installment/models/installment_installment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from odoo import models, fields


class Installment(models.Model):
_name = "installment.installment"
20 changes: 20 additions & 0 deletions installment/models/res_config_setting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

max_duration = fields.Float(string="Max Duration", config_parameter = "installment.max_duration")
down_payment = fields.Integer(string="Down Payment Percentage", config_parameter = "installment.down_payment")
annual_rate = fields.Integer(string="Annual Rate Percentage", config_parameter = "installment.annual_rate")
administrative_expenses = fields.Integer(
string="Administrative Expenses Percentage", config_parameter = "installment.administrative_expenses"
)
delay_penalty_percentage = fields.Integer(string="Delay Penalty Percentage", config_parameter = "installment.delay_penalty_percentage")
delay_penalty_process = fields.Integer(string="Delay Penalty Process",config_parameter = "installment.delay_penalty_process")
nid = fields.Boolean(config_parameter = "installment.nid")
salary_components = fields.Boolean(string="Salary Components", config_parameter = "installment.salary_components")
bank_statement = fields.Boolean(string="Bank Statement", config_parameter = "installment.bank_statement")
bank_rate_letter = fields.Boolean(string="Bank Rate Letter", config_parameter = "installment.bank_rate_letter")
rental_contract = fields.Boolean(string="Rental Contract", config_parameter = "installment.rental_contract")
ownership_contract = fields.Boolean(string="Ownershp Contract", config_parameter = "installment.ownership_contract")
12 changes: 12 additions & 0 deletions installment/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models


class SalesOrder(models.Model):
_name = "sale.order"
_inherit = "sale.order"

def action_upload_documents(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"documents.document_action"
)
return action
3 changes: 3 additions & 0 deletions installment/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
installment.access_installment_installment,access_installment_installment,installment.model_installment_installment,base.group_user,1,1,1,1
installment.access_add_emi,access_add_emi,installment.model_add_emi,base.group_user,1,1,1,1
6 changes: 6 additions & 0 deletions installment/views/installment_menuitem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo>
<menuitem id="installment_root_menu" name="Installment"/>
<menuitem id="subscription_menu" name="Subscriptions" parent="installment_root_menu" action="action_installment" />
<menuitem id="installment_config_menu" name="Configuration" parent="installment_root_menu" />
<menuitem id="installment_config_settings_menu" name="Settings" parent="installment_config_menu" action="action_installment_config_settings"/>
</odoo>
26 changes: 26 additions & 0 deletions installment/views/installment_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<record id="action_installment" model="ir.actions.act_window">
<field name="name">Installment</field>
<field name="res_model">installment.installment</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Installment
</p>
</field>
</record>

<record id="view_installment" model="ir.ui.view">
<field name="name">Subscription</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_subscription.sale_subscription_order_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='so_button_below_order_lines']/button" position="before">
<button name="installment.action_add_emi" class="btn btn-primary" invisible="state not in ['draft']" string="Add EMI" type="action"/>
</xpath>
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button name="action_upload_documents" class="btn btn-primary " icon="fa-file-text" string="Document" type="object"/>
</xpath>
</field>
</record>
</odoo>
69 changes: 69 additions & 0 deletions installment/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<odoo>
<record id="res_config_settings_view_inherited_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//form" position="inside">
<app string="Installment" data-string="Installment" name="installemnt Setting">
<block title="Installment Process" name="installment_process">
<setting string="Max Duration" help=" Define Max Duration">
<field name="max_duration" style="width: 40%; min-width: 4rem;"/>
<span> years</span>
</setting>
<setting string="Anual Rate Percentage" help="Define Annual Rate Percentage">
<field name="annual_rate" style="width: 40%; min-width: 4rem;"/>
<span> %Per Years</span>
</setting>
<setting string="Down Payment" help=" Define Down Payment Percentage">
<field name="down_payment" style="width: 40%; min-width: 4rem;"/>
<span> %From Product Price</span>
</setting>
<setting string="Administrative Expenses Percentage" help="Define Administrative Expense Percentage">
<field name="administrative_expenses" style="width: 40%; min-width: 4rem;"/>
<span>%From Amount After D.Payment</span>
</setting>
<setting string="Delay Penalty Percentage" help="Define Delay Penalty Percentage">
<field name="delay_penalty_percentage" style="width: 40%; min-width: 4rem;"/>
<span>%From Monthly Amount</span>
</setting>
<setting string="Delay Penalty Process" help="Define Delay Penalty Process">
<field name="delay_penalty_process" style="width: 40%; min-width: 4rem;"/>
<span>Days</span>
<div class="text-muted">
Delay penalty percentqage will be applied after exceed the delay process period
</div>
</setting>
</block>
<block title="Needed Documents" name="needed_document">
<setting string="Nid">
<field name="nid"/>
</setting>
<setting string="Salary Components">
<field name="salary_components"/>
</setting>
<setting string="Bank Statement">
<field name="bank_statement"/>
</setting>
<setting string="Bank Rate Letter">
<field name="bank_rate_letter"/>
</setting>
<setting string="Rental Contract">
<field name="rental_contract"/>
</setting>
<setting string="Ownership Contract">
<field name="ownership_contract"/>
</setting>
</block>
</app>
</xpath>
</field>
</record>

<record id="action_installment_config_settings" model="ir.actions.act_window">
<field name="name">Settings</field>
<field name="res_model">res.config.settings</field>
<field name="view_id" ref="res_config_settings_view_inherited_form"/>
<field name="view_mode">form</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions installment/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import add_emi
82 changes: 82 additions & 0 deletions installment/wizard/add_emi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from odoo import models, fields, api, Command


class AddEmi(models.TransientModel):
_name = "add.emi"
total_so_amount = fields.Float(readonly=True)
down_payment = fields.Float(readonly=True)
remaining_amount = fields.Float(readonly=True)
interest = fields.Float(readonly=True)
number_monthly_installment = fields.Integer(readonly=True)
installement_amount = fields.Float(readonly=True)

@api.model
def default_get(self, fields):
res = super().default_get(fields) or {}
active_id = self.env.context["active_id"]
sale_order = self.env["sale.order"].browse(active_id)
config_param = self.env["ir.config_parameter"]
max_duration = float(
config_param.get_param("installment.max_duration", default=0.0)
)
down_payment_percentage = int(
config_param.get_param("installment.down_payment", default=0)
)
annual_rate = float(
config_param.get_param("installment.annual_rate", default=0.0)
)

administrative_expenses = float(
config_param.get_param("installment.administrative_expenses", default=0.0)
)
# Total
total = sale_order.amount_total
# Down Payment calculated
down_payment_evaluate = (down_payment_percentage / 100) * total
# Administrative Expenses
remaining = total - down_payment_evaluate
adminstrative_expense = (administrative_expenses / 100) * remaining
total_remaining = remaining + adminstrative_expense
# Annually Interest
annuall_intrest = ((annual_rate / 100) * total_remaining) * max_duration
total_remaining += annuall_intrest
# Installment Amount
installment_ammount = (total_remaining) / (max_duration * 12)
# print(annuall_intrest)
res.update(
{
"total_so_amount": sale_order.amount_total,
"down_payment": down_payment_evaluate,
"remaining_amount": sale_order.amount_total - down_payment_evaluate,
"interest": annuall_intrest,
"number_monthly_installment": max_duration * 12,
"installement_amount": installment_ammount,
}
)
return res

def add_installment(self):
active_id = self.env.context["active_id"]
sale_order = self.env["sale.order"].browse(active_id)
sale_order.order_line = [
Command.create(
{
"order_id": sale_order.id,
"price_unit": self.installement_amount,
"product_id": self.env.ref("installment.product_installment").id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"tax_id": None,
}
),
Command.create(
{
"order_id": sale_order.id,
"product_uom_qty": 1.0,
"price_unit": -self.installement_amount,
"product_id": self.env.ref("installment.product_monthly").id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"tax_id": None,
},
),
]
return
29 changes: 29 additions & 0 deletions installment/wizard/add_emi_wizard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<odoo>
<record id='from_add_emi' model='ir.ui.view'>
<field name="name">Add EMI Form</field>
<field name="model">add.emi</field>
<field name="arch" type="xml">
<form>
<group>
<field name="total_so_amount"/>
<field name="down_payment"/>
<field name="remaining_amount" readonly='1'/>
<field name="interest" readonly='1'/>
<field name="number_monthly_installment" readonly='1'/>
<field name="installement_amount" readonly='1'/>
</group>
<footer>
<button name="add_installment" class="btn btn-primary" string="Add Installment" type="object"/>
</footer>
</form>
</field>
</record>

<record id="action_add_emi" model="ir.actions.act_window">
<field name="name">Add EMI</field>
<field name="res_model">add.emi</field>
<field name="view_mode">form</field>
<field name="view_id" ref="from_add_emi" />
<field name="target">new</field>
</record>
</odoo>

0 comments on commit bb55acf

Please sign in to comment.