Skip to content

Added deposit for rental products - #500

Draft
jmra-odoo wants to merge 1 commit into
odoo:18.0from
odoo-dev:18.0-rental-add-deposit-jmra
Draft

jmra-odoo wants to merge 1 commit into
odoo:18.0from
odoo-dev:18.0-rental-add-deposit-jmra

Conversation

@jmra-odoo

Copy link
Copy Markdown

With This Commit

  • Added deposit product configuration in settings.
  • Inherited product.template to add require_deposit & deposit_amount field.
  • Linked deposit product automatically to rental product in sale order line.
  • Synced deposit product quantity with main product in cart.
  • Disabled remove button and quantity changer for deposit products in cart view.

@robodoo

robodoo commented Mar 3, 2025

Copy link
Copy Markdown

Pull request status dashboard

@jmra-odoo
jmra-odoo force-pushed the 18.0-rental-add-deposit-jmra branch 3 times, most recently from aca29c1 to 9e2db7e Compare March 4, 2025 05:25

@rare-odoo rare-odoo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jmra-odoo,
Great work 👏
I've made a few suggestions for your consideration.

Comment on lines +11 to +12
const $depositSpan = $('#product_deposit_amount');
if (!$depositSpan.length) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using jQuery.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, replaced with JS.

deposit_product_id = int(self.env['ir.config_parameter'].get_param('deposit_product_id'))
deposit_product = self.env['product.product'].browse(deposit_product_id)
if deposit_product:
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}"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not filter by name.
Will this code still work if there are multiple records in 'self'?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtered by linked_line_id so now no need for complex or filter by name.
No it will not work with multiple records in self as i thought there is no possibility to create multiple records but yes there can be a chance to create multiple so updated with looped approach.


def set_values(self):
super().set_values()
self.env['ir.config_parameter'].sudo().set_param('deposit_product_id', self.deposit_product_id.id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is sudo used?

Copy link
Copy Markdown
Author

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.

@jmra-odoo
jmra-odoo force-pushed the 18.0-rental-add-deposit-jmra branch from 9e2db7e to d981eea Compare March 6, 2025 10:45
Comment on lines +15 to +16
if not deposit_product:
raise ValidationError("Deposit product is not set in the setting.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid this error, as it unnecessarily interrupts the flow.

With This Commit
========================================================

- Added deposit product configuration in settings.
- Inherited product.template to add require_deposit & deposit_amount field.
- Linked deposit product automatically to rental product in sale order line.
- Synced deposit product quantity with main product in cart.
- Disabled remove button and quantity changer for deposit products in cart view.
@jmra-odoo
jmra-odoo force-pushed the 18.0-rental-add-deposit-jmra branch from d981eea to 054ca6f Compare March 7, 2025 11:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants