Skip to content
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
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

jmra-odoo
Copy link

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
Copy link

robodoo commented Mar 3, 2025

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
Copy link

@rare-odoo rare-odoo left a comment

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;

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
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}"))

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
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)

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
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.")

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
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