Skip to content

Commit

Permalink
[ADD] installment: create a module,invoice cron, doc upload wizard, i…
Browse files Browse the repository at this point in the history
…nvoice

- Add setting section for installment
- Add wizard for Add EMI
- Add Button for document module redirect
- Implemented the invoice schedule when exceed the delay process day
- Add the Document Upload  request smart button
- Add wizard for document request for sales order
  • Loading branch information
irah-odoo committed Sep 20, 2024
1 parent b901bee commit edaf4ae
Show file tree
Hide file tree
Showing 21 changed files with 696 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dental/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ class dentalController(Controller):
def dental_patient(self, **kwarg):
current_user = request.env.user
page = int(kwarg.get("page", 1))
total_patients = request.env["dental.patient"].sudo().search_count(
[("guarantor", "=", current_user.id)]
total_patients = (
request.env["dental.patient"]
.sudo()
.search_count([("guarantor", "=", current_user.id)])
)

pager = request.website.pager(
url="/home/dental",
total=total_patients,
page=page,
step=4,
step=4
)
patients = request.env["dental.patient"].sudo().search(
[("guarantor", "=", current_user.id)], limit=4, offset=pager["offset"]
patients = (
request.env["dental.patient"]
.sudo()
.search(
[("guarantor", "=", current_user.id)], limit=4, offset=pager["offset"]
)
)

return request.render(
Expand Down
6 changes: 6 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ def _delete_state(self):
for record in self:
if record.state != "new" and record.state != "canceled":
raise ValidationError("can't be deleted")

def add_properties_draft(self):

for record in self:
if record.state == "canceled" or record.state == "offer_received":
record.state = "new"
1 change: 1 addition & 0 deletions estate/view/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
decoration-bf="state in ('offer_accepted')" decoration-muted="state in ('sold')">
<header>
<button string="Add offer" name="%(estate.add_offer_action)d" type="action" />
<button string="Draft" name="add_properties_draft" type="object" />
</header>
<field name='sequence' widget='handle' />
<field name="name" string="Title" />
Expand Down
3 changes: 3 additions & 0 deletions estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ def button_action_sold(self):
}
self.env["account.move"].sudo().create(invoice_vals)
return result



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
19 changes: 19 additions & 0 deletions installment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "installment",
"version": "0.1",
"license": "LGPL-3",
"depends": ["base", "sale_subscription", "documents"],
"description": "Installment Application",
"installable": True,
"application": True,
"data": [
"security/ir.model.access.csv",
"views/installment_setting_view.xml",
"wizard/add_emi_view.xml",
"wizard/documents_request_view.xml",
"views/installment_menu.xml",
"views/sales_order_view.xml",
"data/product_data.xml",
"data/corn.xml",
],
}
14 changes: 14 additions & 0 deletions installment/data/corn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<data>
<record model="ir.cron" id="installemnt_invoice_corn">
<field name="name">installemnt.invoice.corn</field>
<field name="model_id" ref="model_account_move"/>
<field name="state">code</field>
<field name="code">model.cron_recurring_create_invoice()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>

</record>
</data>
</odoo>
20 changes: 20 additions & 0 deletions installment/data/product_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<odoo>
<data>
<record id="product_product_installment" model="product.product">
<field name="name">Installment</field>
<field name="recurring_invoice">True</field>
</record>

<record id="product_product_down_payment" model="product.product">
<field name="name">Down Payment</field>

</record>

<record id="product_product_penalty" model="product.product">
<field name="name">Penalty</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_installemnt
from . import sale_order
from . import account_move
84 changes: 84 additions & 0 deletions installment/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from datetime import timedelta
from odoo import Command, models, fields, api


class accountMove(models.Model):
_inherit = "account.move"

applied_penalty = fields.Boolean(string="Applied Penalty", default=False)

@api.model
def cron_recurring_create_invoice(self):

today = fields.Date.today()
delay_penalty_process = float(
self.env["ir.config_parameter"]
.sudo()
.get_param("installment.delay_penalty_process")
)

invoices = self.env["account.move"].search(
[
("state", "=", "posted"),
("payment_state", "=", "not_paid"),
("move_type", "=", "out_invoice"),
("applied_penalty", "=", False),
]
)
for invoice in invoices:

for line in invoice.line_ids:
if (
line.product_id.id
== self.env.ref("installment.product_product_installment").id
):
due_date = invoice.invoice_date_due

penalty_start_date = due_date + timedelta(
days=delay_penalty_process
)

if today >= penalty_start_date:
penalty_amount = self.calculate_penalty_amount(invoice)

invoice_vals = {
"partner_id": invoice.partner_id.id,
"move_type": "out_invoice",
"line_ids": [
Command.create(
{
"product_id": self.env.ref(
"installment.product_product_installment"
).id,
"name": "Installment",
"price_unit": invoice.amount_total,
"tax_ids": None,
}
),
Command.create(
{
"product_id": self.env.ref(
"installment.product_product_penalty"
).id,
"name": "Penalty Charge",
"price_unit": penalty_amount,
"tax_ids": None,
}
),
],
}
new_invoice = (
self.env["account.move"].sudo().create(invoice_vals)
)
new_invoice.action_post()
invoice.write({"applied_penalty": True})

def calculate_penalty_amount(self, invoice):

down_penalty_percentage = float(
self.env["ir.config_parameter"]
.sudo()
.get_param("installment.down_penalty_percentage")
)
penalty_amount = (invoice.amount_total * down_penalty_percentage) / 100
return penalty_amount
39 changes: 39 additions & 0 deletions installment/models/installment_installemnt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from odoo import fields, models


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

name = fields.Char()
max_duration = fields.Float(config_parameter="installment.max_duration")
annual_percentage_rate = fields.Float(
config_parameter="installment.annual_percentage_rate"
)
down_payment_percentage = fields.Float(
config_parameter="installment.down_payment_percentage"
)
administrative_expenses_percentage = fields.Float(
config_parameter="installment.administrative_expenses_percentage"
)
down_penalty_percentage = fields.Float(
config_parameter="installment.down_penalty_percentage"
)
delay_penalty_process = fields.Integer(
config_parameter="installment.delay_penalty_process"
)
nid = fields.Boolean(config_parameter="installment.nid", default=False)
salary_components = fields.Boolean(
config_parameter="installment.salary_components", default=False
)
bank_statement = fields.Boolean(
config_parameter="installment.bank_statement", default=False
)
bank_rate_letter = fields.Boolean(
config_parameter="installment.bank_rate_letter", default=False
)
rental_contract = fields.Boolean(
config_parameter="installment.rental_contract", default=False
)
owership_contract = fields.Boolean(
config_parameter="installment.owership_contract", default=False
)
5 changes: 5 additions & 0 deletions installment/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from odoo import models


class sale_order(models.Model):
_inherit = "sale.order"
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_add_emi,access_add_emi,installment.model_add_emi,base.group_user,1,1,1,1
installment.access_documents_request,access_documents_request,installment.model_documents_request,base.group_user,1,1,1,1
9 changes: 9 additions & 0 deletions installment/views/installment_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<odoo>
<menuitem id="installment_root" name="Installment app">
<menuitem id="installment_configration_level_menu" name="Configration">
<menuitem id="installment_configuration_menu_action"
action="action_sale_config_settings" />
</menuitem>

</menuitem>
</odoo>
98 changes: 98 additions & 0 deletions installment/views/installment_setting_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="res_installment_configuration_settings_view_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.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//form" position="inside">
<app string="Installment" data-string="Installment" name="installment">
<block title="Installment Process" name="installment_setting_container">
<setting string="Max Duration" help=" Define Max Duration">

<field name="max_duration" />
<span>Years</span>
</setting>
<setting string="Annual Percentage Rate"
help=" Define Annual Percentage Rate">

<field name="annual_percentage_rate" />
<span>% Per Years</span>
</setting>
<setting string="Down Payment Percentage"
help=" Define Down Payment Percentage">

<field name="down_payment_percentage" />
<span>% From Product Price</span>
</setting>
<setting string="Administrative Expenses Percentage"
help=" Define Administrative Expenses Percentage">

<field name="administrative_expenses_percentage" />
<span>% From Amount After D.Payment</span>
</setting>
<setting string="Down Penalty Percentage"
help=" Define Down Penalty Percentage ">

<field name="down_penalty_percentage" />
<span>% From Monthly Amount</span>
</setting>
<setting string="Delay Penalty Process"
help=" Define Delay Penalty Process ">

<field name="delay_penalty_process" />
<span
help="Delay Penalty percentage will be applied after exceed the delay process period">
Days</span>
<div class="text-muted">
Delay Penalty percentage will be applied after exceed the delay
process period
</div>
</setting>
</block>

<block title="Needed Documents" name="needed_documents_setting_container">
<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="Owership Contract">

<field name="owership_contract" />

</setting>

</block>
</app>
</xpath>
</field>
</record>

<record id="action_sale_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_installment_configuration_settings_view_form" />
<field name="view_mode">form</field>
<!-- <field name="target">inline</field> -->


</record>

</odoo>
19 changes: 19 additions & 0 deletions installment/views/sales_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<odoo>
<record id="view_sales_order_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']/button" position="before">
<button name="%(installment.add_emi_action)s" type="action" string="Add EMI" />
</xpath>

<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button name="%(action_upload_documents)s" type="action" string="Add Documents"
class="oe_stat_button"
icon="fa-file-pdf-o" />
</xpath>
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions installment/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import add_emi
from . import document_request
Loading

0 comments on commit edaf4ae

Please sign in to comment.