Skip to content

Commit

Permalink
[MIG]rental_pricelist: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Sep 20, 2024
1 parent ca4cdce commit 374391d
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 242 deletions.
82 changes: 73 additions & 9 deletions rental_pricelist/README.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
================
Rental Pricelist
====================================================
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:abb8d54f6920d71a4ca8c6ffe2552ecebbbca7f055e9029cc8ef05bc6d3779db
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fvertical--rental-lightgray.png?logo=github
:target: https://github.com/OCA/vertical-rental/tree/16.0/rental_pricelist
:alt: OCA/vertical-rental
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/vertical-rental-16-0/vertical-rental-16-0-rental_pricelist
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/vertical-rental&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

*This file has been generated on 2022-05-04-12-21-41. Changes to it will be overwritten.*

Summary
-------

Enables the user to define different rental prices with time uom (Month, Day and Hour).

Description
-----------

Rental prices are usually scaled prices based on a time unit, typically day, sometimes months or hour.
This modules integrates the standard Odoo pricelists into rental use cases and allows the user an
easy way to specify the prices in a product tab as well as to use all the enhanced pricelist features.

**Table of contents**

.. contents::
:local:

Usage
-----
=====

Create a rentable product:
* Go to Rentals > Configuration > Settings.
Expand Down Expand Up @@ -55,8 +80,47 @@ Create a rental order:
Please also see the usage section of sale_rental and rental_base module.

Changelog
---------
=========

- 8d191ff7 2022-04-10 15:41:16 +0200 [email protected] add missing/lost documentation (issue #4516)
- 4509f78a 2022-02-23 20:48:33 +0100 [email protected] (origin/feature_4516_add_files_ported_from_v12_v14, feature_4516_add_files_ported_from_v12_v14) add files ported to v14 by cpatel and khanhbui (issue #4516)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/vertical-rental/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/vertical-rental/issues/new?body=module:%20rental_pricelist%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* elego Software Solutions GmbH

Contributors
~~~~~~~~~~~~

elego Software Solutions GmbH, Odoo Community Association (OCA)

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/vertical-rental <https://github.com/OCA/vertical-rental/tree/16.0/rental_pricelist>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 0 additions & 4 deletions rental_pricelist/README/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

Configuration
-------------

To configure this module, you need to:

#. Go to company settings and define the default interval ranges on 'Rental Interval Prices' tab.
Expand Down
4 changes: 0 additions & 4 deletions rental_pricelist/README/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

Contributors
------------

elego Software Solutions GmbH, Odoo Community Association (OCA)
9 changes: 0 additions & 9 deletions rental_pricelist/README/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
Rental Pricelist
====================================================

*This file has been generated on 2022-05-04-12-21-41. Changes to it will be overwritten.*

Summary
-------

Enables the user to define different rental prices with time uom (Month, Day and Hour).

Description
-----------

Rental prices are usually scaled prices based on a time unit, typically day, sometimes months or hour.
This modules integrates the standard Odoo pricelists into rental use cases and allows the user an
easy way to specify the prices in a product tab as well as to use all the enhanced pricelist features.
4 changes: 0 additions & 4 deletions rental_pricelist/README/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@

Changelog
---------

- 8d191ff7 2022-04-10 15:41:16 +0200 [email protected] add missing/lost documentation (issue #4516)
- 4509f78a 2022-02-23 20:48:33 +0100 [email protected] (origin/feature_4516_add_files_ported_from_v12_v14, feature_4516_add_files_ported_from_v12_v14) add files ported to v14 by cpatel and khanhbui (issue #4516)
4 changes: 0 additions & 4 deletions rental_pricelist/README/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

Usage
-----

Create a rentable product:
* Go to Rentals > Configuration > Settings.
* Please activate the checkbox for using 'Product Variants'.
Expand Down
2 changes: 1 addition & 1 deletion rental_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Rental Pricelist",
"summary": "Enables the user to define different rental prices with "
"time uom (Month, Day and Hour).",
"version": "14.0.1.0.2",
"version": "16.0.1.0.1",
"category": "Rental",
"author": "elego Software Solutions GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/vertical-rental",
Expand Down
4 changes: 2 additions & 2 deletions rental_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Part of rental-vertical See LICENSE file for full copyright and licensing details.

from . import sale
from . import sale_order_line
from . import sale_order
from . import product
from . import product_pricelist_item
from . import res_company
46 changes: 28 additions & 18 deletions rental_pricelist/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,39 @@ def _check_rental(self):
if product.rented_product_id:
if product.type != "service":
raise ValidationError(
_("The rental product '%s' must be of type 'Service'.")
% product.name
_("The rental product '%(name)s' must be of type 'Service'.")
% {"name": product.name}
)
if not product.must_have_dates:
raise ValidationError(
_(
"The rental product '%s' must have the option "
"The rental product '%(name)s' must have the option "
"'Must Have Start and End Dates' checked."
)
% product.name
% {"name": product.name}
)

@api.model
def _get_rental_service_prefix_suffix(self, field, str_type, rental_type):
field_name = "rental_service_%s_%s_%s" % (field, str_type, rental_type)
field_name = "rental_service_%(field)s_%(str_type)s_%(rental_type)s" % {
"field": field,
"str_type": str_type,
"rental_type": rental_type,
}
res = getattr(self.env.user.company_id, field_name)
return res

def _get_rental_service(self, rental_type):
self.ensure_one()
if rental_type == "month" and self.product_rental_month_id:
return self.product_rental_month_id
elif rental_type == "day" and self.product_rental_day_id:
if rental_type == "day" and self.product_rental_day_id:
return self.product_rental_day_id
elif rental_type == "hour" and self.product_rental_hour_id:
if rental_type == "hour" and self.product_rental_hour_id:
return self.product_rental_hour_id
else:
raise exceptions.ValidationError(
_("The product has no related rental services.")
)
raise exceptions.ValidationError(
_("The product has no related rental services.")
)

def _get_rental_service_list(self):
self.ensure_one()
Expand Down Expand Up @@ -183,9 +186,9 @@ def _get_rental_service_name(self, rental_type, sp_name):
suffix = self._get_rental_service_prefix_suffix("name", "suffix", rental_type)
name = sp_name
if prefix:
name = "%s %s" % (prefix, name)
name = "%(prefix)s %(name)s" % {"prefix": prefix, "name": name}
if suffix:
name = "%s %s" % (name, suffix)
name = "%(name)s %(suffix)s" % {"name": name, "suffix": suffix}
return name

def _get_rental_service_default_code(self, rental_type, sp_code):
Expand All @@ -199,9 +202,15 @@ def _get_rental_service_default_code(self, rental_type, sp_code):
default_code = sp_code
if default_code:
if prefix:
default_code = "%s-%s" % (prefix, default_code)
default_code = "%(prefix)s-%(default_code)s" % {
"prefix": prefix,
"default_code": default_code,
}
if suffix:
default_code = "%s-%s" % (default_code, suffix)
default_code = "%(default_code)s-%(suffix)s" % {
"default_code": default_code,
"suffix": suffix,
}
else:
default_code = ""
return default_code
Expand All @@ -211,10 +220,12 @@ def _create_rental_service(self, rental_type, product, price=0):
uom = self._get_rental_service_uom(rental_type)
values = {
"hw_product_id": product.id,
"name": _("Rental of %s (%s)") % (product.name, uom.name),
"name": _("Rental of %(product_name)s (%(uom_name)s)")
% {"product_name": product.name, "uom_name": uom.name},
"categ_id": product.categ_id.id,
"copy_image": True,
"default_code": "RENT-%s-%s" % (rental_type.upper(), product.default_code),
"default_code": "RENT-%(rental)s-%(code)s"
% {"rental": rental_type.upper(), "code": product.default_code},
}
res = (
self.env["create.rental.product"]
Expand Down Expand Up @@ -290,7 +301,6 @@ def _update_rental_service_fields(self, vals, fields, rental_services):
for field in fields:
if field in vals:
service_vals[field] = vals.get(field, False)
# check 'active' becomes True from False
check_rental_services = (
service_vals.get("active", False)
and not self.rental_service_ids
Expand Down
5 changes: 4 additions & 1 deletion rental_pricelist/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ def _onchange_product_id(self):
uom_month = self.env.ref("rental_base.product_uom_month")
uom_day = self.env.ref("uom.product_uom_day")
uom_hour = self.env.ref("uom.product_uom_hour")
super()._onchange_product_id()
res = super()._onchange_product_id()
if self.product_id.rented_product_id:
if self.product_id.uom_id.id == uom_month.id:
self.month_item_id = self.product_id.rented_product_id.id

if self.product_id.uom_id.id == uom_day.id:
self.day_item_id = self.product_id.rented_product_id.id

if self.product_id.uom_id.id == uom_hour.id:
self.hour_item_id = self.product_id.rented_product_id.id
return res
20 changes: 20 additions & 0 deletions rental_pricelist/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import _, models
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = "sale.order"

def _check_rental_order_line(self):
for order in self:
for line in order.order_line:
if line.rental and line.product_id:
if line.product_id.type != "service":
raise UserError(
_("The product %(name)s is not correctly configured.")
% {"name": line.product_id.name}
)

def action_confirm(self):
self._check_rental_order_line()
return super().action_confirm()
Loading

0 comments on commit 374391d

Please sign in to comment.