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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 366
    Comment on it

    In OpenERP first create partner and then validate the partner form. After this compare it with the membership of the other partner. Then standard dictionary for contextual values and the dictionary of Membership state Value.

    Use this function show below

    def state(self, cr, uid, ids, name, args, context=None):
        
            res = {}
            for id in ids:
                res[id] = 'none'
            today = time.strftime('%Y-%m-%d')
            for id in ids:
                partner_data = self.browse(cr, uid, id, context=context)
                if partner_data.membership_cancel and today > partner_data.membership_cancel:
                    res[id] = 'canceled'
                    continue
                if partner_data.membership_stop and today > partner_data.membership_stop:
                    res[id] = 'old'
                    continue
                s = 4
                if partner_data.member_lines:
                    for mline in partner_data.member_lines:
                        if mline.date_to >= today:
                            if mline.account_invoice_line and mline.account_invoice_line.invoice_id:
                                mstate = mline.account_invoice_line.invoice_id.state
                                if mstate == 'paid':
                                    s = 0
                                    inv = mline.account_invoice_line.invoice_id
                                    for payment in inv.payment_ids:
                                        if payment.invoice.type == 'out_refund':
                                            s = 2
                                    break
                                elif mstate == 'open' and s!=0:
                                    s = 1
                                elif mstate == 'cancel' and s!=0 and s!=1:
                                    s = 2
                                elif  (mstate == 'draft' or mstate == 'proforma') and s!=0 and s!=1:
                                    s = 3
                    if s==4:
                        for mline in partner_data.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':
                                s = 5
                            else:
                                s = 6
                    if s==0:
                        res[id] = 'paid'
                    elif s==1:
                        res[id] = 'invoiced'
                    elif s==2:
                        res[id] = 'canceled'
                    elif s==3:
                        res[id] = 'waiting'
                    elif s==5:
                        res[id] = 'old'
                    elif s==6:
                        res[id] = 'none'
                if partner_data.free_member and s!=0:
                    res[id] = 'free'
                if partner_data.associate_member:
                    res_state = self._membership_state(cr, uid, [partner_data.associate_member.id], name, args, context=context)
                    res[id] = res_state[partner_data.associate_member.id]
            return res
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: