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
yasp-odoo committed Sep 16, 2024
1 parent 89b321a commit b2bcbfb
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dental/controller/dental_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class DentalPortal(CustomerPortal):
@http.route('/my/dental', type='http', auth='user', website=True)
def portal_my_dental(self, **kw):
patients = request.env['dental.patient'].search([('guarantor_id', '=', request.env.user.id)])
patients = request.env['dental.patient'].search([('guarantor_id', '=', request.env.user.id), ('gender', '=', 'male'), ('patient_history_ids', '!=', False), ('emergency_contact_id', '!=', False), ('allergy_ids', '!=', False ), '|' ('psychiatric_history', '!=', False)])
return request.render('dental.portal_my_dental', {
'patients': patients
})
Expand Down
2 changes: 1 addition & 1 deletion dental/models/dental_patient_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DentalPatientHistory(models.Model):
('full_consultation', 'Full Consultation with Bitewings and Scan'),
('basic_consultation', 'Basic Consultation'),
('no_consultation', 'No Consultation')
], shabits_substance_abusetring="Consultation Type")
], string="Consultation Type")

call_out = fields.Boolean(string="Call Out")
scale_and_polish = fields.Boolean(string="Scale and Polish")
Expand Down
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 wizard
from . import models
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',
'version': '1.0',
'description': 'A module for installment',
'category': 'sales',
'author': 'YASP',
'sequence': 1,
'depends': ['base', 'sale_subscription'],
'license': 'LGPL-3',
'data': [
'security/ir.model.access.csv',
'wizard/wizard_view.xml',
'views/res_config_settings_view.xml',
'views/add_emi_view.xml'
],
'installable': True,
'application': True,
}
1 change: 1 addition & 0 deletions installment/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 installment/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 ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

max_duration = fields.Integer(string="Max Duration", config_parameter="installment.max_duration")
annual_rate_percentage = fields.Integer(string="Annual Rate Percentage", config_parameter="installment.annual_rate_percentage")
down_payment_percentage = fields.Integer(string="Down Payment Percentage", config_parameter="installment.down_payment_percentage")
administrative_expense_percentage = fields.Integer(string="Administrative Expense Percentage", config_parameter="installment.administrative_expense_percentage")
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")
2 changes: 2 additions & 0 deletions installment/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_installment_add_emi_wizard,access_installment_add_emi_wizard,model_installment_add_emi_wizard,base.group_user,1,1,1,1
15 changes: 15 additions & 0 deletions installment/views/add_emi_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>
<record id="add_emi_view" model="ir.ui.view">
<field name="name">add.emi.view</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="%(installment.action_add_emi_wizard)d"
type="action"
class="btn btn-primary"/>
</xpath>
</field>
</record>
</odoo>
43 changes: 43 additions & 0 deletions installment/views/res_config_settings_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_installment_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.installment</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//block[@name='integration']" 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_percentage"/>
<a>%Per Year</a>
</setting>
<setting id="down_payment_percentage_setting" help="Define the Down Payment Percentage">
<field name="down_payment_percentage"/>
<a>%From Product Price</a>
</setting>
<setting id="administrative_expense_percentage_setting" help="Define the Administrative Expense Percentage">
<field name="administrative_expense_percentage"/>
<a>%From Amount After D.Payment</a>
</setting>
<setting id="delay_penalty_percentage_setting" help="Define the Delay Penalty Percentage">
<field name="delay_penalty_percentage"/>
<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 installment/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import add_emi_wizard
42 changes: 42 additions & 0 deletions installment/wizard/add_emi_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from odoo import models, fields, api


class AddEmiWizard(models.TransientModel):
_name = 'installment.add.emi.wizard'
_description = 'Add Emi Wizard'

totalso_amount = fields.Float(string="Total Amount", readonly=True)
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 Amount2", compute="_compute_values")
interest = fields.Float(string="Interest", compute="_compute_values")
administrative_expense = fields.Float(string="Administrative Expense", compute="_compute_values")
nof_installment = fields.Integer(string="No. of Monthly Installment", 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['totalso_amount'] = self.env['sale.order'].browse(self.env.context.get('active_id')).amount_total
return defaults

@api.depends("totalso_amount")
def _compute_values(self):
for rec in self:
down_payment_percent = self.env['ir.config_parameter'].get_param('installment.down_payment_percentage')
x = float(rec.totalso_amount) * float(down_payment_percent)
rec.down_payment = x / 100
rec.remaining_amount = rec.totalso_amount - rec.down_payment
administrative_expense_percent = self.env['ir.config_parameter'].get_param('installment.administrative_expense_percentage')
y = float(rec.remaining_amount) * float(administrative_expense_percent)
rec.administrative_expense = y / 100
rec.remaining_amount2 = rec.remaining_amount + rec.administrative_expense
annual_rate_percent = self.env['ir.config_parameter'].get_param('installment.annual_rate_percentage')
z = float(rec.remaining_amount2) * float(annual_rate_percent)
rec.interest = z / 100
nof_install = float(self.env['ir.config_parameter'].get_param('installment.max_duration'))
rec.nof_installment = nof_install * 12
final_amount = rec.remaining_amount2 + rec.interest
rec.installment_amount = final_amount / rec.nof_installment

def action_add_emi(self):
pass
30 changes: 30 additions & 0 deletions installment/wizard/wizard_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<odoo>
<record id="installment_add_emi_wizard_form" model="ir.ui.view">
<field name="name">installment.add.emi.wizard.form</field>
<field name="model">installment.add.emi.wizard</field>
<field name="arch" type="xml">
<form string="Add EMI">
<group>
<field name="totalso_amount" />
<field name="down_payment" />
<field name="remaining_amount" />
<field name="interest" />
<field name="nof_installment" />
<field name="installment_amount" />
</group>
<footer>
<button string="Add Installment" type="object" name="action_add_emi"
class="btn-primary" />
</footer>
</form>
</field>
</record>

<record id="action_add_emi_wizard" model="ir.actions.act_window">
<field name="name">ADD EMI</field>
<field name="res_model">installment.add.emi.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="installment_add_emi_wizard_form" />
<field name="target">new</field>
</record>
</odoo>

0 comments on commit b2bcbfb

Please sign in to comment.