Permalink
Browse files

[FIX] membership: date empty values

- Before this PR when a membership product is created with no date_from or date_to values (fields aren't set to required in the model) it causes a crash because the value was set to '0000-00-00' and it couldn't be written to the DB.
- To comply properly with python3, possible false values must be considered in the evaluation itself.
  • Loading branch information...
chienandalu committed Oct 13, 2017
1 parent 119ae9b commit ff18edf8fda9a07589f8455838a2942199fc6064
Showing with 6 additions and 6 deletions.
  1. +4 −4 addons/membership/models/account_invoice.py
  2. +2 −2 addons/membership/models/partner.py
@@ -36,7 +36,7 @@ def write(self, vals):
# Product line has changed to a membership product
date_from = line.product_id.membership_date_from
date_to = line.product_id.membership_date_to
if line.invoice_id.date_invoice > date_from and line.invoice_id.date_invoice < date_to:
if line.invoice_id.date_invoice > (date_from or '0000-00-00') and line.invoice_id.date_invoice < (date_to or '0000-00-00'):
date_from = line.invoice_id.date_invoice
MemberLine.create({
'partner': line.invoice_id.partner_id.id,
@@ -60,9 +60,9 @@ def create(self, vals):
invoice_line.product_id.membership and \
not MemberLine.search([('account_invoice_line', '=', invoice_line.id)]):
# Product line is a membership product
date_from = invoice_line.product_id.membership_date_from or '0000-00-00'
date_to = invoice_line.product_id.membership_date_to or '0000-00-00'
if date_from < (invoice_line.invoice_id.date_invoice or '0000-00-00') < date_to:
date_from = invoice_line.product_id.membership_date_from
date_to = invoice_line.product_id.membership_date_to
if date_from and date_from < (invoice_line.invoice_id.date_invoice or '0000-00-00') < (date_to or '0000-00-00'):
date_from = invoice_line.invoice_id.date_invoice
MemberLine.create({
'partner': invoice_line.invoice_id.partner_id.id,
@@ -108,7 +108,7 @@ def _membership_state(self):
s = 4
if partner.member_lines:
for mline in partner.member_lines:
if mline.date_to >= today and mline.date_from <= today:
if (mline.date_to or '0000-00-00') >= today and (mline.date_from or '0000-00-00') <= today:
if mline.account_invoice_line.invoice_id:
mstate = mline.account_invoice_line.invoice_id.state
if mstate == 'paid':
@@ -126,7 +126,7 @@ def _membership_state(self):
s = 3
if s == 4:
for mline in partner.member_lines:
if mline.date_from < today and mline.date_to < today and mline.date_from <= mline.date_to and mline.account_invoice_line and mline.account_invoice_line.invoice_id.state == 'paid':
if (mline.date_from or '0000-00-00') < today and (mline.date_to or '0000-00-00') < today and (mline.date_from or '0000-00-00') <= (mline.date_to or '0000-00-00') and mline.account_invoice_line and mline.account_invoice_line.invoice_id.state == 'paid':
s = 5
else:
s = 6

0 comments on commit ff18edf

Please sign in to comment.