Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to return Membership State For Given Partner in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 307
    Comment on it

    In OpenERP first current row of the database cursor finds the current user’s ID for security checks. Then This Function return Membership State For Given Partner and return dictionary of membership state Value.

    Use this function show below

    1. def memberships(self, cr, uid, ids, name, args, context=None):
    2. res = {}
    3. for id in ids:
    4. res[id] = 'none'
    5. today = time.strftime('%Y-%m-%d')
    6. for id in ids:
    7. partner_data = self.browse(cr, uid, id, context=context)
    8. if partner_data.membership_cancel and today > partner_data.membership_cancel:
    9. res[id] = 'canceled'
    10. continue
    11. if partner_data.membership_stop and today > partner_data.membership_stop:
    12. res[id] = 'old'
    13. continue
    14. s = 4
    15. if partner_data.member_lines:
    16. for mline in partner_data.member_lines:
    17. if mline.date_to >= today:
    18. if mline.account_invoice_line and mline.account_invoice_line.invoice_id:
    19. mstate = mline.account_invoice_line.invoice_id.state
    20. if mstate == 'paid':
    21. s = 0
    22. inv = mline.account_invoice_line.invoice_id
    23. for payment in inv.payment_ids:
    24. if payment.invoice.type == 'out_refund':
    25. s = 2
    26. break
    27. elif mstate == 'open' and s!=0:
    28. s = 1
    29. elif mstate == 'cancel' and s!=0 and s!=1:
    30. s = 2
    31. elif (mstate == 'draft' or mstate == 'proforma') and s!=0 and s!=1:
    32. s = 3
    33. if s==4:
    34. for mline in partner_data.member_lines:
    35. 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':
    36. s = 5
    37. else:
    38. s = 6
    39. if s==0:
    40. res[id] = 'paid'
    41. elif s==1:
    42. res[id] = 'invoiced'
    43. elif s==2:
    44. res[id] = 'canceled'
    45. elif s==3:
    46. res[id] = 'waiting'
    47. elif s==5:
    48. res[id] = 'old'
    49. elif s==6:
    50. res[id] = 'none'
    51. if partner_data.free_member and s!=0:
    52. res[id] = 'free'
    53. if partner_data.associate_member:
    54. res_state = self._membership_state(cr, uid, [partner_data.associate_member.id], name, args, context=context)
    55. res[id] = res_state[partner_data.associate_member.id]
    56. return res
    57.  

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: