From 7db3affe7d5a54874a548f3eb4ecc03cddb4d204 Mon Sep 17 00:00:00 2001 From: Anjeel Haria Date: Thu, 10 Oct 2024 20:25:45 +0530 Subject: [PATCH] [FIX] membership_prorate: Prevent error when using prorate with variable period without membership_prorate_variable_period module installed --- .../models/account_move_line.py | 5 +++++ .../tests/test_membership_prorate.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/membership_prorate/models/account_move_line.py b/membership_prorate/models/account_move_line.py index 47f3f68d7..ec674f8ef 100644 --- a/membership_prorate/models/account_move_line.py +++ b/membership_prorate/models/account_move_line.py @@ -26,6 +26,11 @@ def _prepare_invoice_line_prorate_vals(self, invoice_line): product = invoice_line.product_id date_invoice = invoice_line.move_id.invoice_date or fields.Date.today() date_from, date_to = self._get_membership_interval(product, date_invoice) + if not date_from: + return { + "quantity": 1.0, + "date_from": date_invoice, + } if date_invoice < date_from: date_invoice = date_from if date_invoice > date_to: diff --git a/membership_prorate/tests/test_membership_prorate.py b/membership_prorate/tests/test_membership_prorate.py index e511970bf..528eb5dd8 100644 --- a/membership_prorate/tests/test_membership_prorate.py +++ b/membership_prorate/tests/test_membership_prorate.py @@ -2,9 +2,12 @@ # Copyright 2017-19 Tecnativa - David Vidal # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html from datetime import date +from unittest.mock import patch from odoo.tests import Form, common +from odoo.addons.membership_prorate.models.account_move_line import AccountMoveLine + class TestMembershipProrate(common.SavepointCase): @classmethod @@ -86,3 +89,19 @@ def test_create_invoice_membership_product_prorate(self): ) self.assertAlmostEqual(memb_line.member_price, 0.00, 2) self.assertEqual(memb_line.date_from, date(2017, 12, 31)) + + def test_create_invoice_membership_product_prorate_variable_period(self): + """It is a test for case where membership type is set to variable + on product with membership_prorate_variable_period not installed""" + + def _get_membership_interval(self, product, date): + return False, False + + with patch.object( + AccountMoveLine, + "_get_membership_interval", + _get_membership_interval, + ): + invoice = self.partner.create_membership_invoice(self.product, 1.0) + self.assertEqual(invoice.invoice_line_ids[0].quantity, 1.0) +