-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] rental_deposit: implement deposit amount feature for rental products #898
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
rodh-odoo
wants to merge
1
commit into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-deposit-rodh
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.
Draft
Changes from all commits
Commits
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 hidden or 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 hidden or 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,17 @@ | ||
{ | ||
'name': 'Rental Deposit', | ||
'version': '1.0', | ||
'category': 'Rental', | ||
'author': 'rodh', | ||
'license': "LGPL-3", | ||
'summary': 'Add deposit product functionality for rentals', | ||
'depends': ['sale_renting', 'website_sale'], | ||
'data': [ | ||
'views/res_config_settings_views.xml', | ||
'views/product_template_views.xml', | ||
'views/website_sale_product.xml', | ||
], | ||
'installable': True, | ||
'auto_install': False, | ||
'application': False, | ||
} |
This file contains hidden or 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 hidden or 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,31 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
|
||
require_deposit = fields.Boolean(string="Require Deposit") | ||
deposit_amount = fields.Monetary(string="Deposit Amount", currency_field='currency_id') | ||
|
||
@api.onchange('require_deposit') | ||
def _onchange_requires_deposit(self): | ||
if self.require_deposit: | ||
param_obj = self.env['ir.config_parameter'].sudo() | ||
deposit_product_id = param_obj.get_param('rental_deposit.deposit_product_id') | ||
if deposit_product_id: | ||
deposit_product = self.env['product.product'].browse(int(deposit_product_id)) | ||
if deposit_product: | ||
self.deposit_amount = deposit_product.list_price | ||
else: | ||
self.deposit_amount = 0.0 | ||
else: | ||
self.deposit_amount = 0.0 | ||
else: | ||
self.deposit_amount = 0.0 | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
require_deposit = fields.Boolean(related='product_tmpl_id.require_deposit', readonly=False) | ||
deposit_amount = fields.Monetary(related='product_tmpl_id.deposit_amount', currency_field='currency_id', readonly=False) |
This file contains hidden or 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 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
rental_deposit_product_id = fields.Many2one( | ||
'product.product', | ||
string='Deposit Product', | ||
domain=[('sale_ok', '=', True)], | ||
config_parameter='rental_deposit.product_id' | ||
) |
This file contains hidden or 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,35 @@ | ||
from odoo import api, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
orders = super().create(vals_list) | ||
for order in orders: | ||
order._add_deposit_lines() | ||
return orders | ||
|
||
def _add_deposit_lines(self): | ||
for line in self.order_line: | ||
product = line.product_id | ||
if product.require_deposit: | ||
exists = self.order_line.filtered( | ||
lambda l: l.is_deposit_line and l.product_id == product | ||
) | ||
if not exists: | ||
self.env['sale.order.line'].create({ | ||
'order_id': self.id, | ||
'product_id': product.id, | ||
'name': f"Deposit for {product.display_name}", | ||
'product_uom_qty': line.product_uom_qty, | ||
'price_unit': product.deposit_amount, | ||
'is_deposit_line': True, | ||
}) | ||
|
||
def _cart_update(self, product_id=None, line_id=None, add_qty=0, set_qty=0, **kwargs): | ||
res = super()._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, **kwargs) | ||
self._add_deposit_lines() | ||
|
||
return res |
This file contains hidden or 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,28 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
deposit_amount = fields.Monetary( | ||
string="Deposit Amount", | ||
compute="_compute_deposit_amount", | ||
currency_field="currency_id" | ||
) | ||
is_deposit_line = fields.Boolean( | ||
string="Is Deposit Line", | ||
help="Indicates whether this line is for a rental deposit", | ||
default=False | ||
) | ||
|
||
@api.depends('product_id') | ||
def _compute_is_deposit_line(self): | ||
for line in self: | ||
line.is_deposit_line = line.product_id and line.product_id.is_deposit_product | ||
Comment on lines
+12
to
+21
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. You define |
||
|
||
def _compute_deposit_amount(self): | ||
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. depends on? |
||
for line in self: | ||
if line.product_id.rent_ok: | ||
line.deposit_amount = line.product_id.deposit_amount or (line.price_unit * 0.5) | ||
else: | ||
line.deposit_amount = 0.0 |
This file contains hidden or 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,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_sale_order_line_deposit,sale.order.line.deposit,model_sale_order_line,,1,1,1,1 |
This file contains hidden or 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> | ||
<record id="product_template_inherit" model="ir.ui.view"> | ||
<field name="name">product.template.inherit</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_only_form_view"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//page[@name='pricing']" position="inside"> | ||
<group name="deposit" string="Deposit"> | ||
<field name="require_deposit"/> | ||
<field name="deposit_amount" invisible="not require_deposit"/> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains hidden or 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,13 @@ | ||
<odoo> | ||
<record id="rental_res_config_settings_view_form_inherit" model="ir.ui.view"> | ||
<field name="name">res.config.settings.view.form.deposit</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="base.res_config_settings_view_form"/> | ||
<field name="arch" type="xml"> | ||
<setting name="rental_delay_costs" position="inside"> | ||
<label for="rental_deposit_product_id" class="col-lg-3"/> | ||
<field name="rental_deposit_product_id" string="Deposit" widget="many2one" options="{'no_create': True}"/> | ||
</setting> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains hidden or 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,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="rental_deposit_product" inherit_id="website_sale.product"> | ||
<xpath expr="//div[@id='o_wsale_cta_wrapper']" position="after"> | ||
<t t-if="product.rent_ok and product.require_deposit"> | ||
<div class="mt16 alert alert-info"> | ||
<strong>Deposit Required: </strong> | ||
<span t-esc="product.deposit_amount" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/> | ||
</div> | ||
</t> | ||
</xpath> | ||
</template> | ||
<template id="cart_lines_deposit_control" inherit_id="website_sale.cart_lines"> | ||
<xpath expr="//div[@name='website_sale_cart_line_quantity']" position="replace"> | ||
<div name="website_sale_cart_line_quantity" class="css_quantity input-group"> | ||
<a href="#" class="js_add_cart_json btn btn-link border-end-0" aria-label="Remove one"> | ||
<i class="fa fa-minus"/> | ||
</a> | ||
<input type="text" class="js_quantity quantity form-control border-start-0 border-end-0" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-att-value="line.product_uom_qty"/> | ||
<a href="#" class="js_add_cart_json btn btn-link border-start-0" aria-label="Add one"> | ||
<i class="fa fa-plus"/> | ||
</a> | ||
</div> | ||
</xpath> | ||
<xpath expr="//a[hasclass('js_delete_product')]" position="attributes"> | ||
<attribute name="t-if">not line.is_deposit_line</attribute> | ||
</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.
Your
res_config_settings
usesconfig_parameter='rental_deposit.product_id'
but here you readparam_obj.get_param('rental_deposit.deposit_product_id')
. Shouldn't this key match? Am I missing anything?