Skip to content

Commit

Permalink
[FIX] membership_prorate: Prevent error when using prorate with varia…
Browse files Browse the repository at this point in the history
…ble period without membership_prorate_variable_period module installed
  • Loading branch information
ByteMeAsap committed Oct 11, 2024
1 parent 299c370 commit 7db3aff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions membership_prorate/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions membership_prorate/tests/test_membership_prorate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 7db3aff

Please sign in to comment.