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
- implemented business logic
  • Loading branch information
pkgu-odoo committed Sep 16, 2024
1 parent 44585cc commit 743be1a
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dental/views/dental_medical_aids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<record id="action_dental_medical_aids" model="ir.actions.act_window">
<field name="name">Medical Aids</field>
<field name="res_model">dental.medical.aids</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">tree,form</field>
</record>

<record id="medicalaids_view_form" model="ir.ui.view">
Expand Down
2 changes: 1 addition & 1 deletion estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<field name="state" widget="statusbar"/>
</header>
<sheet>
<group>
<group>search_default_available
<group>
<field name="name" />
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
Expand Down
2 changes: 2 additions & 0 deletions installments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
16 changes: 16 additions & 0 deletions installments/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
'name': 'Installment Management',
'version': '1.0',
'category': 'Sales',
'author': 'odoo',
'depends': ['base', 'sale_subscription'],
'data': [
'security/ir.model.access.csv',
'wizard/action_open_emi_wizard_view.xml',
'view/res_config_setting_view.xml',
'view/installments_view.xml'
],
'installable': True,
'application': True,
'license': 'LGPL-3'
}
1 change: 1 addition & 0 deletions installments/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
12 changes: 12 additions & 0 deletions installments/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class InstallmentSettings(models.TransientModel):
_inherit = 'res.config.settings'

max_duration = fields.Float('Max Duration', config_parameter="installments.max_duration")
annual_rate = fields.Float('Annual Rate', config_parameter="installments.annual_rate")
down_payment_perc = fields.Float('Down Payment', config_parameter="installments.down_payment_perc")
admin_exp_perc = fields.Float('Administrative Expenses', config_parameter="installments.admin_exp_perc")
delay_penalty_perc = fields.Float('Delay Penalty', config_parameter="installments.delay_penalty_perc")
delay_penalty_process = fields.Integer('Delay Penalty Process', config_parameter="installments.delay_penalty_process")
2 changes: 2 additions & 0 deletions installments/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_installments_settings_base_user,access_installments_settings_base_user,model_action_open_emi_wizard,base.group_user,1,1,1,1
16 changes: 16 additions & 0 deletions installments/view/installments_view.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="view_order_form_inherited" model="ir.ui.view">
<field name="name">sale.order.form.inherited</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="before">
<button string="Add EMI"
name="%(installments.action_open_emi_wizard)d"
type="action"
class="btn btn-primary"/>
</xpath>
</field>
</record>
</odoo>
43 changes: 43 additions & 0 deletions installments/view/res_config_setting_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.setting.view.form.inherit.installment</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="//block[@name='companies_setting_container']" position="after">
<block title="Installment Process" id="installment_general_settings">
<setting id="max_duration_setting" help="Define your Max duration">
<field name="max_duration"/>
<a>Years</a>
</setting>
<setting id="annual_rate_percentage_setting" help="Define the Annual Rate Percentage">
<field name="annual_rate"/>
<a>%Per Year</a>
</setting>
<setting id="down_payment_percentage_setting" help="Define the Down Payment Percentage">
<field name="down_payment_perc"/>
<a>%From Product Price</a>
</setting>
<setting id="administrative_expense_percentage_setting" help="Define the Administrative Expense Percentage">
<field name="admin_exp_perc"/>
<a>%From Amount After D.Payment</a>
</setting>
<setting id="delay_penalty_percentage_setting" help="Define the Delay Penalty Percentage">
<field name="delay_penalty_perc"/>
<a>%From Monthly Amount</a>
</setting>
<setting id="delay_penalty_process_setting" help="Define the Delay Penalty Process">
<field name="delay_penalty_process"/>
<a>Days</a>
<br>
<help>
help="Define the Delay Penalty Process"
</help>
</br>
</setting>
</block>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions installments/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import action_open_emi_wizard
42 changes: 42 additions & 0 deletions installments/wizard/action_open_emi_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from odoo import models, fields, api


class ActionOpenEmiWizard(models.TransientModel):
_name = 'action.open.emi.wizard'
_description = 'Installment Settings'

total_so_amount = fields.Float(string="Total SO Amount")
down_payment = fields.Float(string="Down Payment", compute="_compute_values")
remaining_amount = fields.Float(string="Remaining Amount", compute="_compute_values")
remaining_amount2 = fields.Float(string="Remaining Amount", compute="_compute_values")
interest = fields.Float(string="Interest", compute="_compute_values")
admin_expence = fields.Float(string="Administrative Expense", compute="_compute_values")
num_installments = fields.Integer(string="Number of Monthly Installments", compute="_compute_values")
installment_amount = fields.Float(string="Installment Amount", compute="_compute_values")

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

@api.depends("total_so_amount")
def _compute_values(self):
for rec in self:
down_payment_percent = self.env['ir.config_parameter'].get_param('installments.down_payment_perc')
x = float(rec.total_so_amount) * float(down_payment_percent)
rec.down_payment = x / 100
rec.remaining_amount = rec.total_so_amount - rec.down_payment
administrative_expense_percent = self.env['ir.config_parameter'].get_param('installments.admin_exp_perc')
y = float(rec.remaining_amount) * float(administrative_expense_percent)
rec.admin_expence = y / 100
rec.remaining_amount2 = rec.remaining_amount + rec.admin_expence
annual_rate_percent = self.env['ir.config_parameter'].get_param('installments.annual_rate')
z = float(rec.remaining_amount2) * float(annual_rate_percent)
rec.interest = z / 100
nof_install = float(self.env['ir.config_parameter'].get_param('installments.max_duration'))
rec.num_installments = nof_install * 12
final_amount = rec.remaining_amount2 + rec.interest
rec.installment_amount = final_amount / rec.num_installments

def add_installment(self):
pass
32 changes: 32 additions & 0 deletions installments/wizard/action_open_emi_wizard_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<odoo>
<record id="open_emi_wizard_form" model="ir.ui.view">
<field name="name">action.open.emi.form</field>
<field name="model">action.open.emi.wizard</field>
<field name="arch" type="xml">
<form string="EMI">
<group>
<field name="total_so_amount"/>
<field name="down_payment"/>
<field name="remaining_amount"/>
<field name="interest"/>
<field name="num_installments"/>
<field name="installment_amount"/>
</group>
<footer>
<button string="Add EMI Installment" type="object" name="add_installment" class="btn-primary"/>
</footer>
</form>
</field>
</record>
<odoo>
<!-- Action to open the wizard -->
<record id="action_open_emi_wizard" model="ir.actions.act_window">
<field name="name">Add EMI</field>
<field name="res_model">action.open.emi.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="open_emi_wizard_form"/>
<field name="target">new</field>
</record>
</odoo>

</odoo>

0 comments on commit 743be1a

Please sign in to comment.