Skip to content

Commit 781ee29

Browse files
committed
[ADD] Rental Deposit: Configure and Display Deposit for Rental Products
In this commit: - Added option to set a deposit product from configuration - Introduced checkbox to enable deposit for rental products - Added a field to specify the deposit amount - Inherited sale order line to auto-add deposit line when rental product added - Synced deposit quantity with rental product quantity - Displayed deposit amount on the product page in the website - Shown deposit details with amount in the shopping cart
1 parent 4c650f3 commit 781ee29

File tree

10 files changed

+152
-0
lines changed

10 files changed

+152
-0
lines changed

deposit_in_rental_app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

deposit_in_rental_app/__manifest__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
'name': 'Rental Deposit',
3+
'installable': True,
4+
'license': 'LGPL-3',
5+
'depends': ['sale_renting', 'website_sale_renting'],
6+
'data': [
7+
'views/res_config_settings_views.xml',
8+
'views/product_template_views.xml',
9+
'views/templates.xml',
10+
],
11+
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import res_config_settings
2+
from . import product_template
3+
from . import sale_order_line
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import fields, models
2+
3+
4+
class ProductTemplate(models.Model):
5+
_inherit = 'product.template'
6+
7+
require_deposit = fields.Boolean(string='Require Deposit', default=False)
8+
deposit_amount = fields.Float(string='Amount')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import fields, models
2+
3+
4+
class ResConfigSettings(models.TransientModel):
5+
_inherit = 'res.config.settings'
6+
7+
deposit_product_id = fields.Many2one('product.product', string='Deposit', config_parameter='deposit_in_rental_app.deposit_product_id')
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from odoo import api, fields, models
2+
from odoo.exceptions import UserError
3+
4+
5+
class SaleOrderLine(models.Model):
6+
_inherit = 'sale.order.line'
7+
8+
is_deposit_line = fields.Boolean(default=False)
9+
parent_id = fields.Many2one(comodel_name="sale.order.line", ondelete='cascade', copy=False)
10+
child_ids = fields.One2many(comodel_name="sale.order.line", inverse_name="parent_id", copy=False)
11+
12+
@api.model_create_multi
13+
def create(self, vals_list):
14+
res = super().create(vals_list)
15+
# fetch deposit product name from ip.config.setting
16+
deposit_product_id = self.env["ir.config_parameter"].sudo().get_param("deposit_in_rental_app.deposit_product_id")
17+
18+
if not deposit_product_id:
19+
raise UserError("Set deposit product from setting")
20+
21+
for line in res:
22+
# If product line product is deposit enable create new deposit line
23+
if line.product_id.require_deposit and line.product_id.deposit_amount:
24+
deposit_order_line = self.env['sale.order.line'].create({
25+
"order_id": line.order_id.id,
26+
"product_id": int(deposit_product_id),
27+
"name": f"Deposit for {line.product_id.name}",
28+
"product_uom_qty": line.product_uom_qty,
29+
"price_unit": line.product_template_id.deposit_amount,
30+
"parent_id": line.id,
31+
"sequence": line.sequence + 1,
32+
"is_deposit_line": True,
33+
})
34+
35+
if not deposit_order_line:
36+
raise UserError("Something went wrong!!")
37+
38+
return res
39+
40+
def write(self, vals):
41+
res = super().write(vals)
42+
# Update quantity if deposit order line is already created
43+
if 'product_uom_qty' in vals:
44+
for line in self:
45+
if line.child_ids:
46+
line.child_ids.write({
47+
"product_uom_qty": vals['product_uom_qty'],
48+
"price_unit": line.child_ids.price_unit
49+
})
50+
return res
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="product_template_form_view" model="ir.ui.view">
5+
<field name="name">product.template.form.view.inherit.deposit.in.rental.app</field>
6+
<field name="model">product.template</field>
7+
<field name="inherit_id" ref="product.product_template_form_view" />
8+
<field name="arch" type="xml">
9+
<xpath expr="//group[@name='extra_rental']" position="inside">
10+
<field name="require_deposit" />
11+
<field name="deposit_amount" invisible="not require_deposit" widget="monetary" />
12+
</xpath>
13+
</field>
14+
</record>
15+
16+
</odoo>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="res_config_settings_view_form" model="ir.ui.view">
5+
<field name="name">res.config.settings.view.form.inherit.deposit.product</field>
6+
<field name="model">res.config.settings</field>
7+
<field name="inherit_id" ref="base.res_config_settings_view_form" />
8+
<field name="arch" type="xml">
9+
<xpath expr="//setting[@name='rental_delay_costs']" position="inside">
10+
<div class="row mt8">
11+
<label string="Deposit" for="deposit_product_id" class="col-lg-3 o_light_label"/>
12+
<field name="deposit_product_id" placeholder="Product to used for sale order" options="{'no_create': true}" domain="[('rent_ok', '=', True)]"/>
13+
</div>
14+
</xpath>
15+
</field>
16+
</record>
17+
18+
</odoo>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<template id="deposit_in_rental_app_template" inherit_id="website_sale_renting.rental_pricing_table">
5+
<xpath expr="//table[@id='oe_wsale_rental_pricing_table']//tbody" position="after">
6+
<t t-if="product.require_deposit and product.deposit_amount">
7+
<tr>
8+
<td t-attf-class="{{hide_border_bottom_classes}} ps-0"><strong>Deposit</strong></td>
9+
<td t-attf-class="{{hide_border_bottom_classes}} pe-0 text-muted text-end">
10+
<span t-esc="product.currency_id.symbol"/>
11+
<span id="deposit_amount">
12+
<t t-out="product.deposit_amount" />
13+
</span>
14+
</td>
15+
</tr>
16+
</t>
17+
</xpath>
18+
</template>
19+
20+
<template id="cart_lines_inherit_deposit" inherit_id="website_sale.cart_lines">
21+
<xpath expr="//t[@t-call='website_sale.cart_line_product_link']" position="inside">
22+
<t t-if="line.parent_id">
23+
<span class="d-inline align-top h6 fw-bold">for <t t-out="line.parent_id.product_id.name" /></span>
24+
</t>
25+
</xpath>
26+
<!-- hide remove button for deposit -->
27+
<xpath expr="//div[@name='o_wsale_cart_line_button_container']" position="attributes">
28+
<attribute name="t-if">not line.is_deposit_line</attribute>
29+
</xpath>
30+
<!-- hide quantity increment and decrement for deposit products -->
31+
<xpath expr="//div[@name='website_sale_cart_line_quantity']" position="attributes">
32+
<attribute name="t-if">not line.is_deposit_line</attribute>
33+
</xpath>
34+
</template>
35+
36+
</odoo>

0 commit comments

Comments
 (0)