Skip to content

Commit 9a7ae06

Browse files
committed
[ADD] rental: Implemented deposit work flow for rental orders
- Added a field in Rental Settings to configure a default deposit product (rental_product_id). - Extended product template with require_deposite and deposite_amount fields under Rental tab. - Automatically creates a deposit order line linked to the main rental product line when deposit is required. - Ensures deposit line quantity syncs with the main rental product quantity and is read only. - Displayed deposit amount on the product page (website_sale). - Updated the cart and checkout views to include and properly handle deposit lines.
1 parent 605ad98 commit 9a7ae06

10 files changed

+153
-0
lines changed

deposite_in_rental/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

deposite_in_rental/__manifest__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "deposite_in_rental",
3+
"depends": ["base", "account_invoice_extract", "sale_renting", "website_sale"],
4+
"data": [
5+
"views/res_config_setting_rental_view.xml",
6+
"views/product_template_inherit_view.xml",
7+
"views/website_rental_inherit.xml",
8+
"views/sale_order_line_inherit_view.xml",
9+
],
10+
"license": "LGPL-3",
11+
}

deposite_in_rental/models/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import res_config_settings_inherit
2+
from . import product_template_inherit
3+
from . import sale_order_line_rental_inherit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import fields, models
2+
3+
4+
class ProductTemplateInherit(models.Model):
5+
_inherit = "product.template"
6+
7+
require_deposite = fields.Boolean(string="Requires Deposite?")
8+
deposite_amount = fields.Monetary(string="Deposite Amount")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from odoo import api, fields, models
2+
3+
4+
class ResConfigSettingInherit(models.TransientModel):
5+
_inherit = "res.config.settings"
6+
7+
rental_product_id = fields.Many2one(
8+
"product.product",
9+
string="Deposite Product",
10+
inverse="_set_rental_product",
11+
compute="_get_rental_product",
12+
)
13+
14+
def _set_rental_product(self):
15+
self.env["ir.config_parameter"].set_param(
16+
"rental.deposite_product", self.rental_product_id.id or ""
17+
)
18+
19+
@api.depends()
20+
def _get_rental_product(self):
21+
return int(self.env["ir.config_parameter"].get_param("rental.deposite_product"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from odoo import api, models, fields
2+
3+
4+
class SaleOrderLineRentalInherit(models.Model):
5+
_inherit = "sale.order.line"
6+
main_rental_id = fields.Many2one("sale.order.line", ondelete="cascade")
7+
child_rental_id = fields.Many2one("sale.order.line", ondelete="cascade")
8+
9+
@api.model_create_multi
10+
def create(self, vals_list):
11+
res = super().create(vals_list)
12+
deposit_product_id = (
13+
self.env["ir.config_parameter"].sudo().get_param("rental.deposite_product")
14+
)
15+
for line in res:
16+
if (
17+
deposit_product_id
18+
and line.product_template_id.require_deposite
19+
and line.product_template_id.deposite_amount
20+
):
21+
child_rental_ol = self.env["sale.order.line"].create(
22+
{
23+
"order_id": line.order_id.id,
24+
"product_id": (int)(deposit_product_id),
25+
"name": f"Deposit for {line.product_id.name}",
26+
"product_uom_qty": line.product_uom_qty,
27+
"price_unit": line.product_template_id.deposite_amount,
28+
"main_rental_id": line.id,
29+
}
30+
)
31+
line.child_rental_id = child_rental_ol.id
32+
return res
33+
34+
def write(self, vals):
35+
for line in self:
36+
if line.child_rental_id and "product_uom_qty" in vals:
37+
qty = vals["product_uom_qty"]
38+
line.child_rental_id.write(
39+
{
40+
"product_uom_qty": qty,
41+
"price_unit": line.product_template_id.deposite_amount,
42+
}
43+
)
44+
return super().write(vals)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="product_template_rental_inherit" model="ir.ui.view">
4+
<field name="name">Product.Template.Rental.Inherit</field>
5+
<field name="model">product.template</field>
6+
<field name="inherit_id" ref="sale_renting.product_template_form_view_rental"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//page[@name='pricing']//group[@name='extra_rental']" position="inside">
9+
<field name="require_deposite"/>
10+
<field name="deposite_amount" invisible="not require_deposite"/>
11+
</xpath>
12+
</field>
13+
</record>
14+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="rental_config_setting_inherit" model="ir.ui.view">
4+
<field name="name">Rental config inherit</field>
5+
<field name="model">res.config.settings</field>
6+
<field name="inherit_id" ref="sale_renting.res_config_settings_view_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//form//setting[@name='rental_delay_costs']//div[hasclass('content-group')]" position='inside'>
9+
<div class="row mt2 oe-inline">
10+
<label for="rental_product_id"/>
11+
<field name="rental_product_id"/>
12+
</div>
13+
</xpath>
14+
</field>
15+
</record>
16+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="sale_order_inherit_view_rental" model="ir.ui.view">
4+
<field name="name">Sale.Order.Inherit.View.Rental</field>
5+
<field name="model">sale.order</field>
6+
<field name="inherit_id" ref="sale.view_order_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//field[@name='order_line']//list//field[@name='product_template_id']" position="attributes">
9+
<attribute name="readonly">main_rental_id</attribute>
10+
</xpath>
11+
<xpath expr="//field[@name='order_line']//list//field[@name='product_uom_qty']" position="attributes">
12+
<attribute name="readonly">main_rental_id</attribute>
13+
</xpath>
14+
<xpath expr="//field[@name='order_line']//list//field[@name='price_unit']" position="attributes">
15+
<attribute name="readonly">main_rental_id</attribute>
16+
</xpath>
17+
</field>
18+
</record>
19+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<template id="website_product_rental" inherit_id="website_sale.product">
4+
<xpath expr="//div[@id='product_detail_main']//div[@id='o_wsale_cta_wrapper']" position="after">
5+
<div class="my-2" t-if='product.deposite_amount'>
6+
<h4>Deposite Amount: $<t t-esc='product.deposite_amount'/>
7+
</h4>
8+
</div>
9+
</xpath>
10+
</template>
11+
<template id="website_sale_stock_cart_lines" inherit_id="website_sale.cart_lines" name="Shopping Cart Lines">
12+
<xpath expr="//div[@name='website_sale_cart_line_quantity']" position="attributes">
13+
<attribute name="t-att-class">'d-none' if line.main_rental_id else ''+('css_quantity input-group mb-2')</attribute>
14+
</xpath>
15+
</template>
16+
</odoo>

0 commit comments

Comments
 (0)