Skip to content

Commit

Permalink
[ADD] warranty: Add waranty feature for sale order
Browse files Browse the repository at this point in the history
-Created new model waranty feture for sale order
-Create delete functionality for sale.order.line
-Create wizard for show to product which is sale.order.line and show the year
 end_date
  • Loading branch information
krku-odoo committed Sep 26, 2024
1 parent 92478f7 commit 456c8ed
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 83 deletions.
31 changes: 15 additions & 16 deletions dental/views/dental_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
<!-- show all patient -->
<template id="dental_patient_view_controller">
<t t-call="website.layout">
<div style="container" class="mb-5 container">
<nav class="navbar navbar-expand-lg flex-wrap mb-4 p-0 o_portal_navbar ">
<ol class="o_portal_submenu breadcrumb mb-0 flex-grow-1 px-0">
<div class="container mb-5">
<nav class="navbar navbar-expand-lg flex-wrap mb-4 p-0">
<ol class="breadcrumb mb-0 flex-grow-1 px-0">
<li class="breadcrumb-item active">
<a t-attf-href="/my/home" aria-label="Home">
<i class="fa fa-home">
</i>
<i class="fa fa-home"></i>
</a>
</li>
</ol>
</nav>
<h1 class="text-center mt-5">Dental</h1>
<div t-if="patients">
<div class="d-flex justify-content-start flex-wrap">
<div t-foreach="patients" t-as="record"
style="width:28%;length:10%; margin:2rem;padding:1px; border-radius:10px; border:solid black 1px background: #f9f9f9; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); transition: all 0.3s ease;">
<img src="dental/static/icons/icon.svg" />
<a t-attf-href="/patient/#{record.id}" class="text-decoration-none">
<br />
<h4 style="width:100%;text-align:center;">
<t t-out="record.name"/>
</h4>
</a>
<div t-foreach="patients" t-as="record" class="card" style="width: 28%; margin: 2rem; padding: 1px; border-radius: 10px; background: #f9f9f9; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); transition: all 0.3s ease;">
<img src="dental/static/icons/icon.svg" class="card-img-top" />
<div class="card-body">
<a t-attf-href="/patient/#{record.id}" class="text-decoration-none">
<h4 class="card-title text-center">
<t t-out="record.name"/>
</h4>
</a>
</div>
</div>
</div>
<div class="pagination-container" style="width: 100%; text-align: center; margin-top: 2rem;">
<div class="pagination-container text-center mt-4">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<li class="page-item" t-att-class="page == 1 and 'disabled'">
Expand Down Expand Up @@ -59,7 +58,7 @@
</div>
</t>
</template>

<!-- for ptient detail View -->
<template id="patient_details_view_controller" name="Patient Details">
<t t-call="website.layout">
Expand Down
3 changes: 1 addition & 2 deletions installment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "LGPL-3",
"category": "Subscription Installment",
"summary": "Subscription Installment",
"depends": ["base_setup", "sale_subscription"],
"depends": ["base_setup", "sale_subscription","documents"],
"data": [
"security/ir.model.access.csv",
"wizard/add_button_emi_views.xml",
Expand All @@ -15,5 +15,4 @@
],
"installable": True,
"application": True,
"auto_install": False,
}
36 changes: 16 additions & 20 deletions installment/model/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
from odoo import models, fields, Command
from odoo import api, models, fields, Command
from datetime import timedelta


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

#create cron function
@api.model
def action_cron_auto_transfer(self):
invoices = (
self.env["account.move "]
.sudo()
.search(
[
(
"line_ids.product_id",
"=",
self.env.ref("installment.product1").id,
),
( "line_ids.product_id","=",self.env.ref("installment.product1").id,),
("state", "in", ["posted", "open"]),
("payment_state", "!=", "paid"),
("penalty_applied", "=", False),
]
)
)

current_date = fields.Date.today()
for invoice in invoices:
print(invoice.sale_order_line.id)
penalty_delay_date = self.env["ir.config_parameter"].get_param(
"installment.delay_panalty_process"
)

penalty_delay_days = int(float(penalty_delay_date))
invoice_date = invoice.invoice_date_due + timedelta(days=penalty_delay_days)

if current_date >= invoice_date:
penalty_amount = self.calculate_penalty_amount(invoice)
values = {
Expand Down Expand Up @@ -58,25 +58,23 @@ def action_cron_auto_transfer(self):
),
],
}
print(values)
new_invoice = self.env["account.move"].create(values)
new_invoice.action_post()
print(new_invoice.name)

# calculate penalty amounte
def calculate_penalty_amount(self, invoice):
down_penalty_percentage = float(
self.env["ir.config_parameter"]
.sudo()
.get_param("installment.delay_panalty_perc")
)

penalty_invoice_amount = (invoice.amount_total * down_penalty_percentage) / 100

return penalty_invoice_amount


# create fuction for document upload
def action_upload_documents(self):
print("gffg")
# Retrieve the configuration settings
config_settings = self.env["ir.config_parameter"].sudo()
config_settings = self.env["ir.config_parameter"]

# Create a mapping of setting fields to document names
document_settings = {
Expand All @@ -88,17 +86,15 @@ def action_upload_documents(self):
"owner_contract": "Ownership Contract",
}

# Prepare a list of required documents based on the configuration
# Prepare a list of required docu ents based on the configuration
required_documents = []
for setting_key, document_name in document_settings.items():
if config_settings.get_param(f"installment.{setting_key}", default=False):
required_documents.append(document_name)

for order in self:
# Ensure the Installments folder exists
installments_folder = self.env["documents.folder"].search(
[("name", "=", "Installments")], limit=1
)
[("name", "=", "Installments")], limit=1)
if not installments_folder:
installments_folder = self.env["documents.folder"].create(
{
Expand Down Expand Up @@ -157,7 +153,7 @@ def action_upload_documents(self):
"view_mode": "kanban,tree,form",
"domain": [("folder_id", "=", folder.id)],
"context": {
"default_folder_id": folder.id,
"default_partner_id": order.partner_id.id,
"searchpanel_default_folder_id": folder.id,
"searchpanel_default_partner_id": order.partner_id.id,
},
}
2 changes: 1 addition & 1 deletion installment/views/menuitem.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="action_installment_config_settings" name="Installment">
<menuitem id="action_installment_config_settings" name="Installment"/>
</odoo>
73 changes: 29 additions & 44 deletions installment/wizard/add_emi_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,51 @@ class AddEmi(models.TransientModel):
total_sale_amount = fields.Float(string="Total sale Amount", readonly=True)
down_payment = fields.Float(compute="_compute_values")
remaining_amount = fields.Float(compute="_compute_values")
interest = fields.Float(compute="_compute_values")
number_of_monthly_installement = fields.Integer(compute="_compute_values")
interest = fields.Float(compute='_compute_values')
number_of_monthly_installement = fields.Integer(compute='_compute_values')
installement_amount = fields.Float(readonly=True)
admin_expense = fields.Float(compute="_compute_values")
remaining_amount_2 = fields.Float(compute="_compute_values")
admin_expense = fields.Float(compute='_compute_values')
remaining_amount_2 = fields.Float(compute='_compute_values')

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

@api.depends("total_sale_amount")
def _compute_values(self):
for rec in self:
down_payment_perc = self.env["ir.config_parameter"].get_param(
"installment.down_payment_perc"
)
down_payment_perc = self.env['ir.config_parameter'].get_param(
'installment.down_payment_perc')
x = float(rec.total_sale_amount) * float(down_payment_perc)
rec.down_payment = x / 100
rec.remaining_amount = rec.total_sale_amount - rec.down_payment
administrative_expenses_percentage = self.env[
"ir.config_parameter"
].get_param("installment.administ_exp")
administrative_expenses_percentage = self.env['ir.config_parameter'].get_param(
'installment.administ_exp')
y = float(rec.remaining_amount) * float(administrative_expenses_percentage)
rec.admin_expense = y / 100
rec.remaining_amount_2 = rec.remaining_amount + rec.admin_expense
max_dur = float(
self.env["ir.config_parameter"].get_param("installment.max_duration")
)
annual_rate_percentage = self.env["ir.config_parameter"].get_param(
"installment.annual_rate_perc"
)
z = (
float(rec.remaining_amount_2)
* float(annual_rate_percentage)
* float(max_dur)
)
max_dur = float(self.env['ir.config_parameter'].get_param(
'installment.max_duration'))
annual_rate_percentage = self.env['ir.config_parameter'].get_param(
'installment.annual_rate_perc')
z = float(rec.remaining_amount_2) * float(annual_rate_percentage)*float(max_dur)
rec.interest = z / 100
rec.number_of_monthly_installement = float(max_dur) * 12
rec.installement_amount = (
rec.remaining_amount_2 + rec.interest
) / rec.number_of_monthly_installement

# add installment button
rec.remaining_amount_2 + rec.interest)/rec.number_of_monthly_installement
# add installment button
def add_installement(self):
self.env["sale.order.line"].create(
[
{
"order_id": self.env.context.get("active_id"),
"product_id": self.env.ref("installment.product1").id,
"price_unit": self.installement_amount,
},
{
"order_id": self.env.context.get("active_id"),
"product_id": self.env.ref("installment.product2").id,
"price_unit": self.down_payment,
},
]
)
self.env['sale.order.line'].create([{
'order_id': self.env.context.get('active_id'),
'product_id':self.env.ref('installment.product1').id,
'price_unit':self.installement_amount
},
{
'order_id': self.env.context.get('active_id'),
'product_id':self.env.ref('installment.product2').id,
'price_unit':self.down_payment
}
])

1 change: 1 addition & 0 deletions installment/wizard/inherit_subscription.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<odoo>
<record id="add_emi_view" model="ir.ui.view">
<field name="name">add.emi.view</field>
<field name="mode">extension</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
Expand Down
2 changes: 2 additions & 0 deletions warranty/__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 warranty/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Product Warranty",
"version": "1.0",
"license": "LGPL-3",
"depends": ["base","stock","sale_management"],
"data": [
"security/ir.model.access.csv",
"wizard/add_warranty_button_action.xml",
"views/inherit_product_template.xml",
"views/add_warranty_button.xml",
"views/waranty_configuration_views.xml",
"views/warranty_configuration.xml",
],
"installable": True,
"application": True,
}
4 changes: 4 additions & 0 deletions warranty/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import product_warranty
from . import product_template
from . import warranty_configuration
from . import sale_order
8 changes: 8 additions & 0 deletions warranty/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models, fields, api

class ProductTemplate(models.Model):
_inherit = 'product.template'


is_warranty_available = fields.Boolean()

7 changes: 7 additions & 0 deletions warranty/models/product_warranty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import models, fields, api


class ProductWarranty(models.Model):
_name='product.warranty'

name = fields.Char('Title')
22 changes: 22 additions & 0 deletions warranty/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import models
from datetime import timedelta
from odoo.exceptions import UserError


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

def add_warranty_wizard_button(self):
products = self.order_line
for product in products:
if product.product_template_id.is_warranty_available:
return {
'type': 'ir.actions.act_window',
'name': 'Add Warranty',
'res_model': 'add.warranty',
'view_mode': 'form',
'view_id': self.env.ref('warranty.view_warranty_form').id,
'target': 'new',
}
else:
raise UserError('This product does not have a warranty.')
10 changes: 10 additions & 0 deletions warranty/models/warranty_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models, fields, api


class WarrantyConfiguration(models.Model):
_name='warranty.configuration'

name = fields.Char()
product_id = fields.Many2one('product.template',string="product")
period = fields.Integer('Period')
percentage = fields.Float()
5 changes: 5 additions & 0 deletions warranty/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
warranty.access_product_warranty,access_product_warranty,model_product_warranty,base.group_user,1,1,1,1
warranty.access_warranty_configuration,access_warranty_configuration,warranty.model_warranty_configuration,base.group_user,1,1,1,1
warranty.access_add_warranty,access_add_warranty,warranty.model_add_warranty,base.group_user,1,1,1,1
warranty.access_add_warranty_line,access_add_warranty_line,warranty.model_add_warranty_line,base.group_user,1,1,1,1
15 changes: 15 additions & 0 deletions warranty/views/add_warranty_button.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.warranty</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//div//button[@name='action_open_discount_wizard']" position="before">
<button string="Add Warranty"
name="add_warranty_wizard_button"
type="object"
class="btn btn-primary"/>
</xpath>
</field>
</record>
</odoo>
Loading

0 comments on commit 456c8ed

Please sign in to comment.