Files
enterprise-addons/sale_renting/tests/test_rental_report.py
T

39 lines
1.7 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import timedelta
from odoo import Command, fields
from odoo.tests import tagged
from .common import SaleRentingCommon
@tagged('post_install', '-at_install')
class TestRentalReport(SaleRentingCommon):
def test_5_days_rental_generates_5_rows_with_5_dates(self):
"""Test that a rental order of 5 days generates 5 rows, with 5 dates."""
start_date = fields.Datetime.now().replace(hour=0, minute=0, second=0)
return_date = start_date + timedelta(days=5, seconds=-1)
rental_product = self._create_product(
product_pricing_ids=[
Command.create({'recurrence_id': self.recurrence_day.id, 'price': 100})
]
)
rental_order = self._create_rental_order(
rental_start_date=start_date,
rental_return_date=return_date,
order_line=[Command.create({'product_id': rental_product.id})],
)
report_lines = self.env['sale.rental.report'].search([('order_id', '=', rental_order.id)])
self.assertEqual(len(report_lines), 5, "The report should have 5 rows")
# Verify dates
report_dates = [line.date.date() for line in report_lines]
rental_dates = [
(rental_order.rental_start_date.date() + timedelta(days=i)) for i in range(5)
]
self.assertEqual(report_dates, rental_dates, "Report dates should match rental dates.")
# Verify product and price
for line in report_lines:
self.assertEqual(line.product_id.id, rental_order.order_line.product_id.id)
self.assertEqual(line.price, rental_order.order_line.price_unit / 5)