Skip to content

Commit

Permalink
[IMP] installment: implemented the document upload request wizard
Browse files Browse the repository at this point in the history
- Implemented document upload wizard
- Modifies the new invoice creation
  • Loading branch information
amya-odoo committed Sep 20, 2024
1 parent 16712c7 commit 9d2dfa9
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 128 deletions.
1 change: 1 addition & 0 deletions installment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"depends": ["base", "sale_subscription", "documents", "account"],
"data": [
"security/ir.model.access.csv",
"wizard/document_wizard.xml",
"wizard/add_emi_wizard.xml",
"views/installment_views.xml",
"views/res_config_settings_views.xml",
Expand Down
43 changes: 22 additions & 21 deletions installment/models/installment_installment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ def _cron_create_invoice(self):
("state", "=", "posted"),
("payment_state", "=", "not_paid"),
("penalty_applied", "=", False),
(
"invoice_date_due",
"<=",
today - timedelta(days=delay_penalty_process),
), # filter the invoice which exceed the delay procces day
("invoice_date_due", "<=", today - timedelta(days=delay_penalty_process)),
]
)
_logger.info(f" account---->>> {invoices}")
for invoice in invoices:
list = self._calculate_penalty(invoice.amount_total)
for line in invoice.line_ids:
if (
line.product_id.id
== self.env.ref("installment.product_installment").id
):
if (line.product_id.id == self.env.ref("installment.product_installment").id):
sale_order = self.env['sale.order'].search([("invoice_ids","=",invoice.id)])
# print(sale_order.name)
values = {
"move_type": "out_invoice",
"partner_id": invoice.partner_id.id,
Expand Down Expand Up @@ -68,14 +63,24 @@ def _cron_create_invoice(self):
],
}
new_invoice = self.env["account.move"].create(values)
_logger.info(new_invoice.name)
new_invoice.action_post()
invoice.write(
{
"penalty_applied": True,
}
)
_logger.info(new_invoice.name)
# Set the invoice with sale order
# print("Invoice set Sale Order")
# print(sale_order.invoice_ids)
# print(new_invoice.line_ids)
try:
sale_order.order_line.invoice_lines = [
Command.set(new_invoice.line_ids.ids)
]
# print(sale_order.name)
# print(sale_order.invoice_ids)
except Exception as e:
_logger.info(f"{e}")

invoice.write({
"penalty_applied": True,
})
else:
continue

Expand All @@ -85,12 +90,8 @@ def _calculate_penalty(self, amount_total):
Return the list[ penatly amount, due process day, percentage ]
"""
config_param = self.env["ir.config_parameter"]
delay_penalty_percentage = int(
config_param.get_param("installment.delay_penalty_percentage", default=0)
)
delay_penalty_process = int(
config_param.get_param("installment.delay_penalty_process", default=0)
)
delay_penalty_percentage = int(config_param.get_param("installment.delay_penalty_percentage", default=0))
delay_penalty_process = int(config_param.get_param("installment.delay_penalty_process", default=0))
float_delay_penalty_percentage = delay_penalty_percentage / 100
return [
amount_total * float_delay_penalty_percentage,
Expand Down
92 changes: 4 additions & 88 deletions installment/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,8 @@
from odoo import models
import logging
from odoo import fields, models

_logger = logging.getLogger(__name__)


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

document_mapping = {
"installment.nid": "National ID (NID)",
"installment.salary_components": "Salary Components",
"installment.bank_statement": "Bank Statement",
"installment.bank_rate_letter": "Bank Rate Letter",
"installment.rental_contract": "Rental Contract",
"installment.ownership_contract": "Ownership Contract",
}

def action_upload_documents(self):
workspace_name = "Installment"
sub_folder = self.name
existing_workspace = self.env["documents.folder"].search(
[("name", "=", workspace_name)], limit=1
)
if not existing_workspace:
new_workspace = self.env["documents.folder"].create(
{
"name": workspace_name,
"parent_folder_id": None,
"description": f"Workspace for {workspace_name}",
"has_write_access": True,
}
)
subfolder = self.env["documents.folder"].create(
{
"name": sub_folder,
"parent_folder_id": new_workspace.id,
"description": f"Subfolder for {sub_folder} under {workspace_name}",
"has_write_access": True,
}
)
self._create_document_wizard_request(subfolder)

else:
existing_sub_folder = self.env["documents.folder"].search(
[("name", "=", sub_folder)], limit=1
)
if not existing_sub_folder:
subfolder = self.env["documents.folder"].create(
{
"name": sub_folder,
"parent_folder_id": existing_workspace.id,
"description": f"Subfolder for {sub_folder} under {workspace_name}",
"has_write_access": True,
}
)
self._create_document_wizard_request(subfolder)
else:
exiting_doc_list = self.env["documents.document"].search(
[("folder_id", "=", existing_sub_folder.id)]
)
# Logic for validating docs in sub folder not exist then create
unmatched_doc = []
for doc in exiting_doc_list:
if doc.name not in self.document_mapping.values():
unmatched_doc.append(doc.name)
for name in unmatched_doc:
values = {
"name": name,
"owner_id": self.env.user.id,
"partner_id": self.partner_id.id,
"folder_id": subfolder.id,
}
self.env["documents.document"].create(values)

def _get_document_list(self):
config_param = self.env["ir.config_parameter"].sudo()
# Building document required dictionary dynamically
document = {
key.split(".")[-1]: name
for key, name in self.document_mapping.items()
if config_param.get_param(key, default=False)
}
return document

def _create_document_wizard_request(self, subfolder):
document_required = self._get_document_list()
for name in document_required.values():
values = {
"name": name,
"owner_id": self.env.user.id,
"partner_id": self.partner_id.id,
"folder_id": subfolder.id,
}
self.env["documents.document"].create(values)
3 changes: 2 additions & 1 deletion installment/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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
installment.access_add_emi,access_add_emi,installment.model_add_emi,base.group_user,1,1,1,1
installment.access_installment_document,access_installment_document,installment.model_installment_document,base.group_user,1,1,1,1
4 changes: 3 additions & 1 deletion installment/views/installment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<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"/>
<!-- <button name="action_upload_documents" class="btn btn-primary " icon="fa-file-text" string="Document" type="object"/> -->
<button name="installment.action_document_upload" class="btn btn-primary " icon="fa-file-text" string="Document" type="action"/>

</xpath>
</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions installment/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import add_emi
from . import document_wizard
17 changes: 4 additions & 13 deletions installment/wizard/add_emi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@ def default_get(self, fields):
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)
)
max_duration = float(config_param.get_param("installment.max_duration", default=0.0))
if max_duration == 0:
raise UserError("Max Duration is zero.")
down_payment_percentage = int(
config_param.get_param("installment.down_payment", default=0)
)
annual_rate = int(
config_param.get_param("installment.annual_rate", default=0)
)

administrative_expenses = int(
config_param.get_param("installment.administrative_expenses", default=0.0)
)
down_payment_percentage = int(config_param.get_param("installment.down_payment", default=0))
annual_rate = int(config_param.get_param("installment.annual_rate", default=0))
administrative_expenses = int(config_param.get_param("installment.administrative_expenses", default=0.0))
# Total
total = sale_order.amount_total
# Down Payment calculated
Expand Down
8 changes: 4 additions & 4 deletions installment/wizard/add_emi_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<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'/>
<field name="remaining_amount"/>
<field name="interest"/>
<field name="number_monthly_installment"/>
<field name="installement_amount"/>
</group>
<footer>
<button name="add_installment" class="btn btn-primary" string="Add Installment" type="object"/>
Expand Down
Loading

0 comments on commit 9d2dfa9

Please sign in to comment.