Skip to content

Commit aca29c1

Browse files
committed
Added rental
1 parent 4c650f3 commit aca29c1

10 files changed

+167
-0
lines changed

deposit_renting/__init__.py

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

deposit_renting/__manifest__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'name': "Deposit Rental Products",
3+
'depends': ['sale_renting', 'website_sale'],
4+
'application': False,
5+
'installable': True,
6+
'license': 'LGPL-3',
7+
'data': [
8+
'views/product_template_views.xml',
9+
'views/res_config_settings_views.xml',
10+
'views/templates.xml',
11+
],
12+
'assets': {
13+
'web.assets_frontend': [
14+
'deposit_renting/static/src/js/product_deposit.js',
15+
],
16+
}
17+
}

deposit_renting/models/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import product_template
2+
from . import res_config_settings
3+
from . import sale_order_line
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')
8+
deposit_amount = fields.Float(string='Deposit Amount', help="Deposit amount for single unit.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 Product", help="Product to be used for deposit on sale order.")
8+
9+
def set_values(self):
10+
super().set_values()
11+
self.env['ir.config_parameter'].sudo().set_param('deposit_product_id', self.deposit_product_id.id)
12+
13+
def get_values(self):
14+
res = super().get_values()
15+
product_id = int(self.env['ir.config_parameter'].sudo().get_param('deposit_product_id', default=False))
16+
res['deposit_product_id'] = self.env['product.product'].browse(product_id)
17+
return res
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from odoo import api, fields, models
2+
3+
4+
class SaleOrderLine(models.Model):
5+
_inherit = "sale.order.line"
6+
7+
is_deposit_line = fields.Boolean(string="Is Deposit Line", default=False)
8+
9+
def _add_deposit_line(self):
10+
if not self.product_id:
11+
return
12+
13+
if self.order_id and self.product_id.rent_ok and self.product_id.require_deposit:
14+
deposit_product_id = int(self.env['ir.config_parameter'].get_param('deposit_product_id'))
15+
deposit_product = self.env['product.product'].browse(deposit_product_id)
16+
if deposit_product:
17+
deposit_line = self.order_id.order_line.filtered(lambda line: line.product_id == deposit_product and line.name.endswith(f"For {self.product_id.name}"))
18+
if deposit_line:
19+
deposit_line.product_uom_qty = self.product_uom_qty
20+
deposit_line.price_unit = self.product_id.deposit_amount
21+
else:
22+
self.env["sale.order.line"].create({
23+
'order_id': self.order_id.id,
24+
'product_id': deposit_product.id,
25+
'name': f"Deposit For {self.product_id.name}",
26+
'product_uom_qty': self.product_uom_qty,
27+
'price_unit': self.product_id.deposit_amount,
28+
'linked_line_id': self.id,
29+
'price_subtotal': self.product_uom_qty * self.product_id.deposit_amount,
30+
'is_deposit_line': True,
31+
})
32+
33+
@api.model_create_multi
34+
def create(self, vals_list):
35+
res = super().create(vals_list)
36+
res._add_deposit_line()
37+
return res
38+
39+
def write(self, vals):
40+
res = super().write(vals)
41+
if 'product_uom_qty' in vals:
42+
for line in self:
43+
linked_lines = self.search([('linked_line_id', '=', line.id)])
44+
for linked_line in linked_lines:
45+
linked_line.product_uom_qty = line.product_uom_qty
46+
linked_line.price_subtotal = line.product_uom_qty * line.product_id.deposit_amount
47+
48+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import publicWidget from "@web/legacy/js/public/public_widget";
2+
3+
publicWidget.registry.WebsiteSale.include({
4+
_onChangeAddQuantity: function (ev) {
5+
this._super.apply(this, arguments);
6+
this.changeDepositAmount(ev);
7+
},
8+
9+
changeDepositAmount: function(ev){
10+
const qty = parseFloat($(ev.target).val() || 1);
11+
const $depositSpan = $('#product_deposit_amount');
12+
if (!$depositSpan.length) return;
13+
14+
const baseDeposit = parseFloat($depositSpan.data('baseAmount') || 0);
15+
const currencySymbol = $depositSpan.data('currencySymbol') || '';
16+
const totalDeposit = (baseDeposit * qty).toFixed(2);
17+
$depositSpan.text(currencySymbol + ' ' + totalDeposit);
18+
}
19+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<odoo>
2+
<record id="product_template_form_view_deposit_renting" model="ir.ui.view">
3+
<field name="name">product.template.deposit.renting.form</field>
4+
<field name="model">product.template</field>
5+
<field name="inherit_id" ref="sale_renting.product_template_form_view_rental" />
6+
<field name="arch" type="xml">
7+
<group name="extra_rental" position="inside">
8+
<field name="require_deposit" />
9+
<field name="deposit_amount" invisible="not require_deposit" />
10+
</group>
11+
</field>
12+
</record>
13+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<odoo>
2+
<record id="res_config_settings_view_form_deposit_renting" model="ir.ui.view">
3+
<field name="name">res.config.settings.deposit.renting.form</field>
4+
<field name="model">res.config.settings</field>
5+
<field name="inherit_id" ref="sale_renting.res_config_settings_view_form" />
6+
<field name="arch" type="xml">
7+
<xpath expr="//setting[@name='rental_delay_costs']" position="after">
8+
<setting string="Deposit Product" help="Product to be used for deposit on sale order">
9+
<label string="Deposit" for="deposit_product_id" class="o_light_label me-3" />
10+
<field name="deposit_product_id" />
11+
</setting>
12+
</xpath>
13+
</field>
14+
</record>
15+
</odoo>

deposit_renting/views/templates.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<odoo>
2+
<template id="ecom_extra_deposit_field" inherit_id="website_sale.product">
3+
<xpath expr="//div[@id='o_wsale_cta_wrapper']" position="after">
4+
<t t-if="product.require_deposit">
5+
<div class="mt-3 d-flex justify-content-between" id="product_deposit_section">
6+
<strong>Deposit Required:</strong>
7+
<span id="product_deposit_amount"
8+
t-att-data-base-amount="product.deposit_amount"
9+
t-att-data-currency-symbol="website.company_id.currency_id.symbol">
10+
<t t-out="product.deposit_amount" />
11+
<t t-out="website.company_id.currency_id.symbol" />
12+
</span>
13+
</div>
14+
</t>
15+
</xpath>
16+
</template>
17+
18+
<template id="cart_line_readonly_quantity" inherit_id="website_sale.cart_lines" name="Readonly Quantity in Cart">
19+
<xpath expr="//div[@name='website_sale_cart_line_quantity']" position="before">
20+
<t t-set="show_qty" t-value="not line.is_deposit_line" />
21+
</xpath>
22+
<xpath expr="//div[@name='o_wsale_cart_line_button_container']/a[hasclass('js_delete_product')]" position="attributes">
23+
<attribute name="t-attf-class">#{'d-none' if line.is_deposit_line else 'js_delete_product'}</attribute>
24+
</xpath>
25+
</template>
26+
</odoo>

0 commit comments

Comments
 (0)