membership: The state of Associated members is not changed

Bug #313339 reported by Jordi Esteve (www.zikzakmedia.com)
2
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Undecided
Unassigned

Bug Description

When a membership has paid an invoice containing membership products and his state is changed from Non member -> Invoiced member -> Paid member, other partners containing that membership in the Associate member field, their state is not changed from Non member -> Associated member automatically.

The state of Associated members is only changed if the Associate member field is changed later.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

fixed in trunk.

Changed in openobject-addons:
status: New → Fix Released
Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) wrote :

I have tested and it is not completely fixed.

I you change the invoice of a member (draft->open->canceled->draft), his membership state changes but not the state of the associated members of him.

I think the following code must be add in lines 230 and 237 of membership/membership.py:

        ids2 = list_partner
        while ids2:
            ids2 = self.pool.get('res.partner').search(cr, uid, [('associate_member','in',ids2)], context=context)
            list_partner += ids2

The complete code is:

    def _get_partner_id(self, cr, uid, ids, context=None):
        data_inv = self.pool.get('membership.membership_line').browse(cr, uid, ids, context)
        list_partner = []
        for data in data_inv:
            list_partner.append(data.partner.id)
        ids2 = list_partner
        while ids2:
            ids2 = self.pool.get('res.partner').search(cr, uid, [('associate_member','in',ids2)], context=context)
            list_partner += ids2
        return list_partner

    def _get_invoice_partner(self, cr, uid, ids, context=None):
        data_inv = self.pool.get('account.invoice').browse(cr, uid, ids, context)
        list_partner = []
        for data in data_inv:
            list_partner.append(data.partner_id.id)
        ids2 = list_partner
        while ids2:
            ids2 = self.pool.get('res.partner').search(cr, uid, [('associate_member','in',ids2)], context=context)
            list_partner += ids2
        return list_partner

Also the state of associated members that computes the method _membership_state is wrong, because it takes the state of the associated member (line 288 res[id] = partner_data.associate_member.membership_state) and sometimes this state has not been computed yet.

I think this line must be changed by a recursive call:
                state = self._membership_state(cr, uid, [partner_data.associate_member.id], name, args, context)
                res[id] = state[partner_data.associate_member.id]

I attach the membership/membership.py with all the changes.

Jordi

Changed in openobject-addons:
status: Fix Released → Confirmed
Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) wrote :

I attach the membership/membership.py with all the 3 proposed changes.

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

can you provide a diff file ?

Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) wrote :

I have attached diff file of membership/membership.py

Revision history for this message
qdp (OpenERP) (qdp) wrote :

fixed in revno 2174 and 2176.

thank you for your patch

Changed in openobject-addons:
status: Confirmed → Fix Released
Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) wrote :

OpenERP 5.0.0 stable. I think this bug is partially fixed. The state of associated members that computes the method _membership_state is still wrong, because it takes the state of the associated member and sometimes this state has not been computed yet.

I don't understand the code changed in _membership_state by your fix. self._membership_state() is called but the values computed are not stored not used.

This is the diff between 5.0.0 version and my proposed fix:

membership/membership.py
===================================================================
--- membership.py (5.0.0 version)
+++ membership.py (proposed fix)
@@ -289,15 +289,8 @@
             if partner_data.free_member and s!=0:
                 res[id] = 'free'
             if partner_data.associate_member:
- associate_partners_list = []
- query="SELECT DISTINCT associate_member FROM res_partner"
- cr.execute(query)
- for p in cr.fetchall():
- if p != partner_data.id:
- associate_partners_list.append(p)
- if associate_partners_list != []:
- self._membership_state(cr, uid, associate_partners_list, name, args, context)
- res[id] = partner_data.associate_member.membership_state
+ state = self._membership_state(cr, uid, [partner_data.associate_member.id], name, args, context)
+ res[id] = state[partner_data.associate_member.id]
         return res

     def _membership_start(self, cr, uid, ids, name, args, context=None):

Changed in openobject-addons:
status: Fix Released → Confirmed
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

Hello Jordi,
Fixed in trunk with revision number : 2235

Thanks,

Changed in openobject-addons:
status: Confirmed → Fix Released
Changed in openobject-addons:
status: Fix Released → In Progress
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

fixed in stable 5.0 addons also with revision number : 2232
   link : lp:~openerp/openobject-addons/5.0

Changed in openobject-addons:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.