Skip to content

Commit

Permalink
[MIG] rental_pricelist: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Nov 28, 2024
1 parent ed6f25d commit 34b6776
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 61 deletions.
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": "16.0.1.0.1",
"version": "17.0.1.0.0",
"category": "Rental",
"author": "elego Software Solutions GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/vertical-rental",
Expand Down
6 changes: 1 addition & 5 deletions rental_pricelist/hooks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Part of rental-vertical See LICENSE file for full copyright and licensing details.

from odoo import SUPERUSER_ID
from odoo.api import Environment


def set_multi_sales_price(cr, registry):
env = Environment(cr, SUPERUSER_ID, {})
def set_multi_sales_price(env):
conf_page = env["res.config.settings"].create({})
conf_page.group_uom = True
conf_page.group_product_pricelist = True
Expand Down
33 changes: 8 additions & 25 deletions rental_pricelist/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
class ProductProduct(models.Model):
_inherit = "product.product"

def _default_pricelist(self):
# TODO change default pricelist if country group exist
return self.env.ref("product.list0").id

rental_of_month = fields.Boolean(
string="Rented in months",
copy=False,
Expand Down Expand Up @@ -95,7 +91,6 @@ def _default_pricelist(self):
def_pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Default Pricelist",
default=lambda self: self._default_pricelist(),
)

# override from sale_rental, to remove Uom constrain
Expand All @@ -120,11 +115,7 @@ def _check_rental(self):

@api.model
def _get_rental_service_prefix_suffix(self, 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,
}
field_name = f"rental_service_{field}_{str_type}_{rental_type}"
res = getattr(self.env.user.company_id, field_name)
return res

Expand Down Expand Up @@ -186,9 +177,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 = "%(prefix)s %(name)s" % {"prefix": prefix, "name": name}
name = f"{prefix} {name}"
if suffix:
name = "%(name)s %(suffix)s" % {"name": name, "suffix": suffix}
name = f"{name} {suffix}"
return name

def _get_rental_service_default_code(self, rental_type, sp_code):
Expand All @@ -202,15 +193,9 @@ def _get_rental_service_default_code(self, rental_type, sp_code):
default_code = sp_code
if default_code:
if prefix:
default_code = "%(prefix)s-%(default_code)s" % {
"prefix": prefix,
"default_code": default_code,
}
default_code = f"{prefix}-{default_code}"
if suffix:
default_code = "%(default_code)s-%(suffix)s" % {
"default_code": default_code,
"suffix": suffix,
}
default_code = f"{default_code}-{suffix}"
else:
default_code = ""
return default_code
Expand All @@ -220,12 +205,10 @@ 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 %(product_name)s (%(uom_name)s)")
% {"product_name": product.name, "uom_name": uom.name},
"name": _(f"Rental of {product.name} ({uom.name})"),
"categ_id": product.categ_id.id,
"copy_image": True,
"default_code": "RENT-%(rental)s-%(code)s"
% {"rental": rental_type.upper(), "code": product.default_code},
"default_code": f"RENT-{rental_type.upper()}-{product.default_code}",
}
res = (
self.env["create.rental.product"]
Expand Down Expand Up @@ -312,7 +295,7 @@ def _update_rental_service_fields(self, vals, fields, rental_services):
self.rental_service_ids.write(service_vals)

def write(self, vals):
res = super(ProductProduct, self).write(vals)
res = super().write(vals)
for p in self:
# Create service product automatically
if vals.get("rental_of_month", False):
Expand Down
10 changes: 5 additions & 5 deletions rental_pricelist/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _set_product_id(self):
else:
self.rental = False
self.product_id = self.display_product_id
# raise exceptions.UserError(_('The product has no related rental services.'))
elif not self.rental and self.display_product_id:
self.product_id = self.display_product_id

Expand Down Expand Up @@ -121,7 +120,8 @@ def _check_rental_availability(self):
"title": _("Not enough stock!"),
"message": _(
"You want to rent %(rental_qty).2f %(rental_uom)s but you only "
"have %(available_qty).2f %(rental_uom)s currently available on the "
"have %(available_qty).2f %(rental_uom)s currently available "
"on the "
'stock location "%(rental_name)s"! Make sure that you '
"get some units back in the meantime or "
're-supply the stock location "%(rental_name)s".'
Expand Down Expand Up @@ -194,9 +194,9 @@ def _check_sale_line_rental(self):
_(
"On the sale order line with rental service %(name)s, "
"you are trying to extend a rental with a rental "
"quantity (%(rental_qty)s) that is different from the quantity "
"of the original rental (%(ext_rental_qty)s). "
"This is not supported."
"quantity (%(rental_qty)s) that is different from "
"the quantity of the original rental "
"(%(ext_rental_qty)s). This is not supported."
)
% {
"name": line.product_id.name,
Expand Down
5 changes: 2 additions & 3 deletions rental_pricelist/tests/test_rental_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def setUp(self):
.create(
{
"partner_id": self.partnerA.id,
"pricelist_id": self.env.ref("product.list0").id,
}
)
)
Expand Down Expand Up @@ -484,7 +483,8 @@ def test_05_check_rental_productE(self):
with self.assertRaises(ValidationError) as e:
rental_serviceE.type = "consu"
self.assertEqual(
"The rental product 'Rental of Product E (Day(s))' must be of type 'Service'.",
"The rental product 'Rental of Product E (Day(s))' must be "
"of type 'Service'.",
str(e.exception),
)
with self.assertRaises(ValidationError) as e:
Expand Down Expand Up @@ -547,7 +547,6 @@ def test_06_check_start_end_dates_productF(self):
.create(
{
"partner_id": self.partnerA.id,
"pricelist_id": self.env.ref("product.list0").id,
}
)
)
Expand Down
30 changes: 10 additions & 20 deletions rental_pricelist/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- ProductProduct -->
<record id="product_normal_form_view" model="ir.ui.view">
Expand All @@ -12,25 +11,22 @@
<page
name="rental_price"
string="Rental Price"
attrs="{'invisible': ['|', ('rental', '=', False), ('type', '!=', 'product')]}"
invisible="not rental or type != 'product'"
>
<group>
<group string="Monthly Basis">
<field name="rental_of_month" />
<field name="def_pricelist_id" invisible="1" />
<field
name="rental_price_month"
attrs="{'invisible': [('rental_of_month','=',False)]}"
invisible="not rental_of_month"
/>
<field
name="product_rental_month_id"
groups="base.group_no_one"
/>
<field name="product_rental_month_id" invisible="1" />
<strong
colspan="2"
attrs="{'invisible': [('product_rental_month_id', '=', False)]}"
>
<strong colspan="2" invisible="not product_rental_month_id">
Bulk Prices
</strong>
<field
Expand All @@ -42,7 +38,7 @@
'default_applied_on': '0_product_variant',
'default_compute_price': 'fixed',
'default_product_id': product_rental_month_id, 'default_pricelist_id': def_pricelist_id}"
attrs="{'invisible': ['|', ('rental_of_month', '=', False), ('product_rental_month_id', '=', False)]}"
invisible="not rental_of_month or not product_rental_month_id"
nolabel="1"
colspan="2"
>
Expand All @@ -67,17 +63,14 @@
<field name="rental_of_day" />
<field
name="rental_price_day"
attrs="{'invisible': [('rental_of_day','=',False)]}"
invisible="not rental_of_day"
/>
<field
name="product_rental_day_id"
groups="base.group_no_one"
/>
<field name="product_rental_day_id" invisible="1" />
<strong
colspan="2"
attrs="{'invisible': [('product_rental_day_id', '=', False)]}"
>
<strong colspan="2" invisible="not product_rental_day_id">
Bulk Prices
</strong>
<field
Expand All @@ -89,7 +82,7 @@
'default_applied_on': '0_product_variant',
'default_compute_price': 'fixed',
'default_product_id': product_rental_day_id, 'default_pricelist_id': def_pricelist_id}"
attrs="{'invisible': ['|', ('rental_of_day', '=', False), ('product_rental_day_id', '=', False)]}"
invisible="not rental_of_day or not product_rental_day_id"
nolabel="1"
colspan="2"
>
Expand All @@ -114,17 +107,14 @@
<field name="rental_of_hour" />
<field
name="rental_price_hour"
attrs="{'invisible': [('rental_of_hour','=',False)]}"
invisible="not rental_of_hour"
/>
<field
name="product_rental_hour_id"
groups="base.group_no_one"
/>
<field name="product_rental_hour_id" invisible="1" />
<strong
colspan="2"
attrs="{'invisible': [('product_rental_hour_id', '=', False)]}"
>
<strong colspan="2" invisible="not product_rental_hour_id">
Bulk Prices
</strong>
<field
Expand All @@ -136,7 +126,7 @@
'default_applied_on': '0_product_variant',
'default_compute_price': 'fixed',
'default_product_id': product_rental_hour_id, 'default_pricelist_id': def_pricelist_id}"
attrs="{'invisible': ['|', ('rental_of_hour', '=', False), ('product_rental_hour_id', '=', False)]}"
invisible="not rental_of_hour or not product_rental_hour_id"
nolabel="1"
colspan="2"
>
Expand Down
1 change: 0 additions & 1 deletion rental_pricelist/views/res_company_view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_company_rental_service_form" model="ir.ui.view">
<field name="name">res.company.form</field>
Expand Down
1 change: 0 additions & 1 deletion rental_pricelist/views/sale_view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_order_form" model="ir.ui.view">
Expand Down

0 comments on commit 34b6776

Please sign in to comment.