Skip to content
Snippets Groups Projects
Commit ca34dd39 authored by jvm-odoo's avatar jvm-odoo
Browse files

[FIX] membership: fix state computing


Reproduce this bug:
- Install Contacts & Members app
- Create a Membership product
- Go on any contact, in the membership tab then buy membership

The "current membership status" should use the first valid line.

When you cancel a membership line, the current membership status is
always on "cancelled".

Causes:
- The `_compute_state` state method is not fetching the credits notes
  correctly.
- The `break` statement is at the wrong place.

OPW-2093825

closes odoo/odoo#39803

Signed-off-by: default avatarJorge Pinna Puissant (jpp) <jpp@odoo.com>
parent 6dc0536b
Branches
Tags
No related merge requests found
......@@ -75,7 +75,7 @@ class MembershipLine(models.Model):
line.state = 'invoiced'
elif istate == 'paid':
line.state = 'paid'
invoices = Invoice.browse(fetched[1]).payment_ids.mapped('invoice_ids')
invoices = Invoice.browse(fetched[1]).payment_move_line_ids.mapped('invoice_id')
if invoices.filtered(lambda invoice: invoice.type == 'out_refund'):
line.state = 'canceled'
elif istate == 'cancel':
......
......@@ -123,18 +123,24 @@ class Partner(models.Model):
if mline.account_invoice_line.invoice_id.partner_id == partner:
mstate = mline.account_invoice_line.invoice_id.state
if mstate == 'paid':
s = 0
inv = mline.account_invoice_line.invoice_id
for ml in inv.payment_move_line_ids:
if any(ml.invoice_id.filtered(lambda inv: inv.type == 'out_refund')):
s = 2
break
else:
s = 0
elif mstate == 'open' and s != 0:
s = 1
elif mstate == 'cancel' and s != 0 and s != 1:
s = 2
elif mstate == 'draft' and s != 0 and s != 1:
s = 3
"""
If we have a line who is in the period and paid,
the line is valid and can be used for the membership status.
"""
if s == 0:
break
if s == 4:
for mline in partner.member_lines:
if (mline.date_from or date.min) < today and (mline.date_to or date.min) < today and (mline.date_from or date.min) <= (mline.date_to or date.min) and mline.account_invoice_line and mline.account_invoice_line.invoice_id.state == 'paid':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment