-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[IMP] rental_deposit: added deposit in rental #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ppch-odoo
wants to merge
6
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-imp-deposit-in-rental-ppch
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−0
Draft
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
316efb2
[IMP] rental_deposit: added deposit in rental config settings
ppch-odoo 2e0f893
[IMP] rental_deposit: added deposit in sale order line
ppch-odoo 08a1350
[IMP] rental_deposit: Improved by adding below changes
ppch-odoo 3c41b97
[IMP] rental_deposit: Improved by overriding copy_data
ppch-odoo ea8e259
[IMP] rental_deposit: improved Rental Deposit by some changes
ppch-odoo 908ad13
[IMP] rental_deposit: sudo() removed
ppch-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
'name': "Rental Deposit", | ||
'version': '1.0', | ||
'depends': ['website_sale_renting'], | ||
'author': "ppch", | ||
'category': 'Category', | ||
'description': """ | ||
Rental Deposit is configured and it will be added as deposit product whenever any product | ||
which has deposit required will be true and it will work in both frontend and backend | ||
""", | ||
'license': "LGPL-3", | ||
'data': [ | ||
'views/res_config_settings_views.xml', | ||
'views/product_template_views.xml', | ||
'views/website_rent_template.xml' | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import product_template | ||
from . import res_config_settings | ||
from . import sale_order | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
|
||
require_deposit = fields.Boolean(string="Require Deposit") | ||
deposit_amount = fields.Float(string="Deposit Amount") | ||
|
||
@api.onchange('require_deposit') | ||
def _onchange_require_deposit(self): | ||
self.write({ | ||
'deposit_amount': 0 if self.require_deposit else 0 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
deposit_product_id = fields.Many2one( | ||
'product.product', | ||
string="Deposit Product", | ||
config_parameter='rental_deposit.deposit_product_id' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from odoo import Command, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
def _get_copiable_order_lines_without_deposit(self): | ||
"""Returns the order lines that can be copied to a new order without copying deposit order line.""" | ||
deposit_product_id = self.env['ir.config_parameter'].get_param('rental_deposit.deposit_product_id') | ||
return self.order_line.filtered(lambda line: line.product_id.id != int(deposit_product_id)) | ||
|
||
def copy_data(self, default=None): | ||
"""Override copy_data to prevent deposit lines from being duplicated.""" | ||
default = dict(default or {}) | ||
default.setdefault('order_line', []) | ||
vals_list = super().copy_data(default=default) | ||
for order, vals in zip(self, vals_list): | ||
vals['order_line'] = [ | ||
Command.create(line) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where have you define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. below line 19, in for loop Command.create(line) |
||
for line in order._get_copiable_order_lines_without_deposit().copy_data() | ||
] | ||
return vals_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
"""Create deposit lines automatically for products that require a deposit.""" | ||
lines = super().create(vals_list) | ||
|
||
deposit_product_id = self.env['ir.config_parameter'].sudo().get_param('rental_deposit.deposit_product_id') | ||
ppch-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
deposit_product = self.env["product.product"].browse(int(deposit_product_id)) | ||
|
||
if not deposit_product_id: | ||
raise UserError(_("Please select deposit product from configuration")) | ||
ppch-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for line in lines: | ||
if line.product_id and line.product_id.product_tmpl_id.require_deposit: | ||
deposit_price = line.product_id.product_tmpl_id.deposit_amount if line.product_id.product_tmpl_id.deposit_amount else deposit_product.lst_price | ||
self.create([{ | ||
"order_id": line.order_id.id, | ||
"product_id": deposit_product.id, | ||
"name": f"Deposit for {line.product_id.name}", | ||
"product_uom_qty": line.product_uom_qty, | ||
"price_unit": deposit_price, | ||
"linked_line_id": line.id, | ||
}]) | ||
ppch-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return lines | ||
|
||
def write(self, vals_list): | ||
"""Update deposit lines when the main product quantity changes.""" | ||
lines = super().write(vals_list) | ||
|
||
deposit_product_id = self.env['ir.config_parameter'].sudo().get_param('rental_deposit.deposit_product_id') | ||
ppch-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
deposit_product = self.env['product.product'].browse(int(deposit_product_id)) | ||
|
||
if not deposit_product_id: | ||
raise UserError(_("Please select a deposit product from configuration.")) | ||
|
||
for line in self: | ||
deposit_line = self.env['sale.order.line'].search([ | ||
("order_id", "=", line.order_id.id), | ||
("linked_line_id", "=", line.id), | ||
("product_id", "=", deposit_product.id) | ||
], limit=1) | ||
|
||
if line.product_id and line.product_id.product_tmpl_id.require_deposit: | ||
deposit_price = line.product_id.product_tmpl_id.deposit_amount or deposit_product.lst_price | ||
if deposit_line: | ||
deposit_line.write({ | ||
"product_uom_qty": line.product_uom_qty, | ||
"price_unit": deposit_price, | ||
}) | ||
else: | ||
self.create({ | ||
"order_id": line.order_id.id, | ||
"product_id": deposit_product.id, | ||
"name": f"Deposit for {line.product_id.name}", | ||
"product_uom_qty": line.product_uom_qty, | ||
"price_unit": deposit_price, | ||
"linked_line_id": line.id, | ||
}) | ||
ppch-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
elif deposit_line: | ||
deposit_line.unlink() | ||
|
||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="product_template_form_view_rental_deposit" model="ir.ui.view"> | ||
<field name="name">product.template.form.inherit.rental.deposit</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="sale_renting.product_template_form_view_rental"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='extra_rental']" position="inside"> | ||
<field name="require_deposit"/> | ||
<field name="deposit_amount" invisible="require_deposit == False"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<!-- Inherited View For Rental Settings --> | ||
<record id="res_config_settings_view_form_inherit_rental_deposit" model="ir.ui.view"> | ||
<field name="name">res.config.settings.view.form.inherit.rental.deposit</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="sale_renting.res_config_settings_view_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//setting[@name='rental_delay_costs']" position="after"> | ||
<setting string="Deposit Product" help="Set a product to be used for deposit on sale order"> | ||
<field name="deposit_product_id" placeholder="Select a product"/> | ||
</setting> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="website_sale_renting_deposit" inherit_id="website_sale_renting.rental_product" name="Deposit"> | ||
<xpath expr="//div[@id='product_attributes_simple']" position="after"> | ||
<t t-set="info" t-value="product"/> | ||
<div t-if="info.require_deposit" class="mb-4"> | ||
<strong class="attribute_name">Required Deposit for 1 Quantity:</strong> | ||
<span t-out="info.deposit_amount"/> | ||
</div> | ||
</xpath> | ||
</template> | ||
</odoo> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed
I was checking that if someone after setting a deposit untick then retick on that time it should be zero.
But it i forgot to remove it
so i will remove it