'Create Customer Invoice of Membership for partners.
@param datas: datas has dictionary value which consist Id of Membership product and Cost Amount of Membership.
datas = {\'membership_product_id\': None, \'amount\': None}'

@api.multi
def create_membership_invoice(self, product_id=None, datas=None):

    product_id = (product_id or datas.get('membership_product_id'))
    amount = datas.get('amount', 0.0)
    invoice_list = []
    for partner in self:
        addr = partner.address_get(['invoice'])
        if partner.free_member:
            raise UserError(_('Partner    is    a    free    Member.'))
        if (not addr.get('invoice', False)):
            raise UserError(_("Partner    doesn't    have    an    address    to    make    the    invoice."))
        invoice = self.env['account.invoice'].create({'partner_id': partner.id, 'account_id': partner.property_account_receivable_id.id, 'fiscal_position_id': partner.property_account_position_id.id})
        line_values = {'product_id': product_id, 'price_unit': amount, 'invoice_id': invoice.id}
        invoice_line = self.env['account.invoice.line'].new(line_values)
        invoice_line._onchange_product_id()
        line_values = invoice_line._convert_to_write({name: invoice_line[name] for name in invoice_line._cache})
        line_values['price_unit'] = amount
        invoice.write({'invoice_line_ids': [(0, 0, line_values)]})
        invoice_list.append(invoice.id)
        invoice.compute_taxes()
    return invoice_list
