- |
  In Order to test the Membership in OpenERP, which allows us to manage all operations for managing memberships.
- |
  I'm creating "Gold Membership" which has Membership fee 80 EURO and It's started from 1st June to 31st Dec.
-
  !record {model: product.product, id: product_product_membershipproduct0}:
    categ_id: product.product_category_1
    membership: 1
    membership_date_from: !eval datetime.today().strftime("%Y-%m-%d")
    membership_date_to: !eval "(datetime.now() + timedelta(6*31)).strftime('%Y-%m-%d')" 
    name: Gold Membership
    type: service
    list_price: 80.00

- |
  "Seagate" want to join "Gold Membership", so I'm checking  "Current Membership State" of "Seagate". It is an "Non Member" or not.
-
  !assert {model: res.partner, id: base.res_partner_19}:
      - membership_state == 'none', 'Member should be has "Current Membership State" in "Non Member".'
- |
  I'm doing to make membership invoice for "Seagate" on joining "Gold Membership".
-
  !python {model: res.partner}: |
    self.create_membership_invoice(cr, uid, [ref("base.res_partner_19")], product_id=ref("product_product_membershipproduct0"), datas={"amount":80.00})
- |
  I'm checking  "Current Membership State" of "Seagate". It is an "Waiting Member" or not.
-
  !assert {model: res.partner, id: base.res_partner_19}:
      - membership_state == 'waiting', 'Member should be has "Current Membership State" in "Waiting Member".'
- |
  I'm Opening that Invoice which is created for "Seagate".
-
  !python {model: res.partner}: |
        import netsvc
        from tools.translate import _
        invoice_pool = self.pool.get('account.invoice')
        partner_pool = self.pool.get('res.partner')
        membership_line_pool = self.pool.get('membership.membership_line')
        membership_pool = self.pool.get('product.product')

        membership_line_ids = membership_line_pool.search(cr, uid, [('membership_id','=',ref('product_product_membershipproduct0')),('partner','=',ref('base.res_partner_19'))])
        membership_lines = membership_line_pool.browse(cr, uid, membership_line_ids)
        assert membership_lines, _('Membership is not registrated.')
        membership_line = membership_lines[0]
        wf_service = netsvc.LocalService("workflow")
        wf_service.trg_validate(uid, 'account.invoice', membership_line.account_invoice_id.id, 'invoice_open', cr)
- |
  I'm checking "Current membership state" of "Seagate". It is an "Invoiced Member" or not.
-
  !assert {model: res.partner, id: base.res_partner_19}:
     - membership_state == 'invoiced', 'Member should be has "Current Membership State" in "Invoiced Member".'

- |
  I'm creating free member "Ms. Johnson" of "Gold Membership".
-
  !record {model: res.partner, id: res_partner_msjohnson0}:
        name: Ms. Johnson
        city: paris
        country_id: base.fr
        name: Ms. Johnson
        street: 1 rue Rockfeller
        type: invoice
        zip: '75016'
        free_member: True

- |
  I'm checking "Current membership state" of "Ms. Johnson". It is an "Free Member" or not.
-
  !assert {model: res.partner, id: res_partner_msjohnson0}:
     - membership_state == 'free', 'Member should be has "Current Membership State" in "Free Member".'

- |
  I'm set "Seagate" as a associated member of "Ms. Johnson" and also set Non free member.
-
  !python {model: res.partner}: |
    self.write(cr, uid, [ref("res_partner_msjohnson0")], {'free_member': False, 'associate_member': ref("base.res_partner_19")})

- |
  I'm checking "Current membership state" of "Ms. Johnson". It is an "Paid Member" or not.
-
  !assert {model: res.partner, id: res_partner_msjohnson0}:
     - membership_state == 'paid', 'Member should be has "Current Membership State" in "Paid Member".'

- |
  I'm creating new "Regular Membership" which has Membership fee 50 EURO and It's started from 1st June to 31st Dec.
-
  !record {model: product.product, id: product_product_membershipproduct1}:
    categ_id: product.product_category_1
    membership: 1
    membership_date_from: !eval datetime.today().strftime("%Y-%m-%d")
    membership_date_to: !eval "(datetime.now() + timedelta(6*31)).strftime('%Y-%m-%d')" 
    name: Regular Membership
    type: service
    list_price: 50.00
- |
  I'm making invoice of "Seagate" member on joining new membership "Regular Membership".
-
  !python {model: res.partner}: |
    self.create_membership_invoice(cr, uid, [ref("base.res_partner_19")], product_id=ref("product_product_membershipproduct1"), datas={"amount":50.00})
- |
  I'm checking "Current membership state" of "Seagate". It is an "Old Member" or not.
-
  !assert {model: res.partner, id: base.res_partner_19}:
      - membership_state == 'old', 'Member should be has "Current Membership State" in "Old Member".'
- |
  I'm doing to make credit note of invoice which is paid by "Seagate" to cancel membership.
-
  !python {model: account.invoice}: |
        from tools.translate import _
        invoice_pool = self.pool.get('account.invoice')
        partner_pool = self.pool.get('res.partner')
        membership_line_pool = self.pool.get('membership.membership_line')
        membership_pool = self.pool.get('product.product')
        invoice_refund_pool = self.pool.get('account.invoice.refund')

        membership_line_ids = membership_line_pool.search(cr, uid, [('membership_id','=',ref('product_product_membershipproduct0')),('partner','=',ref('base.res_partner_19'))])
        membership_lines = membership_line_pool.browse(cr, uid, membership_line_ids)
        assert membership_lines, _('Membership is not registrated.')
        membership_line = membership_lines[0]
        refund_id = invoice_refund_pool.create(cr, uid, {'description': 'Refund of Membership', 'filter_refund': 'refund'}, {'active_id': membership_line.account_invoice_id.id})
        invoice_refund_pool.invoice_refund(cr, uid, [refund_id], {'active_id': membership_line.account_invoice_id.id, 'active_ids': [membership_line.account_invoice_id.id]})
- |
  I'm checking "Current membership state" of "Seagate". It is an "Cancelled Member" or not.
-
  !assert {model: res.partner, id: base.res_partner_19}:
      - membership_state == 'canceled', 'Member should be has "Current Membership State" in "Cancelled Member".'

