-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Added deposit for rental products #500
Draft
jmra-odoo
wants to merge
1
commit into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-rental-add-deposit-jmra
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 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': "Deposit Rental Products", | ||
'depends': ['sale_renting', 'website_sale'], | ||
'application': False, | ||
'installable': True, | ||
'license': 'LGPL-3', | ||
'data': [ | ||
'views/product_template_views.xml', | ||
'views/res_config_settings_views.xml', | ||
'views/templates.xml', | ||
'views/sale_order_view.xml', | ||
], | ||
'assets': { | ||
'web.assets_frontend': [ | ||
'deposit_renting/static/src/js/product_deposit.js', | ||
], | ||
} | ||
} |
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,8 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
require_deposit = fields.Boolean(string='Require Deposit') | ||
deposit_amount = fields.Float(string='Deposit Amount', help="Deposit amount for single unit.") |
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,17 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
deposit_product_id = fields.Many2one("product.product", string="Deposit Product", help="Product to be used for deposit on sale order.") | ||
|
||
def set_values(self): | ||
super().set_values() | ||
self.env['ir.config_parameter'].sudo().set_param('deposit_product_id', self.deposit_product_id.id) | ||
|
||
def get_values(self): | ||
res = super().get_values() | ||
product_id = int(self.env['ir.config_parameter'].sudo().get_param('deposit_product_id', default=False)) | ||
res['deposit_product_id'] = self.env['product.product'].browse(product_id) | ||
return res |
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,17 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
require_deposit_config = fields.Boolean(string="Require Deposit Configuration", default=False, compute="_compute_has_deposit_line_without_config", help="Has line that require deposit, without configuring the deposit product in settings.") | ||
|
||
@api.depends('order_line') | ||
def _compute_has_deposit_line_without_config(self): | ||
deposit_product_id = self.env['ir.config_parameter'].get_param('deposit_product_id') | ||
for sale_order in self: | ||
has_line_require_deposit_config = True if len(sale_order.order_line.filtered(lambda line: line.product_id.require_deposit)) > 0 else False | ||
if has_line_require_deposit_config and not deposit_product_id: | ||
sale_order.require_deposit_config = True | ||
else: | ||
sale_order.require_deposit_config = False |
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,45 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
is_deposit_line = fields.Boolean(string="Is Deposit Line", default=False) | ||
|
||
def _add_deposit_line(self): | ||
deposit_product_id = int(self.env['ir.config_parameter'].get_param('deposit_product_id')) | ||
deposit_product = self.env['product.product'].browse(deposit_product_id) | ||
for line in self: | ||
if line.order_id and line.product_id.rent_ok and line.product_id.require_deposit: | ||
deposit_line = line.order_id.order_line.filtered(lambda line: line.linked_line_id == self.id) | ||
if deposit_line: | ||
deposit_line.product_uom_qty = line.product_uom_qty | ||
deposit_line.price_unit = line.product_id.deposit_amount | ||
else: | ||
self.env["sale.order.line"].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': line.product_id.deposit_amount, | ||
'linked_line_id': line.id, | ||
'price_subtotal': line.product_uom_qty * line.product_id.deposit_amount, | ||
'is_deposit_line': True, | ||
}) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
res = super().create(vals_list) | ||
res._add_deposit_line() | ||
return res | ||
|
||
def write(self, vals): | ||
res = super().write(vals) | ||
if 'product_uom_qty' in vals: | ||
for line in self: | ||
linked_lines = self.search([('linked_line_id', '=', line.id)]) | ||
for linked_line in linked_lines: | ||
linked_line.product_uom_qty = line.product_uom_qty | ||
linked_line.price_subtotal = line.product_uom_qty * line.product_id.deposit_amount | ||
|
||
return res |
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,20 @@ | ||
import publicWidget from "@web/legacy/js/public/public_widget"; | ||
|
||
publicWidget.registry.WebsiteSale.include({ | ||
_onChangeAddQuantity: function (ev) { | ||
this._super.apply(this, arguments); | ||
this.changeDepositAmount(ev); | ||
}, | ||
|
||
changeDepositAmount: function(ev){ | ||
const input = ev.target; | ||
const qty = parseFloat(input.value || 1); | ||
const depositSpan = document.getElementById('product_deposit_amount'); | ||
if (!depositSpan) return; | ||
|
||
const baseDeposit = parseFloat(depositSpan.dataset.baseAmount || 0); | ||
const currencySymbol = depositSpan.dataset.currencySymbol || ''; | ||
const totalDeposit = (baseDeposit * qty).toFixed(2); | ||
depositSpan.textContent = `${currencySymbol} ${totalDeposit}`; | ||
} | ||
}) |
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,13 @@ | ||
<odoo> | ||
<record id="product_template_form_view_deposit_renting" model="ir.ui.view"> | ||
<field name="name">product.template.deposit.renting.form</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="sale_renting.product_template_form_view_rental" /> | ||
<field name="arch" type="xml"> | ||
<group name="extra_rental" position="inside"> | ||
<field name="require_deposit" /> | ||
<field name="deposit_amount" invisible="not require_deposit" /> | ||
</group> | ||
</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,15 @@ | ||
<odoo> | ||
<record id="res_config_settings_view_form_deposit_renting" model="ir.ui.view"> | ||
<field name="name">res.config.settings.deposit.renting.form</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="Product to be used for deposit on sale order"> | ||
<label string="Deposit" for="deposit_product_id" class="o_light_label me-3" /> | ||
<field name="deposit_product_id" /> | ||
</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,14 @@ | ||
<odoo> | ||
<record id="view_order_form_inherited" model="ir.ui.view"> | ||
<field name="name">sale.order.view.order.form.inherited</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//form/header" position="before"> | ||
<div class="alert alert-warning" role="alert" invisible="not require_deposit_config"> | ||
<span>Deposit product is not configured in setting.</span> | ||
</div> | ||
</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,26 @@ | ||
<odoo> | ||
<template id="ecom_extra_deposit_field" inherit_id="website_sale.product"> | ||
<xpath expr="//div[@id='o_wsale_cta_wrapper']" position="after"> | ||
<t t-if="product.require_deposit"> | ||
<div class="mt-3 d-flex justify-content-between" id="product_deposit_section"> | ||
<strong>Deposit Required:</strong> | ||
<span id="product_deposit_amount" | ||
t-att-data-base-amount="product.deposit_amount" | ||
t-att-data-currency-symbol="website.company_id.currency_id.symbol"> | ||
<t t-out="website.company_id.currency_id.symbol" /> | ||
<t t-out="product.deposit_amount" /> | ||
</span> | ||
</div> | ||
</t> | ||
</xpath> | ||
</template> | ||
|
||
<template id="cart_line_readonly_quantity" inherit_id="website_sale.cart_lines" name="Readonly Quantity in Cart"> | ||
<xpath expr="//div[@name='website_sale_cart_line_quantity']" position="before"> | ||
<t t-set="show_qty" t-value="not line.is_deposit_line" /> | ||
</xpath> | ||
<xpath expr="//div[@name='o_wsale_cart_line_button_container']/a[hasclass('js_delete_product')]" position="attributes"> | ||
<attribute name="t-attf-class">#{'d-none' if line.is_deposit_line else 'js_delete_product'}</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.
Why is sudo used?
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.
By using sudo(), it gets the access rights to superuser level, temporarily bypassing regular access rules, sometimes it is possible to not have the access right to admin of configuration settings. I have seen it in codebase too.